<p>If the coordinates are precessed to epoch B1875.0, the constellation boundaries lie neatly along the equatorial coordinate grid, allowing simpler tests against boundary segments.</p>
<p><a href="https://ui.adsabs.harvard.edu/abs/1987PASP...99..695R/abstract" rel="nofollow noreferrer">Roman 1987</a> describes a basic algorithm and provides <a href="https://cdsarc.unistra.fr/ftp/VI/42" rel="nofollow noreferrer">implementations</a> in C and F77.</p>
<p><a href="https://ui.adsabs.harvard.edu/abs/2010arXiv1008.3966G/abstract" rel="nofollow noreferrer">Glaschke 2010</a> makes a binary partition of the sky for fast lookup and provides an <a href="https://arxiv.org/src/1008.3966v1/anc" rel="nofollow noreferrer">implementation</a> in C.</p>
<p><a href="https://rhodesmill.org/skyfield/api.html" rel="nofollow noreferrer">Skyfield</a> implements another fast lookup in Python, using lists sorted by right ascension and by declination.
It builds its data structure in <a href="https://github.com/skyfielders/python-skyfield/blob/master/builders/build_constellations.py" rel="nofollow noreferrer">build_constellations.py</a> and uses it in <a href="https://github.com/skyfielders/python-skyfield/blob/master/skyfield/constellationlib.py" rel="nofollow noreferrer">constellationlib.py</a>.</p>

CC BY-SA 4.0
2021-01-28T01:19:24.827Z
Very helpful, thanks! I chose Roman's C implementation [link](https://cdsarc.unistra.fr/ftp/VI/42/), did extensive testing and it worked perfectly!
Ricardo
CC BY-SA 4.0
2022-04-08T21:51:25.210Z
Thanks! See also my study: [Explore astropy get_constellation bugs and Table ASCII CDS format](https://nbviewer.org/gist/nealmcb/a05bb9d3f919faf62db8365f82084889). I did it since the Roman data has the boundaries off slightly (rounded or truncated at 4 decimal places in hours or degrees). Also note that astropy has an implementation (`get_constellation()`) which is based on the Roman data. It also has another bug currently, as described at [get\_constellation\(\) should use exact HMS, DMS boundaries, not 4\-decimal approximations · Issue \#9855](https://github.com/astropy/astropy/issues/9855)
nealmcb
CC BY-SA 4.0
2022-04-10T23:49:04.680Z
My quick IPython `%%timeit` comparison of the astropy code vs SkyField (leveraging the simple code at [Explore astropy get_constellation bugs and Table ASCII CDS format](https://nbviewer.org/gist/nealmcb/a05bb9d3f919faf62db8365f82084889)) suggests that astropy takes about 5 ms, and Skyfield is over 100x faster at 37 µs. Algorithms matter!
nealmcb
CC BY-SA 4.0
2022-04-16T22:07:49.970Z
Note also: a straight conversion of the roman file format to sexagesimal is in Stellarium, at https://github.com/Stellarium/stellarium/blob/master/data/constellations_spans.dat, as changed in commit: https://github.com/Stellarium/stellarium/commit/b3c5ce23cbb36012f207c287c3c5e3b7d73c8a46
nealmcb
CC BY-SA 4.0
2021-01-26T17:15:52.023Z
2021-01-26T17:15:52.023Z
Mike G
<p>I realized it's the problem of checking whether a point is inside a spherical polygon or not. See e.g. <a href="https://github.com/LeoAlexandrov/Spherical" rel="nofollow noreferrer">https://github.com/LeoAlexandrov/Spherical</a>.</p>
<p>But I recommend Roman's implementation, much shorter and simpler (see the accepted answer).</p>

CC BY-SA 4.0
2021-01-26T14:42:44.383Z
2021-01-28T01:29:42.930Z
2021-01-28T01:29:42.930Z
Ricardo
<p>Given its right ascension and declination, find out the constellation a celestial body is in.</p>
<p>Does anyone know of an algorithm (C#, js) for that?</p>
<p>It would read the constellation boundaries (e.g. constellations.bounds.json, at <a href="https://github.com/ofrohn/d3-celestial/tree/master/data" rel="noreferrer">https://github.com/ofrohn/d3-celestial/tree/master/data</a>) and figure the constellation out.</p>
<p>Thanks in advance!</p>

CC BY-SA 4.0
2021-01-24T23:40:41.167Z
I think there is a good chance such an algorithm in those (or similar) languages have been posted before, but it may take some hunting to find them.
uhoh
<positional-astronomy><constellations><algorithm>
Constellation a celestial body is in
Ricardo
# Constellation a celestial body is in

(Asked by: username_0 on 2021-01-24)

Given its right ascension and declination, find out the constellation a celestial body is in.

Does anyone know of an algorithm (C#, js) for that?

It would read the constellation boundaries (e.g. constellations.bounds.json, at <https://github.com/ofrohn/d3-celestial/tree/master/data>) and figure the constellation out.

Thanks in advance!

**Tags:** positional-astronomy, constellations, algorithm

> **Comments:**
> **username_1**: I think there is a good chance such an algorithm in those (or similar) languages have been posted before, but it may take some hunting to find them.  

---

## 2 answers

### Answer by username_2 on 2021-01-26. Score: 4 | Accepted answer

If the coordinates are precessed to epoch B1875.0, the constellation boundaries lie neatly along the equatorial coordinate grid, allowing simpler tests against boundary segments.

[Roman 1987](https://ui.adsabs.harvard.edu/abs/1987PASP...99..695R/abstract) describes a basic algorithm and provides [implementations](https://cdsarc.unistra.fr/ftp/VI/42) in C and F77.

[Glaschke 2010](https://ui.adsabs.harvard.edu/abs/2010arXiv1008.3966G/abstract) makes a binary partition of the sky for fast lookup and provides an [implementation](https://arxiv.org/src/1008.3966v1/anc) in C.

[Skyfield](https://rhodesmill.org/skyfield/api.html) implements another fast lookup in Python, using lists sorted by right ascension and by declination.
It builds its data structure in [build\_constellations.py](https://github.com/skyfielders/python-skyfield/blob/master/builders/build_constellations.py) and uses it in [constellationlib.py](https://github.com/skyfielders/python-skyfield/blob/master/skyfield/constellationlib.py).

> **Comments:**
> **username_0**: Very helpful, thanks! I chose Roman's C implementation [link](https://cdsarc.unistra.fr/ftp/VI/42/), did extensive testing and it worked perfectly!  
> **username_3**: Thanks! See also my study: [Explore astropy get_constellation bugs and Table ASCII CDS format](https://nbviewer.org/gist/username_3/a05bb9d3f919faf62db8365f82084889). I did it since the Roman data has the boundaries off slightly (rounded or truncated at 4 decimal places in hours or degrees). Also note that astropy has an implementation (`get_constellation()`) which is based on the Roman data. It also has another bug currently, as described at [get\_constellation\(\) should use exact HMS, DMS boundaries, not 4\-decimal approximations · Issue \#9855](https://github.com/astropy/astropy/issues/9855)  
> **username_3**: My quick IPython `%%timeit` comparison of the astropy code vs SkyField (leveraging the simple code at [Explore astropy get_constellation bugs and Table ASCII CDS format](https://nbviewer.org/gist/username_3/a05bb9d3f919faf62db8365f82084889)) suggests that astropy takes about 5 ms, and Skyfield is over 100x faster at 37 µs. Algorithms matter!  
> **username_3**: Note also: a straight conversion of the roman file format to sexagesimal is in Stellarium, at https://github.com/Stellarium/stellarium/blob/master/data/constellations_spans.dat, as changed in commit: https://github.com/Stellarium/stellarium/commit/b3c5ce23cbb36012f207c287c3c5e3b7d73c8a46  

---

### Answer by username_0 on 2021-01-26. Score: 1

I realized it's the problem of checking whether a point is inside a spherical polygon or not. See e.g. <https://github.com/LeoAlexandrov/Spherical>.

But I recommend Roman's implementation, much shorter and simpler (see the accepted answer).


---

