# How can I calculate the semi major axis from velocity, position and pull?

I'm working on a game, that is set in space. The game is about orbits and my problem is the following:

I want to be able to draw a predicted orbit for my satellite. Currently, my satellite orbits the host planet. What I have available from the physics simulator is the satellite's velocity, its position and the pulling force from the planet.

As I have researched, I understand that I should be able to calculate the ellipse of the orbit and a starting point could be to first calculate the semi major axis of the ellipse using the total energy equation (taken from Calculating specific orbital energy, semi-major axis, and orbital period of an orbiting body):

\begin{align} E &= \frac{1}{2}v^2 - \frac{\mu}{r}= -\frac{\mu}{2a}, \end{align}

Which can be rewritten to \begin{align} a &= - \frac{\mu r}{r v^2 - 2 \mu } \end{align}

Where $a$ is the semi major axis, $\mu = G(M+m)$, $v$ is the velocity and $M$, $m$ are the bigger and smaller masses, respectively. Using a simulation with two bodies, a planet (with mass 9999999999) and a satellite (with mass 1) placed 10 units from the planet, and a circular orbit, I expect the semi major axis to be 10 but what I get is a negative number.

P.S I want the planet to be the primary.

Any hints of what might be wrong?

• I see mass and length are defined without a unit of measure. No problem with that, but how did you define G then? If you used the SI value $6.67 \times 10^{-11}$ N m$^2$/kg$^2$, then this is the wrong constant for your simulation, since every other parameter isn't measured in SI units. – GRB Nov 28 '16 at 22:56
• Sorry, forgot to mention that. My system is currently "unitless", so everything is just measured in ... units. The underlying physics system let you choose any unit you want. So my units can be considered SI units. My G constant is defined as 6.67×10−11. – mrmclovin Nov 29 '16 at 9:06
• If I consider everything to be SI, then my G value should be correct? @GRB .. I will review my units again to see if I have made a mistake regarding the units.. – mrmclovin Nov 29 '16 at 12:03
• Exactly, otherwise depending on the ratio between your units and SI units your simulated gravity can be stronger or weaker than in our universe and orbits can change dramatically. – GRB Nov 29 '16 at 12:37

As an example, I'll set 1 unit of mass as $10^5$ kg, 1 unit of length as $10^5$ m and 1 unit of time as 1 s, but you can choose any conversion you desire and apply the following procedure. In this example the satellite has a mass of 100 metric tons and a distance of 1000 km from the center of the planet, while the planet has a mass of about $10^{15}$ kg, so it's quite a small body, about the same mass as Deimos, the smallest moon of Mars.
Once you have the conversions, you need to reverse them. In my example, 1 kg is equivalent to $\frac{1}{10^5} = 10^{-5}$ units of mass, while 1 m corresponds to $10^{-5}$ units of length. Now, since G has a unit of N m$^2$/kg$^2$ = m$^3$ kg$^{-1}$ s$^{-2}$, we can replace these units with the conversion factors found above and find that in these custom units G must be multiplied by $10^{-10}$ to scale gravity properly. This means that G = $6.67 \times 10^{-21}$.