# How to find the distance between two galaxies from ra and dec and redshift [duplicate]

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?

• That won't work, consider two galaxies near the north celestial pole, one with an ra of 0 and one with an ra of 180... Dec 13, 2020 at 17:05
• You mean the angular separation? What has it got to do with the redshifts? Dec 13, 2020 at 17:26
• Dec 13, 2020 at 17:28
• Dec 13, 2020 at 17:39

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.

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