occ.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #include "astro.h"
  2. Occ o1, o2;
  3. Obj2 xo1, xo2;
  4. void
  5. occult(Obj2 *p1, Obj2 *p2, double)
  6. {
  7. int i, i1, N;
  8. double d1, d2, d3, d4;
  9. double x, di, dx, x1;
  10. d3 = 0;
  11. d2 = 0;
  12. occ.t1 = -100;
  13. occ.t2 = -100;
  14. occ.t3 = -100;
  15. occ.t4 = -100;
  16. occ.t5 = -100;
  17. for(i=0; i<=NPTS+1; i++) {
  18. d1 = d2;
  19. d2 = d3;
  20. d3 = dist(&p1->point[i], &p2->point[i]);
  21. if(i >= 2 && d2 <= d1 && d2 <= d3)
  22. goto found;
  23. }
  24. return;
  25. found:
  26. N = 2880*PER/NPTS; /* 1 min steps */
  27. i -= 2;
  28. set3pt(p1, i, &o1);
  29. set3pt(p2, i, &o2);
  30. di = i;
  31. x = 0;
  32. dx = 2./N;
  33. for(i=0; i<=N; i++) {
  34. setpt(&o1, x);
  35. setpt(&o2, x);
  36. d1 = d2;
  37. d2 = d3;
  38. d3 = dist(&o1.act, &o2.act);
  39. if(i >= 2 && d2 <= d1 && d2 <= d3)
  40. goto found1;
  41. x += dx;
  42. }
  43. fprint(2, "bad 1 \n");
  44. return;
  45. found1:
  46. if(d2 > o1.act.semi2+o2.act.semi2+50)
  47. return;
  48. di += x - 3*dx;
  49. x = 0;
  50. for(i=0; i<3; i++) {
  51. setime(day + deld*(di + x));
  52. (*p1->obj)();
  53. setobj(&xo1.point[i]);
  54. (*p2->obj)();
  55. setobj(&xo2.point[i]);
  56. x += 2*dx;
  57. }
  58. dx /= 60;
  59. x = 0;
  60. set3pt(&xo1, 0, &o1);
  61. set3pt(&xo2, 0, &o2);
  62. for(i=0; i<=240; i++) {
  63. setpt(&o1, x);
  64. setpt(&o2, x);
  65. d1 = d2;
  66. d2 = d3;
  67. d3 = dist(&o1.act, &o2.act);
  68. if(i >= 2 && d2 <= d1 && d2 <= d3)
  69. goto found2;
  70. x += 1./120.;
  71. }
  72. fprint(2, "bad 2 \n");
  73. return;
  74. found2:
  75. if(d2 > o1.act.semi2 + o2.act.semi2)
  76. return;
  77. i1 = i-1;
  78. x1 = x - 1./120.;
  79. occ.t3 = di + i1 * dx;
  80. occ.e3 = o1.act.el;
  81. d3 = o1.act.semi2 - o2.act.semi2;
  82. if(d3 < 0)
  83. d3 = -d3;
  84. d4 = o1.act.semi2 + o2.act.semi2;
  85. for(i=i1,x=x1;; i++) {
  86. setpt(&o1, x);
  87. setpt(&o2, x);
  88. d1 = d2;
  89. d2 = dist(&o1.act, &o2.act);
  90. if(i != i1) {
  91. if(d1 <= d3 && d2 > d3) {
  92. occ.t4 = di + (i-.5) * dx;
  93. occ.e4 = o1.act.el;
  94. }
  95. if(d2 > d4) {
  96. if(d1 <= d4) {
  97. occ.t5 = di + (i-.5) * dx;
  98. occ.e5 = o1.act.el;
  99. }
  100. break;
  101. }
  102. }
  103. x += 1./120.;
  104. }
  105. for(i=i1,x=x1;; i--) {
  106. setpt(&o1, x);
  107. setpt(&o2, x);
  108. d1 = d2;
  109. d2 = dist(&o1.act, &o2.act);
  110. if(i != i1) {
  111. if(d1 <= d3 && d2 > d3) {
  112. occ.t2 = di + (i+.5) * dx;
  113. occ.e2 = o1.act.el;
  114. }
  115. if(d2 > d4) {
  116. if(d1 <= d4) {
  117. occ.t1 = di + (i+.5) * dx;
  118. occ.e1 = o1.act.el;
  119. }
  120. break;
  121. }
  122. }
  123. x -= 1./120.;
  124. }
  125. }
  126. void
  127. setpt(Occ *o, double x)
  128. {
  129. double y;
  130. y = x * (x-1);
  131. o->act.ra = o->del0.ra +
  132. x*o->del1.ra + y*o->del2.ra;
  133. o->act.decl2 = o->del0.decl2 +
  134. x*o->del1.decl2 + y*o->del2.decl2;
  135. o->act.semi2 = o->del0.semi2 +
  136. x*o->del1.semi2 + y*o->del2.semi2;
  137. o->act.el = o->del0.el +
  138. x*o->del1.el + y*o->del2.el;
  139. }
  140. double
  141. pinorm(double a)
  142. {
  143. while(a < -pi)
  144. a += pipi;
  145. while(a > pi)
  146. a -= pipi;
  147. return a;
  148. }
  149. void
  150. set3pt(Obj2 *p, int i, Occ *o)
  151. {
  152. Obj1 *p1, *p2, *p3;
  153. double a;
  154. p1 = p->point+i;
  155. p2 = p1+1;
  156. p3 = p2+1;
  157. o->del0.ra = p1->ra;
  158. o->del0.decl2 = p1->decl2;
  159. o->del0.semi2 = p1->semi2;
  160. o->del0.el = p1->el;
  161. a = p2->ra - p1->ra;
  162. o->del1.ra = pinorm(a);
  163. a = p2->decl2 - p1->decl2;
  164. o->del1.decl2 = pinorm(a);
  165. o->del1.semi2 = p2->semi2 - p1->semi2;
  166. o->del1.el = p2->el - p1->el;
  167. a = p1->ra + p3->ra - 2*p2->ra;
  168. o->del2.ra = pinorm(a)/2;
  169. a = p1->decl2 + p3->decl2 - 2*p2->decl2;
  170. o->del2.decl2 = pinorm(a)/2;
  171. o->del2.semi2 = (p1->semi2 + p3->semi2 - 2*p2->semi2) / 2;
  172. o->del2.el = (p1->el + p3->el - 2*p2->el) / 2;
  173. }