<p>Since you are presumably using <a href="https://en.wikipedia.org/wiki/Hubble%27s_law" rel="nofollow noreferrer">Hubble's law</a> to get the distance to each of the galaxies, the approximate estimate would the &quot;the greater distance ± the smaller distance&quot;.</p>
<p>But the geometric solution is useful too. Your strategy appears to be something like:</p>
<ol>
<li>Calculate angular separation <span class="math-container">$\Theta$</span> from RA and DEC.</li>
<li>By trigonometry, the distance is then <span class="math-container">$d_{a,b} = \sqrt{d_a^2\sin(\Theta)^2 + (d_b - d_a\cos(\Theta))^2}$</span></li>
</ol>
<p>The problem is that you can not calculate the angular separation on a sphere by the Pythagorean formula, instead, you need the <a href="https://en.wikipedia.org/wiki/Haversine_formula" rel="nofollow noreferrer">haversine formula</a>. To keep this post self-contained, that is:</p>
<p><span class="math-container">$$\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)$$</span></p>
<p>Where <span class="math-container">$\phi$</span> is declination and <span class="math-container">$\lambda$</span> is right ascension.</p>
<p>People are also linking <a href="https://astronomy.stackexchange.com/questions/39595/what-is-the-distance-from-alpha-centauri-to-barnards-star">this answer</a> 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.</p>

CC BY-SA 4.0
2021-04-19T10:26:20.473Z
what is this d_a and d_b?
Edward
CC BY-SA 4.0
2021-04-19T10:56:37.153Z
@astronerd Distance to galaxy A and galaxy B
SE - stop firing the good guys
CC BY-SA 4.0
2021-04-20T05:17:42.177Z
Thank you. Is it comoving distance or proper distance?
Edward
CC BY-SA 4.0
2020-12-15T20:05:28.837Z
2020-12-15T20:05:28.837Z
SE - stop firing the good guys
<p>I have ra and dec and corresponding redshift of galaxies. I would like to calculate the distance between two galaxies.</p>
<p>I did like this to find the nearest neighbour galaxies.</p>
<p>Suppose I am trying to find the nearest neighbour of galaxy A(which has RA,DEC)  and the target galaxy has ra1,dec1,</p>
<p>so to find the distance between two galaxy, I did like this</p>
<pre><code>dist_sqd= sqrt( (RA-ra1)**2 + (DEC-dec1)**2 ) 
#RA, DEC are in degree
</code></pre>
<p>Is this the correct way to find the distance.</p>
<p>As there is projection in 2D, Since, I already have redshift, Is there any best way to find the distance between two galaxies properly?</p>

CC BY-SA 4.0
2020-12-13T17:05:35.870Z
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...
James K
CC BY-SA 4.0
2020-12-13T17:26:12.150Z
You mean the angular separation? What has it got to do with the redshifts?
ProfRob
CC BY-SA 4.0
2020-12-13T17:28:25.860Z
See also https://astronomy.stackexchange.com/questions/26899/comoving-distance-between-two-points-ra1-dec1-z1-and-ra2-dec2-z2
ProfRob
CC BY-SA 4.0
2020-12-13T17:39:35.413Z
Related: [What is the distance from Alpha Centauri to Barnard's Star?](/q/39595)
Mike G
<observational-astronomy><galaxy><astrophysics><distances><redshift>
How to find the distance between two galaxies from ra and dec and redshift
John Singh
# How to find the distance between two galaxies from ra and dec and redshift

(Asked by: username_0 on 2020-12-13)

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?

**Tags:** observational-astronomy, galaxy, astrophysics, distances, redshift
> **Comments:**
> **username_1**: 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...  
> **username_2**: You mean the angular separation? What has it got to do with the redshifts?  
> **username_2**: See also https://astronomy.stackexchange.com/questions/26899/comoving-distance-between-two-points-ra1-dec1-z1-and-ra2-dec2-z2  
> **username_3**: Related: [What is the distance from Alpha Centauri to Barnard's Star?](/q/39595)  

---

## 1 answers

### Answer by username_4 on 2020-12-15. Score: 2

Since you are presumably using [Hubble's law](https://en.wikipedia.org/wiki/Hubble%27s_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](https://en.wikipedia.org/wiki/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](https://astronomy.stackexchange.com/questions/39595/what-is-the-distance-from-alpha-centauri-to-barnards-star) 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.

> **Comments:**
> **username_5**: what is this d_a and d_b?  
> **username_4**: @astronerd Distance to galaxy A and galaxy B  
> **username_5**: Thank you. Is it comoving distance or proper distance?  

---

