Computing planetary positions
Computing planetary positions
0. Foreword
1. Introduction
2. A few words about accuracy
3. The time scale
4. The orbital elements
5. The position of the Sun
5b. The Sidereal Time
6. The position of the Moon and of the planets
7. The position in space
8. Precession
9. Perturbations of the Moon
10. Perturbations of Jupiter, Saturn and Uranus
11. Geocentric (Earth-centered) coordinates
12. Equatorial coordinates
12b. Azimuthal coordinates
13. The Moon's topocentric position
14. The position of Pluto
15. The elongation and physical ephemerides of the planets
16. Positions of asteroids
17. Position of comets
18. Parabolic orbits
19. Near-parabolic orbits
20. Hyperbolic orbits
21. Rise and set times
22. Validity of orbital elements
23. Links to other sites
www.stjarnhimlen.se/comp/ppcomp.html 1/24
02/03/2020 Computing planetary positions
0. Foreword
Below is a description of how to compute the positions for the Sun and Moon and the major planets, as well as for comets and minor planets, from a set of
orbital elements.
The algorithms have been simplified as much as possible while still keeping a fairly good accuracy. The accuracy of the computed positions is a fraction of an
arc minute for the Sun and the inner planets, about one arc minute for the outer planets, and 1-2 arc minutes for the Moon. If we limit our accuracy demands to
this level, one can simplify further by e.g. ignoring the difference between mean, true and apparent positions.
The positions computed below are for the 'equinox of the day', which is suitable for computing rise/set times, but not for plotting the position on a star map
drawn for a fixed epoch. In the latter case, correction for precession must be applied, which is most simply performed as a rotation along the ecliptic.
These algortihms were developed by myself back in 1979, based on a preprint from T. van Flandern's and K. Pulkkinen's paper "Low precision formulae for
planetary positions", published in the Astrophysical Journal Supplement Series, 1980. It's basically a simplification of these algorithms, while keeping a
reasonable accuracy. They were first implemented on a HP-41C programmable pocket calculator, in 1979, and ran in less than 2 KBytes of RAM! Nowadays
considerable more accurate algorithms are available of course, as well as more powerful computers. Nevertheless I've retained these algorithms as what I believe
is the simplest way to compute solar/lunar positions with an accuracy of 1-2 arc minutes.
1. Introduction
The text below describes how to compute the positions in the sky of the Sun, Moon and the major planets out to Neptune. The algorithm for Pluto is taken from
a fourier fit to Pluto's position as computed by numerical integration at JPL. Positions of other celestial bodies as well (i.e. comets and asteroids) can also be
computed, if their orbital elements are available.
These formulae may seem complicated, but I believe this is the simplest method to compute planetary positions with the fairly good accuracy of about one arc
minute (=1/60 degree). Any further simplifications will yield lower accuracy, but of course that may be ok, depending on the application.
www.stjarnhimlen.se/comp/ppcomp.html 2/24
02/03/2020 Computing planetary positions
Note that the formula above is only valid from March 1900 to February 2100.
Below is another formula, which is valid over the entire Gregorian Calendar:
d = 367*y - 7 * ( y + (m+9)/12 ) / 4 - 3 * ( ( y + (m-9)/7 ) / 100 + 1 ) / 4 + 275*m/9 + D - 730515
Note that ALL divisions here should be INTEGER divisions. In Pascal, use "div" instead of "/", in MS-Basic, use "\" instead of "/". In Fortran, C and C++ "/"
can be used if both y and m are integers. Finally, include the time of the day, by adding:
d = d + UT/24.0 (this is a floating-point division)
One Astronomical Unit (AU) is the Earth's mean distance to the Sun, or 149.6 million km. When closest to the Sun, a planet is in perihelion, and when most
distant from the Sun it's in aphelion. For the Moon, an artificial satellite, or any other body orbiting the Earth, one says perigee and apogee instead, for the
points in orbit least and most distant from Earth.
To describe the position in the orbit, we use three angles: Mean Anomaly, True Anomaly, and Eccentric Anomaly. They are all zero when the planet is in
perihelion:
Mean Anomaly (M): This angle increases uniformly over time, by 360 degrees per orbital period. It's zero at perihelion. It's easily computed from the orbital
period and the time since last perihelion.
True Anomaly (v): This is the actual angle between the planet and the perihelion, as seen from the central body (in this case the Sun). It increases non-uniformly
with time, changing most rapidly at perihelion.
Eccentric Anomaly (E): This is an auxiliary angle used in Kepler's Equation, when computing the True Anomaly from the Mean Anomaly and the orbital
eccentricity.
Note that for a circular orbit (eccentricity=0), these three angles are all equal to each other.
Another quantity we will need is ecl, the obliquity of the ecliptic, i.e. the "tilt" of the Earth's axis of rotation (currently 23.4 degrees and slowly decreasing).
First, compute the "d" of the moment of interest (section 3). Then, compute the obliquity of the ecliptic:
ecl = 23.4393 - 3.563E-7 * d
Now compute the orbital elements of the planet of interest. If you want the position of the Sun or the Moon, you only need to compute the orbital elements for
the Sun or the Moon. If you want the position of any other planet, you must compute the orbital elements for that planet and for the Sun (of course the orbital
elements for the Sun are really the orbital elements for the Earth; however it's customary to here pretend that the Sun orbits the Earth). This is necessary to be
able to compute the geocentric position of the planet.
Please note that a, the semi-major axis, is given in Earth radii for the Moon, but in Astronomical Units for the Sun and all the planets.
When computing M (and, for the Moon, when computing N and w as well), one will quite often get a result that is larger than 360 degrees, or negative (all
angles are here computed in degrees). If negative, add 360 degrees until positive. If larger than 360 degrees, subtract 360 degrees until the value is less than 360
degrees. Note that, in most programming languages, one must then multiply these angles with pi/180 to convert them to radians, before taking the sine or cosine
of them.
w = 282.9404 + 4.70935E-5 * d
a = 1.000000 (AU)
e = 0.016709 - 1.151E-9 * d
M = 356.0470 + 0.9856002585 * d
www.stjarnhimlen.se/comp/ppcomp.html 5/24
02/03/2020 Computing planetary positions
e = 0.048498 + 4.469E-9 * d
M = 19.8950 + 0.0830853001 * d
Please note than the orbital elements of Uranus and Neptune as given here are somewhat less accurate. They include a long period perturbation between Uranus
and Neptune. The period of the perturbation is about 4200 years. Therefore, these elements should not be expected to give results within the stated accuracy for
more than a few centuries in the past and into the future.
Of course, we're here really computing the position of the Earth in its orbit around the Sun, but since we're viewing the sky from an Earth-centered perspective,
we'll pretend that the Sun is in orbit around the Earth instead.
First, compute the eccentric anomaly E from the mean anomaly M and from the eccentricity e (E and M in degrees):
www.stjarnhimlen.se/comp/ppcomp.html 6/24
02/03/2020 Computing planetary positions
Note that the formulae for computing E are not exact; however they're accurate enough here.
Then compute the Sun's distance r and its true anomaly v from:
xv = r * cos(v) = cos(E) - e
yv = r * sin(v) = sqrt(1.0 - e*e) * sin(E)
v = atan2( yv, xv )
r = sqrt( xv*xv + yv*yv )
atan2() is a function that converts an x,y coordinate pair to the correct angle in all four quadrants. It is available as a library function in Fortran, C and C++. In
other languages, one has to write one's own atan2() function. It's not that difficult:
atan2( y, x ) = atan(y/x) if x positive
atan2( y, x ) = atan(y/x) +- 180 degrees if x negative
atan2( y, x ) = sign(y) * 90 degrees if x zero
See these links for some code in Basic or Pascal. Fortran and C/C++ already has atan2() as a standard library function.
(since the Sun always is in the ecliptic plane, zs is of course zero). xs,ys is the Sun's position in a coordinate system in the plane of the ecliptic. To convert this to
equatorial, rectangular, geocentric coordinates, compute:
xe = xs
ye = ys * cos(ecl)
ze = ys * sin(ecl)
Finally, compute the Sun's Right Ascension (RA) and Declination (Dec):
www.stjarnhimlen.se/comp/ppcomp.html 7/24
02/03/2020 Computing planetary positions
RA = atan2( ye, xe )
Dec = atan2( ze, sqrt(xe*xe+ye*ye) )
We also need the Sun's mean longitude, Ls, which can be computed from the Sun's M and w as follows:
Ls = M + w
The GMST0 is easily computed from Ls (divide by 15 if you want GMST0 in hours rather than degrees), GMST is then computed by adding the UT, and finally
the LST is computed by adding your local longitude (east longitude is positive, west negative).
Note that "time" is given in hours while "angle" is given in degrees. The two are related to one another due to the Earth's rotation: one hour is here the same as
15 degrees. Before adding or subtracting a "time" and an "angle", be sure to convert them to the same unit, e.g. degrees by multiplying the hours by 15 before
adding/subtracting:
GMST0 = Ls + 180_degrees
GMST = GMST0 + UT
LST = GMST + local_longitude
The formulae above are written as if times are expressed in degrees. If we instead assume times are given in hours and angles in degrees, and if we explicitly
write out the conversion factor of 15, we get:
GMST0 = (Ls + 180_degrees)/15 = Ls/15 + 12_hours
GMST = GMST0 + UT
LST = GMST + local_longitude/15
www.stjarnhimlen.se/comp/ppcomp.html 8/24
02/03/2020 Computing planetary positions
M = e * sin(E) - E
where we know M, the mean anomaly, and e, the eccentricity, and we want to find E, the eccentric anomaly.
We start by computing a first approximation of E:
E = M + e * sin(M) * ( 1.0 + e * cos(M) )
where E and M is in radians. If we want E and M in degrees instead, we need to insert a factor of 180/pi like this:
E = M + e*(180/pi) * sin(M) * ( 1.0 + e * cos(M) )
If e, the eccentricity, is less than about 0.05-0.06, this approximation is sufficiently accurate. If the eccentricity is larger, set E0=E and then use this iteration
formula (E and M in degrees):
E1 = E0 - ( E0 - e*(180/pi) * sin(E0) - M ) / ( 1 - e * cos(E0) )
or (E and M in radians):
E1 = E0 - ( E0 - e * sin(E0) - M ) / ( 1 - e * cos(E0) )
For each new iteration, replace E0 with E1. Iterate until E0 and E1 are sufficiently close together (about 0.001 degrees). For comet orbits with eccentricites close
to one, a difference of less than 1E-4 or 1E-5 degrees should be required.
If this iteration formula won't converge, the eccentricity is probably too close to one. Then you should instead use the formulae for near-parabolic or parabolic
orbits.
v = atan2( yv, xv )
r = sqrt( xv*xv + yv*yv )
For the Moon, this is the geocentric (Earth-centered) position in the ecliptic coordinate system. For the planets, this is the heliocentric (Sun-centered) position,
also in the ecliptic coordinate system. If one wishes, one can compute the ecliptic longitude and latitude (this must be done if one wishes to correct for
www.stjarnhimlen.se/comp/ppcomp.html 9/24
02/03/2020 Computing planetary positions
As a check one can compute sqrt(xh*xh+yh*yh+zh*zh), which of course should equal r (except for small round-off errors).
8. Precession
If one wishes to compute the planet's position for some standard epoch, such as 1950.0 or 2000.0 (e.g. to be able to plot the position on a star atlas), one must
add the correction below to lonecl. If a planet's and not the Moon's position is computed, one must also add the same correction to lonsun, the Sun's longitude.
The desired Epoch is expressed as the year, possibly with a fraction.
lon_corr = 3.82394E-5 * ( 365.2422 * ( Epoch - 2000.0 ) - d )
If one wishes the position for today's epoch (useful when computing rising/setting times and the like), no corrections need to be done.
First compute:
Ms, Mm Mean Anomaly of the Sun and the Moon
Nm Longitude of the Moon's node
ws, wm Argument of perihelion for the Sun and the Moon
Ls = Ms + ws Mean Longitude of the Sun (Ns=0)
Lm = Mm + wm + Nm Mean longitude of the Moon
D = Lm - Ls Mean elongation of the Moon
F = Lm - Nm Argument of latitude for the Moon
All perturbation terms that are smaller than 0.01 degrees in longitude or latitude and smaller than 0.1 Earth radii in distance have been omitted here. A few of
the largest perturbation terms even have their own names! The Evection (the largest perturbation) was discovered already by Ptolemy a few thousand years ago
(the Evection was one of Ptolemy's epicycles). The Variation and the Yearly Equation were both discovered by Tycho Brahe in the 16'th century.
The computations can be simplified by omitting the smaller perturbation terms. The error introduced by this seldom exceeds the sum of the amplitudes of the 4-
5 largest omitted terms. If one only computes the three largest perturbation terms in longitude and the largest term in latitude, the error in longitude will rarley
exceed 0.25 degrees, and in latitude 0.15 degrees.
www.stjarnhimlen.se/comp/ppcomp.html 11/24
02/03/2020 Computing planetary positions
The "great Jupiter-Saturn term" is the largest perturbation for both Jupiter and Saturn. Its period is 918 years, and its amplitude is 0.332 degrees for Jupiter and
0.812 degrees for Saturn. These is also a "great Saturn-Uranus term", period 560 years, amplitude 0.035 degrees for Uranus, less than 0.01 degrees for Saturn
(and therefore omitted). The other perturbations have periods between 14 and 100 years. One should also mention the "great Uranus-Neptune term", which has a
period of 4220 years and an amplitude of about one degree. It is not included here, instead it is included in the orbital elements of Uranus and Neptune.
For Mercury, Venus and Mars we can ignore all perturbations. For Neptune the only significant perturbation is already included in the orbital elements, as
mentioned above, and therefore no further perturbation terms need to be accounted for.
If we are computing the Moon's position, this is already the geocentric position, and thus we simply set xg=xh, yg=yh, zg=zh. Otherwise we must also compute
the Sun's position: convert lonsun, rs (where rs is the r computed here) to xs, ys:
www.stjarnhimlen.se/comp/ppcomp.html 12/24
02/03/2020 Computing planetary positions
xs = rs * cos(lonsun)
ys = rs * sin(lonsun)
(Of course, any correction for precession should be added to lonecl and lonsun before converting to xh,yh,zh and xs,ys).
We now have the planet's geocentric (Earth centered) position in rectangular, ecliptic coordinates.
Finally, compute the planet's Right Ascension (RA) and Declination (Dec):
RA = atan2( ye, xe )
Dec = atan2( ze, sqrt(xe*xe+ye*ye) )
www.stjarnhimlen.se/comp/ppcomp.html 13/24
02/03/2020 Computing planetary positions
HA is usually given in the interval -12 to +12 hours, or -180 to +180 degrees. If HA is zero, the object can be seen directly to the south. If HA is negative, the
object is to the east of south, and if HA is positive, the object is to the west of south. IF your computed HA should fall outside this interval, add or subtract 24
hours (or 360 degrees) until HA falls within this interval.
Now it's time to convert our objects HA and Decl to local azimuth and altitude. To do that, we also must know lat, our local latitude. Then we proceed as
follows:
x = cos(HA) * cos(Decl)
y = sin(HA) * cos(Decl)
z = sin(Decl)
This completes our calculation of the local azimuth and altitude. Note that azimuth is 0 at North, 90 deg at East, 180 deg at South and 270 deg at West. Altitude
is of course 0 at the (mathematical) horizon, 90 deg at zenith, and negative below the horizon.
Let's start by computing the Moon's parallax, i.e. the apparent size of the (equatorial) radius of the Earth, as seen from the Moon:
mpar = asin( 1/r )
where r is the Moon's distance in Earth radii. It's simplest to apply the correction in horizontal coordinates (azimuth and altitude): within our accuracy aim of 1-2
arc minutes, no correction need to be applied to the azimuth. One need only apply a correction to the altitude above the horizon:
alt_topoc = alt_geoc - mpar * cos(alt_geoc)
Sometimes one need to correct for topocentric position directly in equatorial coordinates though, e.g. if one wants to draw on a star map how the Moon passes in
front of the Pleiades, as seen from some specific location. Then we need to know the Moon's geocentric Right Ascension and Declination (RA, Decl), the Local
Sidereal Time (LST), and our latitude (lat).
www.stjarnhimlen.se/comp/ppcomp.html 14/24
02/03/2020 Computing planetary positions
Our astronomical latitude (lat) must first be converted to a geocentric latitude (gclat), and distance from the center of the Earth (rho) in Earth equatorial radii. If
we only want an approximate topocentric position, it's simplest to pretend that the Earth is a perfect sphere, and simply set:
gclat = lat, rho = 1.0
However, if we do wish to account for the flattening of the Earth, we instead compute:
gclat = lat - 0.1924_deg * sin(2*lat)
rho = 0.99833 + 0.00167 * cos(2*lat)
Next we compute the Moon's geocentric Hour Angle (HA) from the Moon's geocentric RA. First we must compute LST as described in 5b above, then we
compute HA as:
HA = LST - RA
Now we're ready to convert the geocentric Right Ascension and Declination (RA, Decl) to their topocentric values (topRA, topDecl):
topRA = RA - mpar * rho * cos(gclat) * sin(HA) / cos(Decl)
topDecl = Decl - mpar * rho * sin(gclat) * sin(g - Decl) / sin(g)
(Note that if decl is exactly 90 deg, cos(Decl) becomes zero and we get a division by zero when computing topRA, but that formula breaks down only very close
to the celestial poles anyway and we never see the Moon there. Also if gclat is precisely zero, g becomes zero too, and we get a division by zero when computing
topDecl. In that case, replace the formula for topDecl with
topDecl = Decl - mpar * rho * sin(-Decl) * cos(HA)
which is valid for gclat equal to zero; it can also be used for gclat extremely close to zero).
This correction to topocentric position can also be applied to the Sun and the planets. But since they're much farther away, the correction becomes much smaller.
It's largest for Venus at inferior conjunction, when Venus' parallax is somewhat larger than 32 arc seconds. Within our aim of obtaining a final accuracy of 1-2
arc minutes, it might barely be justified to correct to topocentric position when Venus is close to inferior conjunction, and perhaps also when Mars is at a
favourable opposition. But in all other cases this correction can safely be ignored within our accuracy aim. We only need to worry about the Moon in this case.
If you want to compute topocentric coordinates for the planets too, you do it the same way as for the Moon, with one exception: the Moon's parallax is replaced
by the parallax of the planet (ppar), as computed from this formula:
ppar = (8.794/3600)_deg / r
where r is the distance of the planet from the Earth, in astronomical units.
www.stjarnhimlen.se/comp/ppcomp.html 15/24
02/03/2020 Computing planetary positions
Next compute the heliocentric ecliptic longitude and latitude (degrees), and distance (a.u.):
lonecl = 238.9508 + 0.00400703 * d
- 19.799 * sin(P) + 19.848 * cos(P)
+ 0.897 * sin(2*P) - 4.956 * cos(2*P)
+ 0.610 * sin(3*P) + 1.211 * cos(3*P)
- 0.341 * sin(4*P) - 0.190 * cos(4*P)
+ 0.128 * sin(5*P) - 0.034 * cos(5*P)
- 0.038 * sin(6*P) + 0.031 * cos(6*P)
+ 0.020 * sin(S-P) - 0.010 * cos(S-P)
latecl = -3.9082
- 5.453 * sin(P) - 14.975 * cos(P)
+ 3.527 * sin(2*P) + 1.673 * cos(2*P)
- 1.051 * sin(3*P) + 0.328 * cos(3*P)
+ 0.179 * sin(4*P) - 0.292 * cos(4*P)
+ 0.019 * sin(5*P) + 0.100 * cos(5*P)
- 0.031 * sin(6*P) - 0.026 * cos(6*P)
+ 0.011 * cos(S-P)
r = 40.72
+ 6.68 * sin(P) + 6.90 * cos(P)
- 1.18 * sin(2*P) - 0.03 * cos(2*P)
+ 0.15 * sin(3*P) - 0.14 * cos(3*P)
Now we know the heliocentric distance and ecliptic longitude/latitude for Pluto. To convert to geocentric coordinates, do as for the other planets.
www.stjarnhimlen.se/comp/ppcomp.html 16/24
02/03/2020 Computing planetary positions
R is the planet's geocentric distance in astronomical units, and d is the planet's apparent diameter at a distance of 1 astronomical unit. d0 is of course different
for each planet. The values below are given in seconds of arc. Some planets have different equatorial and polar diameters:
Mercury 6.74"
Venus 16.92"
Earth 17.59" equ 17.53" pol
Mars 9.36" equ 9.28" pol
Jupiter 196.94" equ 185.08" pol
Saturn 165.6" equ 150.8" pol
Uranus 65.8" equ 62.1" pol
Neptune 62.2" equ 60.9" pol
The Sun's apparent diameter at 1 astronomical unit is 1919.26". The Moon's apparent diameter is:
d = 1873.7" * 60 / r
Two other quantities we'd like to know are the phase angle and the elongation.
The phase angle tells us the phase: if it's zero the planet appears "full", if it's 90 degrees it appears "half", and if it's 180 degrees it appears "new". Only the
Moon and the inferior planets (i.e. Mercury and Venus) can have phase angles exceeding about 50 degrees.
The elongation is the apparent angular distance of the planet from the Sun. If the elongation is smaller than about 20 degrees, the planet is hard to observe, and if
it's smaller than about 10 degrees it's usually not possible to observe the planet.
To compute phase angle and elongation we need to know the planet's heliocentric distance, r, its geocentric distance, R, and the distance to the Sun, s. Now we
can compute the phase angle, FV, and the elongation, elong:
elong = acos( ( s*s + R*R - r*r ) / (2*s*R) )
When we know the phase angle, we can easily compute the phase:
phase = ( 1 + cos(FV) ) / 2 = hav(180_deg - FV)
hav is the "haversine" function. The "haversine" (or "half versine") is an old and now obsolete trigonometric function. It's defined as:
hav(x) = ( 1 - cos(x) ) / 2 = sin^2 (x/2)
www.stjarnhimlen.se/comp/ppcomp.html 17/24
02/03/2020 Computing planetary positions
As usual we must use a different procedure for the Moon. Since the Moon is so close to the Earth, the procedure above would introduce too big errors. Instead
we use the Moon's ecliptic longitude and latitude, mlon and mlat, and the Sun's ecliptic longitude, slon, to compute first the elongation, then the phase angle, of
the Moon:
elong = acos( cos(slon - mlon) * cos(mlat) )
FV = 180_deg - elong
Finally we'll compute the magnitude (or brightness) of the planets. Here we need to use a formula that's different for each planet. FV is the phase angle (in
degrees), r is the heliocentric and R the geocentric distance (both in AU):
Mercury: -0.36 + 5*log10(r*R) + 0.027 * FV + 2.2E-13 * FV**6
Venus: -4.34 + 5*log10(r*R) + 0.013 * FV + 4.2E-7 * FV**3
Mars: -1.51 + 5*log10(r*R) + 0.016 * FV
Jupiter: -9.25 + 5*log10(r*R) + 0.014 * FV
Saturn: -9.0 + 5*log10(r*R) + 0.044 * FV + ring_magn
Uranus: -7.15 + 5*log10(r*R) + 0.001 * FV
Neptune: -6.90 + 5*log10(r*R) + 0.001 * FV
** is the power operator, thus FV**6 is the phase angle (in degrees) raised to the sixth power. If FV is 150 degrees then FV**6 becomes ca 1.14E+13, which is
a quite large number.
For the Moon, we also need the heliocentric distance, r, and geocentric distance, R, in AU (astronomical units). Here r can be set equal to the Sun's geocentric
distance in AU. The Moon's geocentric distance, R, previously computed i Earth radii, must be converted to AU's - we do this by multiplying by sin(17.59"/2) =
1/23450. Or we could modify the magnitude formula for the Moon so it uses r in AU's and R in Earth radii:
Moon: -21.62 + 5*log10(r*R) + 0.026 * FV + 4.0E-9 * FV**4
Saturn needs special treatment due to its rings: when Saturn's rings are "open" then Saturn will appear much brighter than when we view Saturn's rings
edgewise. We'll compute ring_mang like this:
ring_magn = -2.6 * sin(abs(B)) + 1.2 * (sin(B))**2
Here B is the tilt of Saturn's rings which we also need to compute. Then we start with Saturn's geocentric ecliptic longitude and latitude (los, las) which we
compute from the xg, yg, zg computed for Saturn in paragraph 11 above:
los = atan2( yg, xg )
las = atan2( zg, sqrt( xg*xg + yg*yg ) )
We also need the tilt of the rings to the ecliptic, ir, and the "ascending node" of the plane of the rings, Nr:
ir = 28.06_deg
Nr = 169.51_deg + 3.82E-5_deg * d
www.stjarnhimlen.se/comp/ppcomp.html 18/24
02/03/2020 Computing planetary positions
Here d is our "day number" which we've used so many times before. Now let's compute the tilt of the rings:
B = asin( sin(las) * cos(ir) - cos(las) * sin(ir) * sin(los-Nr) )
Most often M, the mean anomaly, is given for another day than the day we want to compute the asteroid's position for. If the daily motion, n, is given, simply
add n * (time difference in days) to M. If n is not given, but the period P (in days) is given, then n = 360.0/P. If P is not given, it can be computed from:
P = 365.2568984 * a**1.5 (days) = 1.00004024 * a**1.5 (years)
When all orbital elements has been computed, proceed as with the other planets (section 6).
where P is given in days, and d-dT of course is the time since last perihelion, also in days.
Also, a, the semi-major axis, is usually not given. Instead q, the perihelion distance, is given. a can easily be computed from q and e.
a = q / (1.0 - e)
www.stjarnhimlen.se/comp/ppcomp.html 19/24
02/03/2020 Computing planetary positions
Compute the "day number", d, for T, the moment of perihelion, call this dT. Compute d for the moment we want to compute a position, call it d (section 3). The
constant k is the Gaussian gravitational constant: k = 0.01720209895 exactly!
Then compute:
H = (d-dT) * (k/sqrt(2)) / q**1.5
cbrt() is the cube root function: cbrt(x) = x**(1.0/3.0). The formulae has been devised so that both g+h and g-h always are positive. Therefore one can here
safely compute cbrt(x) as exp(log(x)/3.0) . In general, cbrt(-x) = -cbrt(x) and of course cbrt(0) = 0.
Instead of trying to compute some eccentric anomaly, we compute the true anomaly and the heliocentric distance directly:
v = 2.0 * atan(s)
r = q * ( 1.0 + s*s )
When we know v, the true anomaly, and r, the heliocentric distance, we can proceed by computing the position in space (section 7).
As for the purely parabolic orbit, we start by computing the time since perihelion in days, d-dT, and the perihelion distance, q. We also need to know the
eccentricity, e. The constant k is the Gaussian gravitational constant: k = 0.01720209895 exactly!
www.stjarnhimlen.se/comp/ppcomp.html 20/24
02/03/2020 Computing planetary positions
C = W*W / (1 + W*W)
g = f * C*C
w = W * ( 1 + f * C * ( a1 + a2*g + a3*g*g ) )
v = 2 * atan(w)
r = q * ( 1 + w*w ) / ( 1 + w*w * f )
This algorithm yields the true anomaly, v, and the heliocentric distance, r, for a nearly-parabolic orbit. Note that this algorithm will fail very far from the
perihelion; however the accuracy is sufficient for all comets closer than Pluto.
When we know v, the true anomaly, and r, the heliocentric distance, we can proceed by computing the position in space (section 7).
We start by computing the semi-major axis a of the hyperbola from q, the perihelion distance, and e, the eccentricity. Note that since the eccentricity e is larger
than one for a hyperbola, the semi-major axis will be negative.
a = q / (1 - e)
Next, we compute the hyperbolic equivalent of the mean anomaly, M, for an elliptic orbit. We call it M here too.
Since a is negative in the hyperbolic case, we must negate it to successfully rasie it to the power of 1.5:
M = (t-T) / (-a)**1.5
Now we must use the hyperbolic functions sinh(x) and cosh(x). If you don't have them available on your computer system, you may need to define them
yourself.
www.stjarnhimlen.se/comp/ppcomp.html 21/24
02/03/2020 Computing planetary positions
and, like in the case of an elliptic orbit, we start by computing a first approximation of F, and then iterate with an iteration formula until the value of F
converges.
The first approximation of F can be as simple as this:
F = M
Before the first iteration set F0 = F, then after each iteration set F0 = F1.
Repeat the iterations until F1 and F0 have converged to the same value with sufficient accuracy:
When we know F we can compute v, the true anomaly, and r, the heliocentric distance:
v = 2 * arctan( sqrt((e+1)/(e-1)) ) * tanh(F/2)
r = a * ( 1 - e*e ) / ( 1 + e * cos(v) )
When we know v, the true anomaly, and r, the heliocentric distance, we can proceed by computing the position in space (section 7).
and completely out of scope for this description. As a rule of thumb, though, one can assume that an asteriod, if one uses the orbital elements for a specific
epoch, one or a few revolutions away from that moment will have an error in its computed position of at least one or a few arc minutes, and possibly more. The
errors will accumulate with time.
Elwood Downey's Xephem and Ephem programs, with C source code: http://www.clearskyinstitute.com/xephem/.
Ephem can also be found at https://web.archive.org/web/20030726043728/ftp://seds.lpl.arizona.edu/pub/software/pc/general/ as ephem421.zip
VSOP2010: ftp://ftp.imcce.fr/pub/ephem/planets/vsop2010/
VSOP2013: ftp://ftp.imcce.fr/pub/ephem/planets/vsop2013/
www.stjarnhimlen.se/comp/ppcomp.html 24/24