home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / astrnomy / ephem421.zip / PARALLAX.C < prev    next >
C/C++ Source or Header  |  1990-09-13  |  2KB  |  78 lines

  1. #include <stdio.h>
  2. #include <math.h>
  3. #include "astro.h"
  4.  
  5. /* given true ha and dec, tha and tdec, the geographical latitude, phi, the
  6.  * height above sea-level (as a fraction of the earths radius, 6378.16km),
  7.  * ht, and the equatorial horizontal parallax, ehp, find the apparent
  8.  * ha and dec, aha and adec allowing for parallax.
  9.  * all angles in radians. ehp is the angle subtended at the body by the
  10.  * earth's equator.
  11.  */
  12. ta_par (tha, tdec, phi, ht, ehp, aha, adec)
  13. double tha, tdec, phi, ht, ehp;
  14. double *aha, *adec;
  15. {
  16.     static double last_phi, last_ht, rsp, rcp;
  17.     double rp;    /* distance to object in Earth radii */
  18.     double ctha;
  19.     double stdec, ctdec;
  20.     double tdtha, dtha;
  21.     double caha;
  22.  
  23.     /* avoid calcs involving the same phi and ht */
  24.     if (phi != last_phi || ht != last_ht) {
  25.         double cphi, sphi, u;
  26.         cphi = cos(phi);
  27.         sphi = sin(phi);
  28.         u = atan(9.96647e-1*sphi/cphi);
  29.         rsp = (9.96647e-1*sin(u))+(ht*sphi);
  30.         rcp = cos(u)+(ht*cphi);
  31.         last_phi  =  phi;
  32.         last_ht  =  ht;
  33.     }
  34.  
  35.         rp = 1/sin(ehp);
  36.  
  37.         ctha = cos(tha);
  38.     stdec = sin(tdec);
  39.     ctdec = cos(tdec);
  40.         tdtha = (rcp*sin(tha))/((rp*ctdec)-(rcp*ctha));
  41.         dtha = atan(tdtha);
  42.     *aha = tha+dtha;
  43.     caha = cos(*aha);
  44.     range (aha, 2*PI);
  45.         *adec = atan(caha*(rp*stdec-rsp)/(rp*ctdec*ctha-rcp));
  46. }
  47.  
  48. /* given the apparent ha and dec, aha and adec, the geographical latitude, phi,
  49.  * the height above sea-level (as a fraction of the earths radius, 6378.16km),
  50.  * ht, and the equatorial horizontal parallax, ehp, find the true ha and dec,
  51.  * tha and tdec allowing for parallax.
  52.  * all angles in radians. ehp is the angle subtended at the body by the
  53.  * earth's equator.
  54.  * uses ta_par() iteratively: find a set of true ha/dec that converts back
  55.   *  to the given apparent ha/dec.
  56.  */
  57. at_par (aha, adec, phi, ht, ehp, tha, tdec)
  58. double aha, adec, phi, ht, ehp;
  59. double *tha, *tdec;
  60. {
  61.     double nha, ndec;    /* ha/dec corres. to current true guesses */
  62.     double eha, edec;    /* error in ha/dec */
  63.  
  64.     /* first guess for true is just the apparent */
  65.     *tha = aha;
  66.     *tdec = adec;
  67.  
  68.     while (1) {
  69.         ta_par (*tha, *tdec, phi, ht, ehp, &nha, &ndec);
  70.         eha = aha - nha;
  71.         edec = adec - ndec;
  72.         if (fabs(eha)<1e-6 && fabs(edec)<1e-6)
  73.         break;
  74.         *tha += eha;
  75.         *tdec += edec;
  76.     }
  77. }
  78.