Eccentricity Calculation Problem

XSSA

New member
Joined
Apr 9, 2011
Messages
67
Reaction score
0
Points
0
So i have been teaching myself physics and then programming a simulator with this knowledge in Unity3D. So, i have recently finished eccentricity but when i programmed the script to do the calculation it always returns 1. :facepalm:
So the equation i used was :
e = Sqrt(1+(2(((v^2/2)-((G(M1+M2)/r)))*(r*(m*v)^2)))/((1/((1/M1)+(1/M2)))*(G(M1*M2))^2)) which should be the expanded form of e = Sqrt(1+((2(E*L^2))/(mred*a^2))) but this isn't working. Where
v = velocity
G = Grav. Constant
r = distance
m = M1
E = orbital energy
L = angular momentum
mred = reduced mass
a = coef. of inverse-square law
So maybe i missed a variable or something. So have any ideas on what is wrong? Ohh and to get velocity i used a built in Unity function to find velocity so i don't need to calculate for that. :hailprobe:
 

Quick_Nick

Passed the Turing Test
Donator
Joined
Oct 20, 2007
Messages
4,088
Reaction score
204
Points
103
Location
Tucson, AZ
This seems to imply that a variable in the numerator of your division is 0. (Something inside E or L) You can try displaying their values somehow.
Or you might even look for accidental integer math.

Also, I assume your code only loosely resembles the equation. (the equation is quite long, and includes the ^ symbol)
 
Last edited:

XSSA

New member
Joined
Apr 9, 2011
Messages
67
Reaction score
0
Points
0
I first calculated all the variables and used the smaller equation to solve for it. It looks almost exactly like this. And to do squares i did (variable*variable).
If need be i can post the code. I also tried to remove 1 to see what i was getting before adding 1 and it says N/A.
 
Last edited:

Veterok

New member
Joined
Oct 25, 2011
Messages
65
Reaction score
0
Points
0
N/A might be a divide by zero, assuming N/A + 1 = 1. I'd check that the denominator is working correctly.

I wrote some orbital dynamics stuff for a KSP plugin.

I found this page very helpful for working everything out.
http://braeunig.us/space/orbmech.htm
 

XSSA

New member
Joined
Apr 9, 2011
Messages
67
Reaction score
0
Points
0
Thanks i think i have some reading and testing too do, but not tonight it's time for bed.... ok maybe a little reading.:facepalm:

I'll try to find the problem tomorrow and see what i get.:hailprobe:
 
Top