I have two sources with equatorial coordinates (ra, dec) and (ra_0, dec_0) located at distances r and r_0 , and I need to calculate the 3D distance between them.
I use two approaches that should give the same result, as far as I understand, but do not do this.
The first approach is to use astropy separation_3d . The second approach is to use an expression that gives the distance between two sources with spherical coordinates:

as shown here .
In MCVE, the return values โโare below:
91.3427173002 pc 93.8470493776 pc
Should these two values โโbe equal?
MCVE :
from astropy.coordinates import SkyCoord from astropy import units as u import numpy as np # Define some coordinates and distances for the sources. c1 = SkyCoord(ra=9.7*u.degree, dec=-50.6*u.degree, distance=1500.3*u.pc) c2 = SkyCoord(ra=7.5*u.degree, dec=-47.6*u.degree, distance=1470.2*u.pc) # Obtain astropy distance between c1 & c2 coords. print c1.separation_3d(c2) # Obtain distance between c1 & c2 coords using explicit expression. ra_0, dec_0, r_0 = c1.ra.radian, c1.dec.radian, c1.distance ra, dec, r = c2.ra.radian, c2.dec.radian, c2.distance alpha_delta_par = np.sin(dec) * np.sin(dec_0) * np.cos(ra - ra_0) +\ np.cos(dec) * np.cos(dec_0) d_pc = np.sqrt(r**2 + r_0**2 - 2*r*r_0*alpha_delta_par) print d_pc
source share