<p>As it happens, I was writing code for the exact same transformation last night using <a href="https://downloads.rene-schwarz.com/download/M001-Keplerian_Orbit_Elements_to_Cartesian_State_Vectors.pdf" rel="nofollow">this memo</a> as a reference. I haven't yet tested my implementation but the document is quite clear about what each step is doing, which pleased me greatly.</p>

<p>You'll have to understand the terminology to some degree; "epoch" means a reference time for which you have the orbital elements, and "considered epoch" means the time at which you're evaluating the position, for example. Other points requiring caution: the equations inconsistently drop subscripts; the use of the Newton-Raphson solver isn't particularly clear (i.e. how many times should it run)? Make sure you get the units right also.</p>

CC BY-SA 3.0
2015-12-01T17:10:39.710Z
Thanks for that memo. I also just (5 minutes ago) found a forum post which  describes the calculation for the true anomaly: http://www.orbiter-forum.com/showthread.php?t=26682.
Let's assume that I will use the orbital elements at epoch J.2000 for earth. If I start my calculation at t=0 (Perihelion) and reach Perihelion again when t=365, I will reset t to zero again to calculate the true anomaly? Did I understand that correctly?
Rene8888
CC BY-SA 3.0
2015-12-01T17:33:42.453Z
You can do that; my approach is to compute the mean anomaly as in equation (2) in the memo, then use the fmod() operation to wrap it to the [0, 2pi) range, which has the same effect.
Russell Borogove
CC BY-SA 3.0
2015-12-01T17:44:54.340Z
Since a solar year is actually approximately 365.25 and a bit days, wrapping 365 to 0 will accumulate ~6 hours of error a year, which depending on your application will be either mildly irritating or catastrophic.
Russell Borogove
CC BY-SA 3.0
2015-12-01T18:11:22.387Z
It's just a simple 3d python application. Even if the error would be bigger it doesn't matter. But to be save, I can calculate the orbital period with the help of Kepler's Third Law to be equal with the supplied semi-major axis and standard gravitational constant. The semi-major axis can be calculated with the help of the apogee and perigee, from which I can also calculate the eccentricity. In the end the values should be fairly accurate and I will not have problems with values from different sources.
Rene8888
CC BY-SA 3.0
2015-12-01T16:57:07.557Z
2015-12-01T16:57:07.557Z
Russell Borogove
<p>I want to simulate the orbits of the planets from our solar system. I want to use orbital elements to calculate the current position(xyz) at a time t. The simulation doesn't have to be too exact, but the initial position of the bodies should be somewhat realistic.</p>

<p>Doing some research on the calculation I stumbled upon the following formula:</p>

<pre><code>R,X,Y,Z-Heliocentric Distances
TA - True Anomaly
N - Longitude of the Ascending Node
w - Argument of the Perihelion

R = a * (1 - e ^ 2) / (1 + e * Cos(TA))
X = R * (Cos(N) * Cos(TA + w) - Sin(N) * Sin(TA+w)*Cos(i)
Y = R * (Sin(N) * Cos(TA+w) + Cos(N) * Sin(TA+w)) * Cos(i))
Z = R * Sin(TA+w) * Sin(i)
</code></pre>

<p>Source: <a href="https://www.physicsforums.com/threads/calculating-elliptic-orbits-in-cartesian-coordinates.712979/" rel="noreferrer">https://www.physicsforums.com/threads/calculating-elliptic-orbits-in-cartesian-coordinates.712979/</a></p>

<p>For testing purposes I calculated the true anomaly with the help of the following calculator: <a href="http://www.jgiesen.de/kepler/kepler.html" rel="noreferrer">http://www.jgiesen.de/kepler/kepler.html</a><br>
It needs the mean anomaly and eccentricity which I took from Wikipedia. Doing some more research on the mean anomaly, I now believe that the time at which I want the position will be somehow fed into the calculation of the mean anomaly along with the time of the initial position.</p>

<p>Can somebody clarify for me on how to correctly calculate the position at time t with the above or a different formula. With the above formula I also think I need the initial values at a specific time.</p>

<p>I also want to say that I am not an astronomer and I don't have a clue on how to handle the calculation or which formula to use. The result of the calculations should mimic our solar system as closely as possible.</p>

<p>Thanks,<br>
Rene Hollander</p>

CC BY-SA 3.0
2015-11-30T22:21:14.147Z
possible duplicate http://astronomy.stackexchange.com/questions/8012/how-do-i-calculate-the-positions-of-objects-in-orbit
James K
CC BY-SA 3.0
2015-11-30T22:50:44.280Z
I also found that post, but the answers did not really help me to solve the Problem.
Rene8888
CC BY-SA 3.0
2015-12-01T17:16:22.263Z
That also sounds good. I assume I have to simulate the gravitational forces to do that. If I let the simulation run for a while, wouldn't it be possible through errors during the calculation to mess up the orbits?
Rene8888
<orbit><orbital-elements>
Simulate an orbit with orbital elements
Rene8888
# Simulate an orbit with orbital elements

(Asked by: username_0 on 2015-11-30)

I want to simulate the orbits of the planets from our solar system. I want to use orbital elements to calculate the current position(xyz) at a time t. The simulation doesn't have to be too exact, but the initial position of the bodies should be somewhat realistic.

Doing some research on the calculation I stumbled upon the following formula:

```
R,X,Y,Z-Heliocentric Distances
TA - True Anomaly
N - Longitude of the Ascending Node
w - Argument of the Perihelion

R = a * (1 - e ^ 2) / (1 + e * Cos(TA))
X = R * (Cos(N) * Cos(TA + w) - Sin(N) * Sin(TA+w)*Cos(i)
Y = R * (Sin(N) * Cos(TA+w) + Cos(N) * Sin(TA+w)) * Cos(i))
Z = R * Sin(TA+w) * Sin(i)

```

Source: <https://www.physicsforums.com/threads/calculating-elliptic-orbits-in-cartesian-coordinates.712979/>

For testing purposes I calculated the true anomaly with the help of the following calculator: <http://www.jgiesen.de/kepler/kepler.html>  
It needs the mean anomaly and eccentricity which I took from Wikipedia. Doing some more research on the mean anomaly, I now believe that the time at which I want the position will be somehow fed into the calculation of the mean anomaly along with the time of the initial position.

Can somebody clarify for me on how to correctly calculate the position at time t with the above or a different formula. With the above formula I also think I need the initial values at a specific time.

I also want to say that I am not an astronomer and I don't have a clue on how to handle the calculation or which formula to use. The result of the calculations should mimic our solar system as closely as possible.

Thanks,  
Rene Hollander

**Tags:** orbit, orbital-elements

> **Comments:**
> **username_1**: possible duplicate http://astronomy.stackexchange.com/questions/8012/how-do-i-calculate-the-positions-of-objects-in-orbit  
> **username_0**: I also found that post, but the answers did not really help me to solve the Problem.  
> **username_0**: That also sounds good. I assume I have to simulate the gravitational forces to do that. If I let the simulation run for a while, wouldn't it be possible through errors during the calculation to mess up the orbits?  

---

## 1 answers

### Answer by username_2 on 2015-12-01. Score: 2 | Accepted answer

As it happens, I was writing code for the exact same transformation last night using [this memo](https://downloads.rene-schwarz.com/download/M001-Keplerian_Orbit_Elements_to_Cartesian_State_Vectors.pdf) as a reference. I haven't yet tested my implementation but the document is quite clear about what each step is doing, which pleased me greatly.

You'll have to understand the terminology to some degree; "epoch" means a reference time for which you have the orbital elements, and "considered epoch" means the time at which you're evaluating the position, for example. Other points requiring caution: the equations inconsistently drop subscripts; the use of the Newton-Raphson solver isn't particularly clear (i.e. how many times should it run)? Make sure you get the units right also.

> **Comments:**
> **username_0**: Thanks for that memo. I also just (5 minutes ago) found a forum post which  describes the calculation for the true anomaly: http://www.orbiter-forum.com/showthread.php?t=26682. Let's assume that I will use the orbital elements at epoch J.2000 for earth. If I start my calculation at t=0 (Perihelion) and reach Perihelion again when t=365, I will reset t to zero again to calculate the true anomaly? Did I understand that correctly?  
> **username_2**: You can do that; my approach is to compute the mean anomaly as in equation (2) in the memo, then use the fmod() operation to wrap it to the [0, 2pi) range, which has the same effect.  
> **username_2**: Since a solar year is actually approximately 365.25 and a bit days, wrapping 365 to 0 will accumulate ~6 hours of error a year, which depending on your application will be either mildly irritating or catastrophic.  
> **username_0**: It's just a simple 3d python application. Even if the error would be bigger it doesn't matter. But to be save, I can calculate the orbital period with the help of Kepler's Third Law to be equal with the supplied semi-major axis and standard gravitational constant. The semi-major axis can be calculated with the help of the apogee and perigee, from which I can also calculate the eccentricity. In the end the values should be fairly accurate and I will not have problems with values from different sources.  

---

