I have ra and dec and corresponding redshift of galaxies. I would like to calculate the distance between two galaxies.

I did like this to find the nearest neighbour galaxies.

Suppose I am trying to find the nearest neighbour of galaxy A(which has RA,DEC)  and the target galaxy has ra1,dec1,

so to find the distance between two galaxy, I did like this

dist_sqd= sqrt( (RA-ra1)**2 + (DEC-dec1)**2 ) 
#RA, DEC are in degree

Is this the correct way to find the distance.

As there is projection in 2D, Since, I already have redshift, Is there any best way to find the distance between two galaxies properly?


1 Answer 1


Since you are presumably using Hubble's law to get the distance to each of the galaxies, the approximate estimate would the "the greater distance ± the smaller distance".

But the geometric solution is useful too. Your strategy appears to be something like:

  1. Calculate angular separation $\Theta$ from RA and DEC.
  2. By trigonometry, the distance is then $d_{a,b} = \sqrt{d_a^2\sin(\Theta)^2 + (d_b - d_a\cos(\Theta))^2}$

The problem is that you can not calculate the angular separation on a sphere by the Pythagorean formula, instead, you need the haversine formula. To keep this post self-contained, that is:

$$\Theta = 2\sin^{-1}\left(\sqrt{\sin^2\left(\frac{\phi_2 - \phi_1}{2}\right) + \cos(\phi_1)\cos(\phi_2)\sin^2\left(\frac{\lambda_2 - \lambda_1}{2}\right)}\right)$$

Where $\phi$ is declination and $\lambda$ is right ascension.

People are also linking this answer from the comments, which deals with the problem by converting everything to Cartesian coordinates first, which may or may not be easier for your use case.

  • $\begingroup$ what is this d_a and d_b? $\endgroup$
    – astronerd
    Apr 19, 2021 at 10:26
  • $\begingroup$ @astronerd Distance to galaxy A and galaxy B $\endgroup$ Apr 19, 2021 at 10:56
  • $\begingroup$ Thank you. Is it comoving distance or proper distance? $\endgroup$
    – astronerd
    Apr 20, 2021 at 5:17

Not the answer you're looking for? Browse other questions tagged .