1 /*
2  IAU Constellation boundaries, in J2000, from
3  http://vizier.cfa.harvard.edu/viz-bin/VizieR-3?-source=VI/49/bound_20
4  */
5 /*
6  #
7  #   VizieR Astronomical Server vizier.cfa.harvard.edu
8  #    Date: 2014-07-16T14:54:10 [V1.99+ (14-Oct-2013)]
9  #
10  #Coosys	J2000:	eq_FK5 J2000
11  #INFO	votable-version=1.99+ (14-Oct-2013)
12  #INFO	-ref=VIZ53c69102128c
13  #INFO	-out.max=unlimited
14  #INFO	queryParameters=12
15  #-oc.form=dec
16  #-out.max=unlimited
17  #-nav=cat:VI/49&tab:{VI/49/bound_20}&key:source=VI/49/bound_20&HTTPPRM:&
18  #-c.eq=J2000
19  #-c.r=  2
20  #-c.u=arcmin
21  #-c.geom=r
22  #-source=VI/49/bound_20
23  #-order=I
24  #-out=RAJ2000
25  #-out=DEJ2000
26  #-out=cst
27  #
28 
29  #RESOURCE=yCat_6049
30  #Name: VI/49
31  #Title: Constellation Boundary Data (Davenhall+ 1989)
32  #Table	VI_49_bound_20:
33  #Name: VI/49/bound_20
34  #Title: Boundaries for J2000
35  #Column	RAJ2000	(F10.6)	Right ascension in decimal hours (J2000)	[ucd=pos.eq.ra;meta.main]
36  #Column	DEJ2000	(F11.7)	Declination in degrees (J2000)	[ucd=pos.eq.dec;meta.main]
37  #Column	cst	(A4)	Constellation abbreviation	[ucd=meta.id.part]
38  RAJ2000	DEJ2000	cst
39  deg	deg
40  ----------	-----------	----
41  */
42 
43 #include "constellation-boundaries.h"
44 #include "an-bool.h"
45 #include "bl.h"
46 #include "starutil.h"
47 #include "mathutil.h"
48 
49 typedef struct {
50     double ra;
51     double dec;
52     int con;
53 } boundarypoint_t;
54 
55 static boundarypoint_t boundaries[] = {
56 #include "constellation-boundaries-data.c"
57 };
58 
59 /**
60  Returns the "enum constellations" number of the constellation
61  containing the given RA,Dec point, or -1 if none such is found.
62  */
constellation_containing(double ra,double dec)63 int constellation_containing(double ra, double dec) {
64     int i;
65     int N = sizeof(boundaries) / sizeof(boundarypoint_t);
66     dl* poly = dl_new(256);
67     double xyz[3];
68     radecdeg2xyzarr(ra, dec, xyz);
69 
70     //printf("%i boundary points, %i constellations (%i to %i)\n", N,
71     //CON_FINAL, CON_AND, CON_VUL);
72     for (i=0; i<CON_FINAL; i++) {
73         int j;
74         anbool con_ok;
75         con_ok = TRUE;
76         dl_remove_all(poly);
77         // Find start and end of this constellation, and project
78         // boundary points about the target RA,Dec.
79         for (j=0; j<N; j++) {
80             double xyzc[3];
81             double px, py;
82             if (boundaries[j].con != i)
83                 continue;
84             radecdeg2xyzarr(boundaries[j].ra, boundaries[j].dec, xyzc);
85             if (!star_coords(xyzc, xyz, TRUE, &px, &py)) {
86                 // the constellation is too far away (on other side of
87                 // the sky)
88                 con_ok = FALSE;
89                 break;
90             }
91             dl_append(poly, px);
92             dl_append(poly, py);
93         }
94         if (!con_ok)
95             continue;
96         // Now we have projected all the boundary points of this
97         // constellation about the query point, which is (0,0) by
98         // definition.  Does the boundary polygon contain (0,0)?
99         if (point_in_polygon(0., 0., poly))
100             return i;
101     }
102 
103     return -1;
104 }
105 
106 
107