Eccentricity Calculation Problem

XSSA

New member
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.

Quick_Nick

Passed the Turing Test
Donator
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
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
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.

http://braeunig.us/space/orbmech.htm

XSSA

New member
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.

Replies
1
Views
369
Replies
23
Views
526
Replies
23
Views
2K
Replies
4
Views
1K