moon.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. #include "astro.h"
  2. double k1, k2, k3, k4;
  3. double mnom, msun, noded, dmoon;
  4. void
  5. moon(void)
  6. {
  7. Moontab *mp;
  8. double dlong, lsun, psun;
  9. double eccm, eccs, chp, cpe;
  10. double v0, t0, m0, j0;
  11. double arg1, arg2, arg3, arg4, arg5, arg6, arg7;
  12. double arg8, arg9, arg10;
  13. double dgamma, k5, k6;
  14. double lterms, sterms, cterms, nterms, pterms, spterms;
  15. double gamma1, gamma2, gamma3, arglat;
  16. double xmp, ymp, zmp;
  17. double obl2;
  18. /*
  19. * the fundamental elements - all referred to the epoch of
  20. * Jan 0.5, 1900 and to the mean equinox of date.
  21. */
  22. dlong = 270.434164 + 13.1763965268*eday - .001133*capt2
  23. + 2.e-6*capt3;
  24. argp = 334.329556 + .1114040803*eday - .010325*capt2
  25. - 12.e-6*capt3;
  26. node = 259.183275 - .0529539222*eday + .002078*capt2
  27. + 2.e-6*capt3;
  28. lsun = 279.696678 + .9856473354*eday + .000303*capt2;
  29. psun = 281.220833 + .0000470684*eday + .000453*capt2
  30. + 3.e-6*capt3;
  31. dlong = fmod(dlong, 360.);
  32. argp = fmod(argp, 360.);
  33. node = fmod(node, 360.);
  34. lsun = fmod(lsun, 360.);
  35. psun = fmod(psun, 360.);
  36. eccm = 22639.550;
  37. eccs = .01675104 - .00004180*capt;
  38. incl = 18461.400;
  39. cpe = 124.986;
  40. chp = 3422.451;
  41. /*
  42. * some subsidiary elements - they are all longitudes
  43. * and they are referred to the epoch 1/0.5 1900 and
  44. * to the fixed mean equinox of 1850.0.
  45. */
  46. v0 = 342.069128 + 1.6021304820*eday;
  47. t0 = 98.998753 + 0.9856091138*eday;
  48. m0 = 293.049675 + 0.5240329445*eday;
  49. j0 = 237.352319 + 0.0830912295*eday;
  50. /*
  51. * the following are periodic corrections to the
  52. * fundamental elements and constants.
  53. * arg3 is the "Great Venus Inequality".
  54. */
  55. arg1 = 41.1 + 20.2*(capt+.5);
  56. arg2 = dlong - argp + 33. + 3.*t0 - 10.*v0 - 2.6*(capt+.5);
  57. arg3 = dlong - argp + 151.1 + 16.*t0 - 18.*v0 - (capt+.5);
  58. arg4 = node;
  59. arg5 = node + 276.2 - 2.3*(capt+.5);
  60. arg6 = 313.9 + 13.*t0 - 8.*v0;
  61. arg7 = dlong - argp + 112.0 + 29.*t0 - 26.*v0;
  62. arg8 = dlong + argp - 2.*lsun + 273. + 21.*t0 - 20.*v0;
  63. arg9 = node + 290.1 - 0.9*(capt+.5);
  64. arg10 = 115. + 38.5*(capt+.5);
  65. arg1 *= radian;
  66. arg2 *= radian;
  67. arg3 *= radian;
  68. arg4 *= radian;
  69. arg5 *= radian;
  70. arg6 *= radian;
  71. arg7 *= radian;
  72. arg8 *= radian;
  73. arg9 *= radian;
  74. arg10 *= radian;
  75. dlong +=
  76. (0.84 *sin(arg1)
  77. + 0.31 *sin(arg2)
  78. + 14.27 *sin(arg3)
  79. + 7.261*sin(arg4)
  80. + 0.282*sin(arg5)
  81. + 0.237*sin(arg6)
  82. + 0.108*sin(arg7)
  83. + 0.126*sin(arg8))/3600.;
  84. argp +=
  85. (- 2.10 *sin(arg1)
  86. - 0.118*sin(arg3)
  87. - 2.076*sin(arg4)
  88. - 0.840*sin(arg5)
  89. - 0.593*sin(arg6))/3600.;
  90. node +=
  91. (0.63*sin(arg1)
  92. + 0.17*sin(arg3)
  93. + 95.96*sin(arg4)
  94. + 15.58*sin(arg5)
  95. + 1.86*sin(arg9))/3600.;
  96. t0 +=
  97. (- 6.40*sin(arg1)
  98. - 1.89*sin(arg6))/3600.;
  99. psun +=
  100. (6.40*sin(arg1)
  101. + 1.89*sin(arg6))/3600.;
  102. dgamma = - 4.318*cos(arg4)
  103. - 0.698*cos(arg5)
  104. - 0.083*cos(arg9);
  105. j0 +=
  106. 0.33*sin(arg10);
  107. /*
  108. * the following factors account for the fact that the
  109. * eccentricity, solar eccentricity, inclination and
  110. * parallax used by Brown to make up his coefficients
  111. * are both wrong and out of date. Brown did the same
  112. * thing in a different way.
  113. */
  114. k1 = eccm/22639.500;
  115. k2 = eccs/.01675104;
  116. k3 = 1. + 2.708e-6 + .000108008*dgamma;
  117. k4 = cpe/125.154;
  118. k5 = chp/3422.700;
  119. /*
  120. * the principal arguments that are used to compute
  121. * perturbations are the following differences of the
  122. * fundamental elements.
  123. */
  124. mnom = dlong - argp;
  125. msun = lsun - psun;
  126. noded = dlong - node;
  127. dmoon = dlong - lsun;
  128. /*
  129. * solar terms in longitude
  130. */
  131. lterms = 0.0;
  132. mp = moontab;
  133. for(;;) {
  134. if(mp->f == 0.0)
  135. break;
  136. lterms += sinx(mp->f,
  137. mp->c[0], mp->c[1],
  138. mp->c[2], mp->c[3], 0.0);
  139. mp++;
  140. }
  141. mp++;
  142. /*
  143. * planetary terms in longitude
  144. */
  145. lterms += sinx(0.822, 0,0,0,0, t0-v0);
  146. lterms += sinx(0.307, 0,0,0,0, 2.*t0-2.*v0+179.8);
  147. lterms += sinx(0.348, 0,0,0,0, 3.*t0-2.*v0+272.9);
  148. lterms += sinx(0.176, 0,0,0,0, 4.*t0-3.*v0+271.7);
  149. lterms += sinx(0.092, 0,0,0,0, 5.*t0-3.*v0+199.);
  150. lterms += sinx(0.129, 1,0,0,0, -t0+v0+180.);
  151. lterms += sinx(0.152, 1,0,0,0, t0-v0);
  152. lterms += sinx(0.127, 1,0,0,0, 3.*t0-3.*v0+180.);
  153. lterms += sinx(0.099, 0,0,0,2, t0-v0);
  154. lterms += sinx(0.136, 0,0,0,2, 2.*t0-2.*v0+179.5);
  155. lterms += sinx(0.083, -1,0,0,2, -4.*t0+4.*v0+180.);
  156. lterms += sinx(0.662, -1,0,0,2, -3.*t0+3.*v0+180.0);
  157. lterms += sinx(0.137, -1,0,0,2, -2.*t0+2.*v0);
  158. lterms += sinx(0.133, -1,0,0,2, t0-v0);
  159. lterms += sinx(0.157, -1,0,0,2, 2.*t0-2.*v0+179.6);
  160. lterms += sinx(0.079, -1,0,0,2, -8.*t0+6.*v0+162.6);
  161. lterms += sinx(0.073, 2,0,0,-2, 3.*t0-3.*v0+180.);
  162. lterms += sinx(0.643, 0,0,0,0, -t0+j0+178.8);
  163. lterms += sinx(0.187, 0,0,0,0, -2.*t0+2.*j0+359.6);
  164. lterms += sinx(0.087, 0,0,0,0, j0+289.9);
  165. lterms += sinx(0.165, 0,0,0,0, -t0+2.*j0+241.5);
  166. lterms += sinx(0.144, 1,0,0,0, t0-j0+1.0);
  167. lterms += sinx(0.158, 1,0,0,0, -t0+j0+179.0);
  168. lterms += sinx(0.190, 1,0,0,0, -2.*t0+2.*j0+180.0);
  169. lterms += sinx(0.096, 1,0,0,0, -2.*t0+3.*j0+352.5);
  170. lterms += sinx(0.070, 0,0,0,2, 2.*t0-2.*j0+180.);
  171. lterms += sinx(0.167, 0,0,0,2, -t0+j0+178.5);
  172. lterms += sinx(0.085, 0,0,0,2, -2.*t0+2.*j0+359.2);
  173. lterms += sinx(1.137, -1,0,0,2, 2.*t0-2.*j0+180.3);
  174. lterms += sinx(0.211, -1,0,0,2, -t0+j0+178.4);
  175. lterms += sinx(0.089, -1,0,0,2, -2.*t0+2.*j0+359.2);
  176. lterms += sinx(0.436, -1,0,0,2, 2.*t0-3.*j0+7.5);
  177. lterms += sinx(0.240, 2,0,0,-2, -2.*t0+2.*j0+179.9);
  178. lterms += sinx(0.284, 2,0,0,-2, -2.*t0+3.*j0+172.5);
  179. lterms += sinx(0.195, 0,0,0,0, -2.*t0+2.*m0+180.2);
  180. lterms += sinx(0.327, 0,0,0,0, -t0+2.*m0+224.4);
  181. lterms += sinx(0.093, 0,0,0,0, -2.*t0+4.*m0+244.8);
  182. lterms += sinx(0.073, 1,0,0,0, -t0+2.*m0+223.3);
  183. lterms += sinx(0.074, 1,0,0,0, t0-2.*m0+306.3);
  184. lterms += sinx(0.189, 0,0,0,0, node+180.);
  185. /*
  186. * solar terms in latitude
  187. */
  188. sterms = 0;
  189. for(;;) {
  190. if(mp->f == 0)
  191. break;
  192. sterms += sinx(mp->f,
  193. mp->c[0], mp->c[1],
  194. mp->c[2], mp->c[3], 0);
  195. mp++;
  196. }
  197. mp++;
  198. cterms = 0;
  199. for(;;) {
  200. if(mp->f == 0)
  201. break;
  202. cterms += cosx(mp->f,
  203. mp->c[0], mp->c[1],
  204. mp->c[2], mp->c[3], 0);
  205. mp++;
  206. }
  207. mp++;
  208. nterms = 0;
  209. for(;;) {
  210. if(mp->f == 0)
  211. break;
  212. nterms += sinx(mp->f,
  213. mp->c[0], mp->c[1],
  214. mp->c[2], mp->c[3], 0);
  215. mp++;
  216. }
  217. mp++;
  218. /*
  219. * planetary terms in latitude
  220. */
  221. pterms =
  222. sinx(0.215, 0,0,0,0, dlong);
  223. /*
  224. * solar terms in parallax
  225. */
  226. spterms = 3422.700;
  227. for(;;) {
  228. if(mp->f == 0)
  229. break;
  230. spterms += cosx(mp->f,
  231. mp->c[0], mp->c[1],
  232. mp->c[2], mp->c[3], 0);
  233. mp++;
  234. }
  235. /*
  236. * planetary terms in parallax
  237. */
  238. spterms = spterms;
  239. /*
  240. * computation of longitude
  241. */
  242. lambda = (dlong + lterms/3600.)*radian;
  243. /*
  244. * computation of latitude
  245. */
  246. arglat = (noded + sterms/3600.)*radian;
  247. gamma1 = 18519.700 * k3;
  248. gamma2 = -6.241 * k3*k3*k3;
  249. gamma3 = 0.004 * k3*k3*k3*k3*k3;
  250. k6 = (gamma1 + cterms) / gamma1;
  251. beta = k6 * (gamma1*sin(arglat) + gamma2*sin(3.*arglat)
  252. + gamma3*sin(5.*arglat) + nterms)
  253. + pterms;
  254. if(flags['o'])
  255. beta -= 0.6;
  256. beta *= radsec;
  257. /*
  258. * computation of parallax
  259. */
  260. spterms = k5 * spterms *radsec;
  261. hp = spterms + (spterms*spterms*spterms)/6.;
  262. rad = hp/radsec;
  263. rp = 1.;
  264. semi = .0799 + .272453*(hp/radsec);
  265. if(dmoon < 0.)
  266. dmoon += 360.;
  267. mag = dmoon/360.;
  268. /*
  269. * change to equatorial coordinates
  270. */
  271. lambda += phi;
  272. obl2 = obliq + eps;
  273. xmp = rp*cos(lambda)*cos(beta);
  274. ymp = rp*(sin(lambda)*cos(beta)*cos(obl2) - sin(obl2)*sin(beta));
  275. zmp = rp*(sin(lambda)*cos(beta)*sin(obl2) + cos(obl2)*sin(beta));
  276. alpha = atan2(ymp, xmp);
  277. delta = atan2(zmp, sqrt(xmp*xmp+ymp*ymp));
  278. meday = eday;
  279. mhp = hp;
  280. geo();
  281. }
  282. double
  283. sinx(double coef, int i, int j, int k, int m, double angle)
  284. {
  285. double x;
  286. x = i*mnom + j*msun + k*noded + m*dmoon + angle;
  287. x = coef*sin(x*radian);
  288. if(i < 0)
  289. i = -i;
  290. for(; i>0; i--)
  291. x *= k1;
  292. if(j < 0)
  293. j = -j;
  294. for(; j>0; j--)
  295. x *= k2;
  296. if(k < 0)
  297. k = -k;
  298. for(; k>0; k--)
  299. x *= k3;
  300. if(m & 1)
  301. x *= k4;
  302. return x;
  303. }
  304. double
  305. cosx(double coef, int i, int j, int k, int m, double angle)
  306. {
  307. double x;
  308. x = i*mnom + j*msun + k*noded + m*dmoon + angle;
  309. x = coef*cos(x*radian);
  310. if(i < 0)
  311. i = -i;
  312. for(; i>0; i--)
  313. x *= k1;
  314. if(j < 0)
  315. j = -j;
  316. for(; j>0; j--)
  317. x *= k2;
  318. if(k < 0)
  319. k = -k;
  320. for(; k>0; k--)
  321. x *= k3;
  322. if(m & 1)
  323. x *= k4;
  324. return x;
  325. }