1 /* 2 # This file is part of the Astrometry.net suite. 3 # Licensed under a 3-clause BSD style license - see LICENSE 4 */ 5 6 #ifndef STARUTIL_H 7 #define STARUTIL_H 8 9 #include <math.h> 10 #include "astrometry/an-bool.h" 11 #include "astrometry/keywords.h" 12 13 #define DIM_STARS 3 14 #define DIM_XY 2 15 16 // upper bound of dimquads value 17 #define DQMAX 5 18 // upper bound of dimcodes value 19 #define DCMAX 6 20 21 InlineDeclare int dimquad2dimcode(int dimquad); 22 23 typedef unsigned char uchar; 24 25 #define ONE_OVER_SIXTY 0.016666666666666666 26 27 // pi / 180. 28 #define RAD_PER_DEG 0.017453292519943295 29 // pi / (180. * 60.) 30 #define RAD_PER_ARCMIN 0.00029088820866572158 31 // pi / (180. * 60. * 60.) 32 #define RAD_PER_ARCSEC 4.8481368110953598e-06 33 34 // 180. / pi 35 #define DEG_PER_RAD 57.295779513082323 36 #define DEG_PER_ARCMIN ONE_OVER_SIXTY 37 // 1./3600. 38 #define DEG_PER_ARCSEC 0.00027777777777777778 39 40 // 60. * 180. / pi 41 #define ARCMIN_PER_RAD 3437.7467707849396 42 #define ARCMIN_PER_DEG 60.0 43 #define ARCMIN_PER_ARCSEC ONE_OVER_SIXTY 44 45 // 60. * 60. * 180. / pi 46 #define ARCSEC_PER_RAD 206264.80624709636 47 #define ARCSEC_PER_DEG 3600.0 48 #define ARCSEC_PER_ARCMIN 60.0 49 50 InlineDeclare Const double rad2deg(double x); 51 InlineDeclare Const double rad2arcmin(double x); 52 InlineDeclare Const double rad2arcsec(double x); 53 54 InlineDeclare Const double deg2rad(double x); 55 InlineDeclare Const double deg2arcmin(double x); 56 InlineDeclare Const double deg2arcsec(double x); 57 58 InlineDeclare Const double arcmin2rad(double x); 59 InlineDeclare Const double arcmin2deg(double x); 60 InlineDeclare Const double arcmin2arcsec(double x); 61 62 InlineDeclare Const double arcsec2rad(double x); 63 InlineDeclare Const double arcsec2deg(double x); 64 InlineDeclare Const double arcsec2arcmin(double x); 65 66 #define MJD_JD_OFFSET 2400000.5 67 68 InlineDeclare Const double mjdtojd(double mjd); 69 InlineDeclare Const double jdtomjd(double jd); 70 71 // RA,Dec in radians: 72 #define radec2x(r,d) (cos(d)*cos(r)) 73 #define radec2y(r,d) (cos(d)*sin(r)) 74 #define radec2z(r,d) (sin(d)) 75 InlineDeclare Const double xy2ra(double x, double y); 76 InlineDeclare Const double z2dec(double z); 77 78 double atora(const char* str); 79 double atodec(const char* str); 80 81 double mag2flux(double mag); 82 83 /* 84 RA,Dec in degrees. RAs in range [0, 360], Decs in range [-90, 90]. 85 */ 86 void radecrange2xyzrange(double ralow, double declow, double rahigh, double dechigh, 87 double* xyzlow, double* xyzhigh); 88 89 // RA,Dec in radians: 90 InlineDeclare void radec2xyz(double ra, double dec, double* x, double* y, double* z); 91 InlineDeclare Flatten void xyz2radec(double x, double y, double z, double *ra, double *dec); 92 InlineDeclare Flatten void xyzarr2radec(const double* xyz, double *ra, double *dec); 93 InlineDeclare void xyzarr2radecarr(const double* xyz, double *radec); 94 InlineDeclare void radec2xyzarr(double ra, double dec, double* p_xyz); 95 InlineDeclare void radec2xyzarrmany(double *ra, double *dec, double* xyz, int n); 96 97 // RA,Dec in degrees: 98 InlineDeclare void radecdeg2xyz(double ra, double dec, double* x, double* y, double* z); 99 InlineDeclare Flatten void xyzarr2radecdeg(const double* xyz, double *ra, double *dec); 100 InlineDeclare Flatten void xyzarr2radecdegarr(double* xyz, double *radec); 101 InlineDeclare void radecdeg2xyzarr(double ra, double dec, double* p_xyz); 102 InlineDeclare void radecdegarr2xyzarr(double* radec, double* xyz); 103 InlineDeclare void radecdeg2xyzarrmany(double *ra, double *dec, double* xyz, int n); 104 105 // RA,Dec in degrees. 106 // Puts the xyz unit vector pointing in positive-RA direction in "dra", 107 // Puts the xyz unit vector pointing in the positive-Dec direction in "ddec". 108 void radec_derivatives(double ra, double dec, double* dra, double* ddec); 109 110 // Returns the distance-squared between two (RA,Dec)s in degrees. 111 double distsq_between_radecdeg(double ra1, double dec1, double ra2, double dec2); 112 113 // Returns the arcseconds between two (RA,Dec)s in degrees. 114 double arcsec_between_radecdeg(double ra1, double dec1, double ra2, double dec2); 115 116 // Returns the degrees between two (RA,Dec)s in degrees. 117 double deg_between_radecdeg(double ra1, double dec1, double ra2, double dec2); 118 119 // RA in degrees to Mercator X coordinate [0, 1). 120 double ra2mercx(double ra); 121 // Dec in degrees to Mercator Y coordinate [0, 1). 122 double dec2mercy(double dec); 123 124 // RA in degrees to H:M:S 125 void ra2hms(double ra, int* h, int* m, double* s); 126 // Dec in degrees to D:M:S 127 void dec2dms(double dec, int* sign, int* d, int* m, double* s); 128 129 double hms2ra(int h, int m, double s); 130 double dms2dec(int sgn, int d, int m, double s); 131 132 void ra2hmsstring(double ra, char* str); 133 void dec2dmsstring(double dec, char* str); 134 135 void project_hammer_aitoff_x(double x, double y, double z, double* projx, double* projy); 136 137 void project_equal_area(double x, double y, double z, double* projx, double* projy); 138 139 // Converts a distance-squared between two points on the 140 // surface of the unit sphere into the angle between the 141 // rays from the center of the sphere to the points, in 142 // radians. 143 InlineDeclare Flatten Const double distsq2arc(double dist2); 144 145 // Distance^2 on the unit sphere to radians. 146 // (alias of distsq2arc) 147 InlineDeclare Flatten Const double distsq2rad(double dist2); 148 149 InlineDeclare Flatten Const double distsq2deg(double dist2); 150 151 // Distance on the unit sphere to radians. 152 InlineDeclare Flatten Const double dist2rad(double dist); 153 154 // Distance^2 on the unit sphere to arcseconds. 155 InlineDeclare Flatten Const double distsq2arcsec(double dist2); 156 157 // Distance on the unit sphere to arcseconds 158 InlineDeclare Flatten Const double dist2arcsec(double dist); 159 160 // Radians to distance^2 on the unit sphere. 161 // (alias of arc2distsq) 162 InlineDeclare Const double rad2distsq(double arcInRadians); 163 164 // Radians to distance on the unit sphere. 165 InlineDeclare Flatten Const double rad2dist(double arcInRadians); 166 167 // Converts an angle (in arcseconds) into the distance-squared 168 // between two points on the unit sphere separated by that angle. 169 InlineDeclare Flatten Const double arcsec2distsq(double arcInArcSec); 170 171 // Arcseconds to distance on the unit sphere. 172 InlineDeclare Flatten Const double arcsec2dist(double arcInArcSec); 173 174 // Degrees to distance on the unit sphere. 175 InlineDeclare Flatten Const double deg2dist(double arcInDegrees); 176 177 InlineDeclare Flatten Const double deg2distsq(double d); 178 179 InlineDeclare Flatten Const double arcmin2dist(double arcmin); 180 181 InlineDeclare Flatten Const double arcmin2distsq(double arcmin); 182 183 // Distance on the unit sphere to degrees. 184 InlineDeclare Flatten Const double dist2deg(double dist); 185 186 #define HELP_ERR -101 187 #define OPT_ERR -201 188 189 void make_rand_star(double* star, double ramin, double ramax, 190 double decmin, double decmax); 191 192 /* 193 Computes the 2D coordinates (x,y) (in units of a celestial sphere of 194 radius 1) that star s would have in a TANGENTIAL PROJECTION defined 195 by (centred at) star r. s and r are both given in xyz coordinates, 196 the parameters are pointers to arrays of size 3. 197 198 If "tangent" is true, the projection is the WCS TAN projection; if 199 not, it is the WCS SIN projection. 200 201 The resulting x,y coordinates are intermediate world coordinates in 202 degrees. The "x" direction should be positive for increasing RA, "y" 203 is increasing Dec. 204 205 WARNING -- this code assumes s and r are UNIT vectors (ie normalized 206 to have length 1). 207 */ 208 WarnUnusedResult InlineDeclare 209 anbool star_coords(const double *s, const double *r, 210 anbool tangent, double *x, double *y); 211 212 InlineDeclare void star_midpoint(double* mid, const double* A, const double* B); 213 214 #ifdef INCLUDE_INLINE_SOURCE 215 #define InlineDefine InlineDefineH 216 #include "astrometry/starutil.inc" 217 #undef InlineDefine 218 #endif 219 220 #endif 221