9
$\begingroup$

Initially I thought that the problem is trivial, but it turned out to be something relatively complex. I found no one place that would answer the question directly nor a quick guide showing what should be learned to find answer to the question how to calculate current distance from planet Earth to any other planet in the solar system.

I would approach this by finding orbital parameters of each planet in the solar system, then calculating current position of Earth and a planet in a virtual 3d grid. Then distance could be calculated as a distance between two points. However, orbital parameters do not indicate where the body was at a specified date and time to calculate current positioon (or does it?).

Anyways, I assume the approach may not be the best one, so could anyone guide me please through the steps what I should do to find out the answer? I am not asking for a detailed answer (but it is also extremely welcome), rather a quick guide with steps to perform.

$\endgroup$
2

2 Answers 2

6
$\begingroup$

You could use Astropy if you want to quickly check your calculations:

from datetime import datetime
from astropy.time import Time
from astropy.coordinates import solar_system_ephemeris, get_body

now = Time(datetime.now())


def describe_coordinates(name, position, attrs=['ra', 'dec', 'distance']):
    print('  %s' % name)
    for attr in attrs:
        print('    %-8s : %s' % (attr, getattr(position, attr)))
    print()


with solar_system_ephemeris.set('builtin'):
    earth = get_body('earth', now)
    print('# At %s' % now)
    print()
    for body_name in solar_system_ephemeris.bodies:
        if body_name != 'earth':
            body = get_body(body_name, now)
            body_name = body_name.capitalize()
            print('## %s' % body_name)
            print()
            distance = earth.separation_3d(body)
            describe_coordinates('Geocentric', body)
            describe_coordinates('Heliocentric', body.hcrs)
            describe_coordinates('Heliocentric, cartesian', body.hcrs.cartesian, 'xyz')
            print('  Distance to Earth : %s' % distance)
            print()
            print()

It outputs:

# At 2023-04-27 09:44:53.778255

## Sun

  Geocentric
    ra       : 34d14m10.90835979s
    dec      : 13d42m21.46001395s
    distance : 1.0063943549757455 AU

  Heliocentric
    ra       : 106d14m27.87159228s
    dec      : 22d28m56.94074267s
    distance : 5.130514948556264e-08 AU

  Heliocentric, cartesian
    x        : -1.3258422804085509e-08 AU
    y        : 4.5513975699407177e-08 AU
    z        : 1.9619138730275765e-08 AU

  Distance to Earth : 1.0063943549757457 AU


## Moon

  Geocentric
    ra       : 124d48m02.39525773s
    dec      : 25d00m38.34773626s
    distance : 0.0026995142599885707 AU

  Heliocentric
    ra       : 214d05m54.6347582s
    dec      : -13d38m39.53898544s
    distance : 1.0061506676951295 AU

  Heliocentric, cartesian
    x        : -0.8096551559027314 AU
    y        : -0.548147038016342 AU
    z        : -0.23734472679499202 AU

  Distance to Earth : 0.002699514259988571 AU


## Mercury

  Geocentric
    ra       : 40d39m03.98386417s
    dec      : 17d43m37.96451338s
    distance : 0.5922967982014921 AU

  Heliocentric
    ra       : 205d38m53.37282051s
    dec      : -7d50m43.33450139s
    distance : 0.42581532038893316 AU

  Heliocentric, cartesian
    x        : -0.38026642171667674 AU
    y        : -0.18258630002004464 AU
    z        : -0.05812382160280432 AU

  Distance to Earth : 0.5922967982014921 AU


## Venus

  Geocentric
    ra       : 77d04m03.06478937s
    dec      : 25d11m50.50768648s
    distance : 1.0084230132455214 AU

  Heliocentric
    ra       : 150d41m16.70795145s
    dec      : 15d24m01.67653178s
    distance : 0.718625801083958 AU

  Heliocentric, cartesian
    x        : -0.6041178464130806 AU
    y        : 0.33918186973575504 AU
    z        : 0.19084110896591244 AU

  Distance to Earth : 1.0084230132455214 AU


## Earth-moon-barycenter

  Geocentric
    ra       : 120d30m00.75838748s
    dec      : 27d21m21.06357159s
    distance : 2.3979115366573416e-05 AU

  Heliocentric
    ra       : 214d14m26.21137691s
    dec      : -13d42m26.02630471s
    distance : 1.006390375351769 AU

  Heliocentric, cartesian
    x        : -0.808269742135427 AU
    y        : -0.5501375148644518 AU
    z        : -0.23847500138959987 AU

  Distance to Earth : 2.3979115366573416e-05 AU


## Mars

  Geocentric
    ra       : 108d21m31.74114144s
    dec      : 24d10m38.18627597s
    distance : 1.705887175958566 AU

  Heliocentric
    ra       : 144d28m48.65313552s
    dec      : 16d05m23.49287567s
    distance : 1.660391044142945 AU

  Heliocentric, cartesian
    x        : -1.2984791319650166 AU
    y        : 0.9268739921775513 AU
    z        : 0.4601684104176693 AU

  Distance to Earth : 1.705887175958566 AU


## Jupiter

  Geocentric
    ra       : 23d42m19.54748266s
    dec      : 8d44m48.66999627s
    distance : 5.935789547383545 AU

  Heliocentric
    ra       : 21d37m27.82704617s
    dec      : 7d42m28.28843327s
    distance : 4.953473431718855 AU

  Heliocentric, cartesian
    x        : 4.563240623775347 AU
    y        : 1.8089627548781806 AU
    z        : 0.6643702279109842 AU

  Distance to Earth : 5.935789547383545 AU


## Saturn

  Geocentric
    ra       : 337d10m28.78583463s
    dec      : -11d03m14.30536309s
    distance : 10.241761362879442 AU

  Heliocentric
    ra       : 332d15m03.21164734s
    dec      : -12d58m37.18881227s
    distance : 9.805931916932145 AU

  Heliocentric, cartesian
    x        : 8.45656099271295 AU
    y        : -4.449043850687695 AU
    z        : -2.2020185627492626 AU

  Distance to Earth : 10.24176136287944 AU


## Uranus

  Geocentric
    ra       : 45d31m37.96826473s
    dec      : 16d51m37.0661311s
    distance : 20.636385176873777 AU

  Heliocentric
    ra       : 46d06m59.18842415s
    dec      : 17d00m23.26250133s
    distance : 19.650620652696077 AU

  Heliocentric, cartesian
    x        : 13.026059371947637 AU
    y        : 13.543854975187806 AU
    z        : 5.747404778310051 AU

  Distance to Earth : 20.636385176873777 AU


## Neptune

  Geocentric
    ra       : 357d04m30.25912968s
    dec      : -2d33m24.96298302s
    distance : 30.67105009955795 AU

  Heliocentric
    ra       : 355d56m45.66281597s
    dec      : -3d04m39.72305339s
    distance : 29.910360622756777 AU

  Heliocentric, cartesian
    x        : 29.792487947312594 AU
    y        : -2.111502508215247 AU
    z        : -1.605892789196556 AU

  Distance to Earth : 30.67105009955795 AU

You could use a Python debugger to see what the intermediary steps are, or move around the code (e.g. in VSCode, Spyder or PyCharm) with "Go To Definition" feature.

$\endgroup$
4
  • 2
    $\begingroup$ Your answer is outstanding! Thank you! $\endgroup$ Apr 26, 2023 at 20:07
  • $\begingroup$ @noonespecial My pleasure! I always like to play a bit with Astropy. I've updated the answer, BTW, to show both spherical and Cartesian coordinates in the heliocentric frame. $\endgroup$ Apr 27, 2023 at 7:48
  • $\begingroup$ Way too many significant digits in that answer. $\endgroup$
    – Wyck
    Apr 28, 2023 at 13:45
  • $\begingroup$ @Wyck: You're correct. That's the standard representation of Astropy coordinates. I didn't want to make the code more complex than it is. $\endgroup$ Apr 28, 2023 at 13:47
17
$\begingroup$

Here's a short answer to get the ball rolling:

However, orbital parameters do not indicate where the body was at a specified date and time to calculate current position...

That's absolutely right, you've got the picture correctly. You have two problems every orbital mechanic faces;

  1. There is no analytical solution for position as a function of time for any Keplerian orbit except circles.
  2. There's all those transformations from a Keplerian orbit in its 2D plane back to the 3D world.

Each of those are addressed in many questions and answers both here in Space SE and in Astronomy SE. You can start with answer(s) to Calculate position of planet on fictitious orbit each day and the links therein, and search further.

If you want to use an ephemeris and a python package, then check out Skyfield.

And as PM2Ring points out there is

For more resources see Where can I find the positions of the planets, stars, moons, artificial satellites, etc. and visualize them? in Astronomy SE.

$\endgroup$
2
  • 1
    $\begingroup$ This is very helpful answer. Lots of useful insights and resources. Thank you. $\endgroup$ Apr 26, 2023 at 9:12
  • 6
    $\begingroup$ While it is technically true that no analytic solution exists for Kepler's equation, it's very tame numerically. See "Fixed-point iteration" at the end of en.wikipedia.org/wiki/Kepler%27s_equation. Why is that at the end? I don't know: the authors seem to want to revel in the difficulty of solving it in other ways. $\endgroup$
    – John Doty
    Apr 26, 2023 at 11:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.