| 1 | /* function to convert between alt/az and ha/dec. | 
|---|
| 2 | */ | 
|---|
| 3 |  | 
|---|
| 4 | #include <stdio.h> | 
|---|
| 5 | #include <math.h> | 
|---|
| 6 |  | 
|---|
| 7 | #include "astro.h" | 
|---|
| 8 |  | 
|---|
| 9 | static void aaha_aux (double lt, double x, double y, double *p, double *q); | 
|---|
| 10 |  | 
|---|
| 11 | /* given geographical latitude (n+, radians), lt, altitude (up+, radians), | 
|---|
| 12 | * alt, and azimuth (angle round to the east from north+, radians), | 
|---|
| 13 | * return hour angle (radians), ha, and declination (radians), dec. | 
|---|
| 14 | */ | 
|---|
| 15 | void | 
|---|
| 16 | aa_hadec ( | 
|---|
| 17 | double lt, | 
|---|
| 18 | double alt, double az, | 
|---|
| 19 | double *ha, double *dec) | 
|---|
| 20 | { | 
|---|
| 21 | aaha_aux (lt, az, alt, ha, dec); | 
|---|
| 22 | if (*ha > PI) | 
|---|
| 23 | *ha -= 2*PI; | 
|---|
| 24 | } | 
|---|
| 25 |  | 
|---|
| 26 | /* given geographical (n+, radians), lt, hour angle (radians), ha, and | 
|---|
| 27 | * declination (radians), dec, return altitude (up+, radians), alt, and | 
|---|
| 28 | * azimuth (angle round to the east from north+, radians), | 
|---|
| 29 | */ | 
|---|
| 30 | void | 
|---|
| 31 | hadec_aa ( | 
|---|
| 32 | double lt, | 
|---|
| 33 | double ha, double dec, | 
|---|
| 34 | double *alt, double *az) | 
|---|
| 35 | { | 
|---|
| 36 | aaha_aux (lt, ha, dec, az, alt); | 
|---|
| 37 | } | 
|---|
| 38 |  | 
|---|
| 39 | #ifdef NEED_GEOC | 
|---|
| 40 | /* given a geographic (surface-normal) latitude, phi, return the geocentric | 
|---|
| 41 | * latitude, psi. | 
|---|
| 42 | */ | 
|---|
| 43 | double | 
|---|
| 44 | geoc_lat ( | 
|---|
| 45 | double phi) | 
|---|
| 46 | { | 
|---|
| 47 | #define MAXLAT  degrad(89.9999) /* avoid tan() greater than this */ | 
|---|
| 48 | return (fabs(phi)>MAXLAT ? phi : atan(tan(phi)/1.00674)); | 
|---|
| 49 | } | 
|---|
| 50 | #endif | 
|---|
| 51 |  | 
|---|
| 52 | /* the actual formula is the same for both transformation directions so | 
|---|
| 53 | * do it here once for each way. | 
|---|
| 54 | * N.B. all arguments are in radians. | 
|---|
| 55 | */ | 
|---|
| 56 | static void | 
|---|
| 57 | aaha_aux ( | 
|---|
| 58 | double lt, | 
|---|
| 59 | double x, double y, | 
|---|
| 60 | double *p, double *q) | 
|---|
| 61 | { | 
|---|
| 62 | static double last_lt = -3434, slt, clt; | 
|---|
| 63 | double cap, B; | 
|---|
| 64 |  | 
|---|
| 65 | if (lt != last_lt) { | 
|---|
| 66 | slt = sin(lt); | 
|---|
| 67 | clt = cos(lt); | 
|---|
| 68 | last_lt = lt; | 
|---|
| 69 | } | 
|---|
| 70 |  | 
|---|
| 71 | solve_sphere (-x, PI/2-y, slt, clt, &cap, &B); | 
|---|
| 72 | *p = B; | 
|---|
| 73 | *q = PI/2 - acos(cap); | 
|---|
| 74 | } | 
|---|
| 75 |  | 
|---|
| 76 | /* For RCS Only -- Do Not Edit */ | 
|---|
| 77 | static char *rcsid[2] = {(char *)rcsid, "@(#) $RCSfile: aa_hadec.c,v $ $Date: 2005-08-21 10:02:36 $ $Revision: 1.5 $ $Name: not supported by cvs2svn $"}; | 
|---|