[Physics] How to calculate the semi major axis from velocity, position and pull

orbital-motion

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?

Best Answer

From your answers it seems the problem is the choice of units of measure. There isn't a clearly defined conversion between your units and SI units, so gravity can't be simulated properly. Everything seems to revolve around the value of G, that sets the strength of gravity in your simulation.

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}$.

With this particular conversion, it results that the gravity of your simulation was ten order of magnitudes stronger than the gravity of our universe.