As of Version 13.2, AstroDistance is a built-in symbol.

Function Repository Resource:

AstroDistance

Source Notebook

Compute the distance between astronomical entities

Contributed by: Jeff Bryant

ResourceFunction["AstroDistance"][entity1,entity2]

computes the distance between entity1 and entity2 for the current date and time.

ResourceFunction["AstroDistance"][entity1,entity2,date]

computes the distance between entity1 and entity2 for the specified date.

ResourceFunction["AstroDistance"][{entity1,,entityn}]

computes the distance between entity1 and entityn, through all the intermediate entityi, for the current date and time.

ResourceFunction["AstroDistance"][{entity1,,entityn},date]

computes the total distance from entity1 to entityn, through all the intermediate entityi, for the specified date.

Details and Options

An internet connection is required.
date must be a DateObject, Interval or a DateInterval.
DateInterval functionality is only available in Version 12.1 and later.
Interval can be used to specify intervals of dates in Versions prior to 12.1.
When an interval is used, the result is a TimeSeries object containing values over the interval.
Shorter dates can be used: DateObject[{y}] is equivalent to DateObject[{y,1,1,0,0,0}], DateObject[{y,m}] to DateObject[{y,m,1,0,0,0}], etc.
The coordinates of all entities must be known or a missing result will be returned.
Supported entity types are "Planet", "MinorPlanet", "Comet", "Exoplanet", "Star", "StarCluster", "Nebula" and "Pulsar".
Distances are all measured from center to center and along a straight line.
Distances are returned in astronomical units by default.
Distances to extra‐solar system objects are based on light‐travel distances for a fixed epoch and ignore effects such as proper motion.
ResourceFunction["AstroDistance"] accepts the following options:
"Increment"Automaticincrement used when sampling date intervals
TargetUnitsAutomatictarget units
"Increment" only applies in cases where the supplied date spec is a DateInterval or Interval.
Possible increments are denominated in the following calendar steps and day types: "Year", "Quarter", "Month", "Week", "Day", "Hour", "Minute", "Second", "Weekday", "Weekend", Monday through Sunday, "EndOfMonth", "BeginningOfMonth" and "BusinessDay".

Examples

Basic Examples (5) 

Compute the current distance between Mars and Jupiter:

In[1]:=
ResourceFunction["AstroDistance"][Entity["Planet", "Mars"], Entity["Planet", "Jupiter"]]
Out[1]=

Compute the distance between Mars and Jupiter on a specified date:

In[2]:=
ResourceFunction["AstroDistance"][Entity["Planet", "Mars"], Entity["Planet", "Jupiter"], DateObject[{2018, 9, 13}, "Day", "Gregorian", -5.`]]
Out[2]=

Compute the current total distance between entities:

In[3]:=
ResourceFunction[
 "AstroDistance"][{Entity["Planet", "Mars"], Entity["Planet", "Jupiter"], Entity["Planet", "Saturn"], Entity["Planet", "Uranus"]}]
Out[3]=

Compute the total distance between entities on a specified date:

In[4]:=
ResourceFunction[
 "AstroDistance"][{Entity["Planet", "Mars"], Entity["Planet", "Jupiter"], Entity["Planet", "Saturn"], Entity["Planet", "Uranus"]}, DateObject[{2018, 9, 13}, "Day", "Gregorian", -5.`]]
Out[4]=

Compute the distance between two objects over a range of dates:

In[5]:=
ts = ResourceFunction["AstroDistance"][Entity["Planet", "Earth"], Entity["Planet", "Mars"], DateInterval[{DateObject[{2020, 1, 1}], DateObject[{2021, 1, 1}]}]]
Out[5]=
In[6]:=
DateListPlot[ts, FrameLabel -> Automatic]
Out[6]=

Scope (2) 

Entities can be in different domains:

In[7]:=
ResourceFunction["AstroDistance"][Entity["Planet", "Mars"], Entity["Star", "ProximaCentauri"]]
Out[7]=
In[8]:=
ResourceFunction["AstroDistance"][Entity["Exoplanet", "55Cancrie"], Entity["Planet", "Uranus"]]
Out[8]=

Results are automatically given in appropriate units by default:

In[9]:=
ResourceFunction["AstroDistance"][Entity["Star", "Rigel"], Entity["Star", "Zubenelgenubi"]]
Out[9]=

Options (3) 

TargetUnits (1) 

Target units can be specified:

In[10]:=
ResourceFunction["AstroDistance"][Entity["Planet", "Mars"], Entity["Star", "ProximaCentauri"], TargetUnits -> "Kilometers"]
Out[10]=

Increment (2) 

Intervals of dates must be sampled in order to do the necessary computations. By default, the sampling increment is automatically determined:

In[11]:=
ResourceFunction["AstroDistance"][Entity["Planet", "Earth"], Entity["Planet", "Mars"], DateInterval[{DateObject[{2020, 1, 1}], DateObject[{2021, 1, 1}]}]]
Out[11]=

The number of sample points for the resulting time series can be controlled by setting the "Increment" option manually:

In[12]:=
ts = ResourceFunction["AstroDistance"][Entity["Planet", "Earth"], Entity["Planet", "Mercury"], DateInterval[{DateObject[{2020, 1, 1}], DateObject[{2021, 1, 1}]}], "Increment" -> "Month"]
Out[12]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 3.0.0 – 12 October 2020
  • 2.0.0 – 03 February 2020
  • 1.0.0 – 29 April 2019

Related Resources

License Information