<p>The python library, <a href="http://rhodesmill.org/pyephem/" rel="nofollow">pyephem</a> has this function.</p>

<pre><code>import ephem
km = 149597871   # 1AU in km
m = ephem.Mars()
m.compute('2016/3/18')
print(m.earth_distance*km)

136729311.6250654
</code></pre>

CC BY-SA 3.0
2016-03-19T06:33:24.210Z
Note that the implied accuracy is well beyond what is realistic. This doesn't actually give the distance accurate to 1/10 mm!
James K
CC BY-SA 4.0
2019-01-12T03:42:06.253Z
related: [PyEphem under the hood - how does it calculate position of planets?](https://stackoverflow.com/q/34487170/3904031) As far as I can figure, starting in 2010 the VSOP models are fitted to [ephemerides](https://english.stackexchange.com/q/370655/217285) derived from numerical integration. Before that it may have been purely a perturbative model. The "[new hotness](https://www.youtube.com/watch?v=ha-uagjJQ9k)" Python package [Skyfield](https://rhodesmill.org/skyfield/) on the other hand will directly interpolate a JPL ephemeris of your choosing. Both are supported by the same person.
uhoh
CC BY-SA 3.0
2016-03-18T17:39:54.417Z
2016-03-18T18:24:20.583Z
2016-03-18T18:24:20.583Z
James K
<p>Do not underestimate the astronomers! 100 km? That's absurd. Saturn('s center of mass) is located to within one mile's distance from the Sun. Mars is of course even much better located.</p>

<p><a href="http://theskylive.com/mars-tracker" rel="nofollow">Here's a site I googled</a> that seems to give current distance to Mars to within single kilometers. I don't know how that site makes up its numbers, but it is certainly possible to measure it like that. With mutual radio communication, there are really good opportunities for precis distance measuring. 135,834,832 km just now! Pretty close and that's why the ExoMars space probe was launched towards Mars a few days ago. And <a href="http://cseligman.com/text/planets/marsoppositions.htm" rel="nofollow">here is</a> a table with the conunction distances just past and soon coming up.</p>

CC BY-SA 4.0
2019-01-12T03:31:00.273Z
`+1` for *Do not underestimate the astronomers!*
uhoh
CC BY-SA 3.0
2016-03-18T15:26:51.590Z
2016-03-18T15:33:06.247Z
2016-03-18T15:33:06.247Z
LocalFluff
<p>I've been scouring the internet for a straightforward way to approximate the distance between Earth and Mars at a given time. I hope to achieve an accuracy of about 100km. </p>

CC BY-SA 3.0
2016-03-18T15:20:06.080Z
Try this: http://www.calsky.com/cs.cgi/Planets/5/1?
Dean
CC BY-SA 3.0
2016-03-19T09:29:43.107Z
If you're willing to do small computations then jpl horizons is a good source http://ssd.jpl.nasa.gov/?horizons
Astroynamicist
<distances>
Approximate distance from Earth to Mars at a given moment with reasonable (+/-100km) accuracy?
Carlos Vergara
# Approximate distance from Earth to Mars at a given moment with reasonable (+/-100km) accuracy?

(Asked by: username_0 on 2016-03-18)

I've been scouring the internet for a straightforward way to approximate the distance between Earth and Mars at a given time. I hope to achieve an accuracy of about 100km.

**Tags:** distances

> **Comments:**
> **username_1**: Try this: http://www.calsky.com/cs.cgi/Planets/5/1?  
> **username_2**: If you're willing to do small computations then jpl horizons is a good source http://ssd.jpl.nasa.gov/?horizons  

---

## 2 answers

### Answer by username_3 on 2016-03-18. Score: 3

The python library, [pyephem](http://rhodesmill.org/pyephem/) has this function.

```
import ephem
km = 149597871   # 1AU in km
m = ephem.Mars()
m.compute('2016/3/18')
print(m.earth_distance*km)

136729311.6250654

```

> **Comments:**
> **username_3**: Note that the implied accuracy is well beyond what is realistic. This doesn't actually give the distance accurate to 1/10 mm!  
> **username_4**: related: [PyEphem under the hood - how does it calculate position of planets?](https://stackoverflow.com/q/34487170/3904031) As far as I can figure, starting in 2010 the VSOP models are fitted to [ephemerides](https://english.stackexchange.com/q/370655/217285) derived from numerical integration. Before that it may have been purely a perturbative model. The "[new hotness](https://www.youtube.com/watch?v=ha-uagjJQ9k)" Python package [Skyfield](https://rhodesmill.org/skyfield/) on the other hand will directly interpolate a JPL ephemeris of your choosing. Both are supported by the same person.  

---

### Answer by username_5 on 2016-03-18. Score: 3

Do not underestimate the astronomers! 100 km? That's absurd. Saturn('s center of mass) is located to within one mile's distance from the Sun. Mars is of course even much better located.

[Here's a site I googled](http://theskylive.com/mars-tracker) that seems to give current distance to Mars to within single kilometers. I don't know how that site makes up its numbers, but it is certainly possible to measure it like that. With mutual radio communication, there are really good opportunities for precis distance measuring. 135,834,832 km just now! Pretty close and that's why the ExoMars space probe was launched towards Mars a few days ago. And [here is](http://cseligman.com/text/planets/marsoppositions.htm) a table with the conunction distances just past and soon coming up.

> **Comments:**
> **username_4**: `+1` for *Do not underestimate the astronomers!*  

---

