Distance Between Bodies In Space
Program by Jay Tanner
Optional Body Names or IDs
 and      Dist Units:
Sirius (α CMa) Right Ascension Declination Distance Value
Vega (α Lyr)
Double-Click Within Text Area to Select ALL Code
The Basic Starting Variables
Rectangular Coordinates For Body1
Rectangular Coordinates For Body2
Distance Between the Bodies in 3D Space

The Process

                     NUMERICAL WORKSHEET FOR THE ABOVE COMPUTATIONS

Let:
αn = RA of Bodyn in Hours
δn = Declination of Bodyn in Degrees
Rn = Distance of Bodyn from Sun or Earth in any convenient units

NOTE:
The distance units can be any convenient units.   For stars and planets it is
usually LY or AU respectively. The computed output distance will be expressed
in the same units used for input.

******************************************************************************
For Body1 = Sirius (α CMa)

α1 = 6.7524769444 h = 101.2871541660 °
δ1 = -16.7161166667 °
R1 = 8.6 LY

---------------------------------------------
Compute essential cosines and sines for Body1

Cos(α1) =  -0.195726283455357        Sin(α1) =  +0.980658565436897
Cos(δ1) =  +0.957741625629213        Sin(δ1) =  -0.287629933312083

---------------------------------------------
Compute rectangular XYZ-coordinates for Body1

x1 = R1 * cos(α1) * cos(δ1)  =    -1.612114796496
y1 = R1 * sin(α1) * cos(δ1)  =    +8.077270746379
z1 = R1 * sin(δ1)            =    -2.473617426484


******************************************************************************
For Body2 = Vega (α Lyr)

α2 = 18.6156489861 h = 279.2347347915 °
δ2 = +38.7836889444 °
R2 = 25.04 LY

---------------------------------------------
Compute essential cosines and sines for Body2

Cos(α2) =  +0.160479596286528        Sin(α2) =  -0.98703915787354
Cos(δ2) =  +0.779516315939937        Sin(δ2) =  +0.626381922778291

---------------------------------------------
Compute rectangular XYZ-coordinates For Body2

x2 = R2 * cos(α2) * cos(δ2)  =    +3.132415450567
y2 = R2 * sin(α2) * cos(δ2)  =   -19.266104725972
z2 = R2 * sin(δ2)            =   +15.684603346368


==============================================================================
Compute the differences between the rectangular coordinates. These differences
may equate to negative or positive values.

dx = x2 − x1  = (  +3.132415450567 -   -1.612114796496)	=    +4.744530247063
dy = y2 − y1  = ( -19.266104725972 -   +8.077270746379)	=   -27.343375472352
dz = z2 − z1  = ( +15.684603346368 -   -2.473617426484)	=   +18.158220772852

Do not be confused by the dual signs between the values.   If the operator and
the numerical sign are the same, then replace the dual signs with a single (+)
sign operator.  If the operator and the numerical sign are different, then re-
place the dual signs with a single (-) sign operator.

------------------------------------------------------------------------------
Compute the squares of the differences between the rectangular XYZ-coordinates.
These will always equate to positive values.

d²x = (x2 − x1)²  =   22.510567265300
d²y = (y2 − y1)²  =  747.660182222000
d²z = (z2 − z1)²  =  329.720981635645

------------------------------------------------------------------------------
  Finally, Compute the Distance (D) Between the Bodies in LY.

  The distance between the bodies equates to the square root of the sum of
  the squares of the differences between their rectangular XYZ-coordinates.

  D = Distance Between the Bodies
    = SqRt(d²x + d²y + d²z)
    = SqRt(22.5105672653 + 747.660182222 + 329.72098163565)
    = SqRt(1099.8917311229)
    = 33.164615648654 LY

      So, the distance between the bodies is about 33.165 LY

------------------------------------------------------------------------------
   CAVEAT:
   The computed distances are only as accurate as the data provided for the
   computations.  The initial demo values use J2000.0 coordinates for the
   stars Sirius (alpha CMa) and Vega (alpha Lyr), as taken from WikiPedia.

   Accurate stellar distances are notoriously hard to measure precisely, so we
   shouldn't expect them to be accurate beyond 2 or 3 decimals at best, so it
   is sensible to round off our final computations accordingly to be practical.

Program by Jay Tanner
v3.1 - Revised: 1970-January-01-Thursday at Local Time 12:00:00 AM (UTC−05:00)