forked from rahulyhg/astro-11
-
Notifications
You must be signed in to change notification settings - Fork 0
/
moon_aspects.php
501 lines (411 loc) · 12.7 KB
/
moon_aspects.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
<?php
include ('header_moon.html');
$num_days = 5;
$start_month = gmdate("m");
$start_day = gmdate("d");
$start_year = gmdate("Y");
$hour2 = gmdate("H");
$minute2 = gmdate("i");
$timezone2 = 0;
// Unset any variables not initialized elsewhere in the program
unset($PATH,$out,$pl_name,$t_longitude, $t_speed);
$swephsrc = 'sweph';
$sweph = 'sweph';
putenv("PATH=$PATH:$swephsrc");
include("constants.php"); // this is here because we must name the planet names, 0 - 12, Sun - True Node
Moon_Aspectarian($pl_name, $start_month, $start_day, $start_year, $num_days, $timezone, $pl_ephem_number, $aspects_defined);
@mail(EMAIL, "Moon Aspects", "");
include("footer.html");
exit();
Function Moon_Aspectarian($pl_name, $init_month, $init_day, $init_year, $num_days, $timezone, $pl_ephem_number, $aspects_defined)
{
$num_t_planets = 13;
$current_tz = $timezone;
//find Julian day for transit date (at midnight)
$starting_JD = gregoriantojd($init_month, $init_day, $init_year) - 0.5;
$ending_JD = $starting_JD + $num_days - 1;
unset($moon_asp_details, $num_moon_aspects);
$num_moon_aspects = 0;
global $num_moon_aspects, $moon_asp_details;
//find when Moon enters new sign
for ($x = 0; $x <= 11; $x++)
{
$p1_idx = $pl_ephem_number[1]; //Moon index into Swiss ephemeris - for calculating new planet position
Get_when_planet_is_at_certain_degree_VOC($x, $p1_idx, $pl_name, $starting_JD, $ending_JD, $current_tz);
}
//start aspectarian - transit to transit
for ($x = 1; $x <= 1; $x++)
{
for ($y = 0; $y <= $num_t_planets - 1; $y++)
{
if ($y != 1 And $y != 11 And $y != 12)
{
$p1_idx = $pl_ephem_number[$x]; //planet index into Swiss ephemeris - for calculating new planet position
$p2_idx = $pl_ephem_number[$y];
Print_Moon_Aspectarian($x, $y, $p1_idx, $p2_idx, $pl_name, $aspects_defined, $starting_JD, $ending_JD, $num_days, $current_tz);
}
}
}
//sort the aspects found according to earliest time
for ($x = 1; $x <= $num_moon_aspects - 1; $x++)
{
for ($y = $x + 1; $y <= $num_moon_aspects; $y++)
{
if ($moon_asp_details[0][$y] < $moon_asp_details[0][$x])
{
$temp1 = $moon_asp_details[0][$x];
$temp2 = $moon_asp_details[1][$x];
$moon_asp_details[0][$x] = $moon_asp_details[0][$y];
$moon_asp_details[1][$x] = $moon_asp_details[1][$y];
$moon_asp_details[0][$y] = $temp1;
$moon_asp_details[1][$y] = $temp2;
}
}
}
// display the Moons aspects
echo "<table align='center' width='50%'><tr><td><font size='2'>";
for ($x = 1; $x <= $num_moon_aspects; $x++)
{
$flag = 0;
if ($x < $num_moon_aspects)
{
if (stristr($moon_asp_details[1][$x + 1], "enters the sign of") == false)
{
if (stristr($moon_asp_details[1][$x], "enters the sign of") == false)
{
$what_to_print = $moon_asp_details[1][$x];
}
else
{
$what_to_print = "<b><font color='#ff0000'>**</font>" . $moon_asp_details[1][$x] . "</b>";
}
}
else
{
$what_to_print = "<font color='#0000ff'><b>VC </b></font>" . $moon_asp_details[1][$x] . "<br>";
$flag = 1;
}
}
else
{
if (stristr($moon_asp_details[1][$x], "enters the sign of") == false)
{
$what_to_print = $moon_asp_details[1][$x];
}
else
{
$what_to_print = "<b><font color='#ff0000'>**</font>" . $moon_asp_details[1][$x] . "</b>";
}
}
if ($flag == 1)
{
echo $what_to_print . "<br><br>";
}
else
{
echo $what_to_print . "<br>";
if (jdtogregorian($moon_asp_details[0][$x] + 0.5) != jdtogregorian($moon_asp_details[0][$x + 1] + 0.5))
{
echo "<br>";
}
}
}
echo "<font></td></tr></table><br />";
}
Function Print_Moon_Aspectarian($p1, $p2, $p1_idx, $p2_idx, $pl_name, $aspects_defined, $starting_JD, $ending_JD, $num_days, $current_tz)
{
//Moon aspectarian
global $num_moon_aspects, $moon_asp_details;
for ($x = $starting_JD; $x <= $ending_JD; $x++)
{
//check for any exact aspect - major aspects only
for ($q = 1; $q <= 7; $q++) //$q is aspect number
{
if ($q != 2 And $q != 6)
{
$angle = $aspects_defined[$q];
$secant_results = Secant_Method($x, $x + 1, 0.00007, 100, $angle, $p1_idx, $p2_idx, $p2);
$Result_JD = $secant_results[0];
$rnd_off = sprintf("%.3f", $Result_JD);
if ($rnd_off >= $x And $rnd_off < $x + 1)
{
$first_date = ConvertJDtoDateandTime($Result_JD, $current_tz);
$num_moon_aspects = $num_moon_aspects + 1;
$moon_asp_details[0][$num_moon_aspects] = $Result_JD;
$moon_asp_details[1][$num_moon_aspects] = Assemble_aspect_string($p1, $q, $p2, $pl_name, $aspects_defined, $first_date, $secant_results);
break;
}
}
}
}
}
Function Secant_Method($earlier_jd, $later_jd, $e, $m, $angle, $p1_idx, $p2_idx, $p2)
{
for ($n = 1; $n <= $m; $n++)
{
//get positions of both planets on JD = later_jd and JD = earlier_jd
$result = Get_2_Planets_geo($later_jd, $p1_idx, $p2_idx);
$y1 = $result[0];
$speed1 = $result[1];
$y2 = $result[2];
$speed2 = $result[3];
$result = Get_2_Planets_geo($earlier_jd, $p1_idx, $p2_idx);
$y3 = $result[0];
$y4 = $result[2];
//get distance from exact aspect for both planets on JD = later_jd
$dayy = $y2 - $y1;
$da = abs($y2 - $y1);
if ($da > 180)
{
$da = 360 - $da;
}
$dist1 = $da - $angle;
if ($dayy <= -180 Or ($dayy >= 0 And $dayy < 180))
{
$dist1 = -$dist1;
}
//get distance from exact aspect for both planets on JD = earlier_jd
$dayy = $y4 - $y3;
$da = abs($y4 - $y3);
if ($da > 180)
{
$da = 360 - $da;
}
$dist2 = $da - $angle;
if ($dayy <= -180 Or ($dayy >= 0 And $dayy < 180))
{
$dist2 = -$dist2;
}
if ($dist1 - $dist2 == 0)
{
$later_jd = ($later_jd + $earlier_jd) / 2;
$d = 0;
}
else
{
$d = (($later_jd - $earlier_jd) / ($dist1 - $dist2)) * $dist1;
}
if (abs($dist1 - $dist2) > 20 And $n >= 2)
{
//keep from looping needlessly AND
//protect against case where dist1 = -dist2, which gives false aspect
//example 21 March 2006 - Moon 120 Mars - there is no trine, but an opposition
$later_jd = 0;
break;
}
if (abs($d) < $e)
{
break;
}
$earlier_jd = $later_jd;
if (abs($d) >= 1.001)
{
//out of range - there is no aspect in this time frame (1 day)
$later_jd = 0;
break;
}
else
{
$later_jd = $later_jd - $d;
}
}
$results[0] = $later_jd;
$results[1] = $y1;
$results[2] = $speed1;
$results[3] = $y2;
$results[4] = $speed2;
return $results;
}
Function Get_1_Planet_geo($jd, $p_idx)
{
//get longitude of planet indicated by $p_idx
$swephsrc = 'sweph';
$sweph = 'sweph';
//to account for ephemeris time (delta t added in) instead of universal time
//I suppose I could fetch delta t exactly, but I do not think it is worth it
$ejd = $jd + 0.00075388 / 2;
unset($out,$t_long);
exec ("swetest -edir$sweph -bj$ejd -p$p_idx -eswe -fls -g, -head", $out);
// Each line of output data from swetest is exploded into array $row, giving these elements:
// 0 = longitude
// 1 = speed
foreach ($out as $key => $line)
{
$row = explode(',',$line);
$t_long[$key] = $row[0];
$t_speed[$key] = $row[1];
};
$long_speed[0] = $t_long[0];
$long_speed[1] = $t_speed[0];
return $long_speed;
}
Function ConvertJDtoDateandTime($Result_JD, $current_tz)
{
//returns date and time in local time, e.g. 9/3/2007 4:59 am
//get calendar day - must adjust for the way the PHP function works by adding 0.5 days to the JD of interest
$jd_to_use = $Result_JD + $current_tz / 24;
$JDDate = jdtogregorian($jd_to_use + 0.5);
$fraction = $jd_to_use - floor($jd_to_use);
if ($fraction < 0.5)
{
$am_pm = "pm";
}
else
{
$fraction = $fraction - 0.5;
$am_pm = "am";
}
$hh = $fraction * 24;
if ($hh < 1)
{
$hh = $hh + 12;
}
$mm = $hh - floor($hh);
if (floor($mm * 60) < 10)
{
return $JDDate . " " . floor($hh) . ":0" . floor($mm * 60) . " " . $am_pm . " GMT";
}
else
{
return $JDDate . " " . floor($hh) . ":" . floor($mm * 60) . " " . $am_pm . " GMT";
}
}
Function Assemble_aspect_string($x, $q, $y, $pl_name, $aspects_defined, $first_date, $secant_results)
{
$t = $pl_name[$x] . Attach_sign($x, $secant_results[1], $secant_results[2]) . $aspects_defined[$q] . " " . $pl_name[$y] . Attach_sign($y, $secant_results[3], $secant_results[4]) . " on " . $first_date;
return $t;
}
Function Attach_sign($p_num, $t_longitude, $t_speed)
{
$pos = $t_longitude;
$rx = " ";
if ($t_speed < 0)
{
$rx = " R";
}
$sign_num = floor($pos / 30);
$zodiac_signs = "AriTauGemCanLeoVirLibScoSagCapAquPis";
return " in " . substr($zodiac_signs, $sign_num * 3, 3) . " <font color='#ff0000'>" . $rx . "</font> "; //end with a space
}
Function Get_when_planet_is_at_certain_degree_VOC($deg_idx, $p1_idx, $pl_name, $starting_JD, $ending_JD, $current_tz)
{
//aspectarian for when a planet hits a certain degree of the zodiac
global $num_moon_aspects, $moon_asp_details;
$degr = $deg_idx * 30;
for ($x = $starting_JD; $x <= $ending_JD; $x++)
{
$angle = 0;
$secant_results = Secant_Method_one_degree($x, $x + 1, 0.00007, 100, $angle, $p1_idx, $degr);
$Result_JD = $secant_results[0];
$name_of_sign = Get_Name_of_Sign($secant_results[1] + 1); //add 1 to the longitude so we dont get rounding errors
$rnd_off = sprintf("%.3f", $Result_JD);
if ($rnd_off >= $x And $rnd_off < $x + 1)
{
$first_date = ConvertJDtoDateandTime($Result_JD, $current_tz);
$num_moon_aspects = $num_moon_aspects + 1;
$moon_asp_details[0][$num_moon_aspects] = $Result_JD;
$moon_asp_details[1][$num_moon_aspects] = "t. Moon enters the sign of $name_of_sign at $first_date";
}
}
}
Function Secant_Method_one_degree($earlier_jd, $later_jd, $e, $m, $angle, $p1_idx, $degr)
{
for ($n = 1; $n <= $m; $n++)
{
//get positions of both planets on JD = later_jd and JD = earlier_jd
$ls = Get_1_Planet_geo($later_jd, $p1_idx);
$y1 = $ls[0];
$ls = Get_1_Planet_geo($earlier_jd, $p1_idx);
$y3 = $ls[0];
//get distance from exact aspect for both planets on JD = later_jd
$dayy = $degr - $y1;
$da = abs($degr - $y1);
if ($da > 180)
{
$da = 360 - $da;
}
$dist1 = $da - $angle;
if ($dayy <= -180 Or ($dayy >= 0 And $dayy < 180))
{
$dist1 = -$dist1;
}
//get distance from exact aspect for both planets on JD = earlier_jd
$dayy = $degr - $y3;
$da = abs($degr - $y3);
if ($da > 180)
{
$da = 360 - $da;
}
$dist2 = $da - $angle;
if ($dayy <= -180 Or ($dayy >= 0 And $dayy < 180))
{
$dist2 = -$dist2;
}
if ($dist1 - $dist2 == 0)
{
$later_jd = ($later_jd + $earlier_jd) / 2;
$d = 0;
}
else
{
$d = (($later_jd - $earlier_jd) / ($dist1 - $dist2)) * $dist1;
}
if (abs($dist1 - $dist2) > 20 And $n >= 2)
{
//keep from looping needlessly AND
//protect against case where dist1 = -dist2, which gives false aspect
//example 21 March 2006 - Moon 120 Mars - there is no trine, but an opposition
$later_jd = 0;
break;
}
if (abs($d) < $e)
{
break;
}
$earlier_jd = $later_jd;
if (abs($d) >= 1.001)
{
//out of range - there is no aspect in this time frame (1 day)
$later_jd = 0;
break;
}
else
{
$later_jd = $later_jd - $d;
}
}
$results[0] = $later_jd;
$results[1] = $y1;
return $results;
}
Function Get_Name_of_Sign($degr)
{
$sign_of = floor($degr / 30) + 1;
return $name_of_sign[$sign_of];
}
Function Get_2_Planets_geo($jd, $p1_idx, $p2_idx)
{
//get longitudes of planets indicated by $p1_idx and $p2_idx
$swephsrc = 'sweph';
$sweph = 'sweph';
//to account for ephemeris time (delta t added in) instead of universal time
//I suppose I could fetch delta t exactly, but I do not think it is worth it
$ejd = $jd + 0.00075388 / 2;
unset($out,$t_long);
exec ("swetest -edir$sweph -bj$ejd -p$p1_idx$p2_idx -eswe -fls -g, -head", $out);
// Each line of output data from swetest is exploded into array $row, giving these elements:
// 0 = longitude
// 1 = speed
foreach ($out as $key => $line)
{
$row = explode(',',$line);
$t_long[$key] = $row[0];
$t_speed[$key] = $row[1];
};
$result[0] = $t_long[0]; //planet 1
$result[1] = $t_speed[0];
$result[2] = $t_long[1]; //planet 2
$result[3] = $t_speed[1];
return $result;
}
?>