forked from CruiserOne/Astrolog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
calc.cpp
3207 lines (2792 loc) · 105 KB
/
calc.cpp
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
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
** Astrolog (Version 7.70) File: calc.cpp
**
** IMPORTANT NOTICE: Astrolog and all chart display routines and anything
** not enumerated below used in this program are Copyright (C) 1991-2024 by
** Walter D. Pullen ([email protected], http://www.astrolog.org/astrolog.htm).
** Permission is granted to freely use, modify, and distribute these
** routines provided these credits and notices remain unmodified with any
** altered or distributed versions of the program.
**
** The main ephemeris databases and calculation routines are from the
** library SWISS EPHEMERIS and are programmed and copyright 1997-2008 by
** Astrodienst AG. Use of that source code is subject to license for Swiss
** Ephemeris Free Edition at https://www.astro.com/swisseph/swephinfo_e.htm.
** This copyright notice must not be changed or removed by any user of this
** program.
**
** Additional ephemeris databases and formulas are from the calculation
** routines in the program PLACALC and are programmed and Copyright (C)
** 1989,1991,1993 by Astrodienst AG and Alois Treindl ([email protected]). The
** use of that source code is subject to regulations made by Astrodienst
** Zurich, and the code is not in the public domain. This copyright notice
** must not be changed or removed by any user of this program.
**
** The original planetary calculation routines used in this program have
** been copyrighted and the initial core of this program was mostly a
** conversion to C of the routines created by James Neely as listed in
** 'Manual of Computer Programming for Astrologers', by Michael Erlewine,
** available from Matrix Software.
**
** Atlas composed using data from https://www.geonames.org/ licensed under a
** Creative Commons Attribution 4.0 License. Time zone changes composed using
** public domain TZ database: https://data.iana.org/time-zones/tz-link.html
**
** The PostScript code within the core graphics routines are programmed
** and Copyright (C) 1992-1993 by Brian D. Willoughby ([email protected]).
**
** More formally: This program is free software; you can redistribute it
** and/or modify it under the terms of the GNU General Public License as
** published by the Free Software Foundation; either version 2 of the
** License, or (at your option) any later version. This program is
** distributed in the hope that it will be useful and inspiring, but
** WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** General Public License for more details, a copy of which is in the
** LICENSE.HTM file included with Astrolog, and at http://www.gnu.org
**
** Initial programming 8/28-30/1991.
** X Window graphics initially programmed 10/23-29/1991.
** PostScript graphics initially programmed 11/29-30/1992.
** Last code change made 4/22/2024.
*/
#include "astrolog.h"
/*
******************************************************************************
** Julian Day Calculations.
******************************************************************************
*/
// Given a month, day, and year, convert it into a single Julian day value,
// i.e. the number of days passed since a fixed reference date.
long MdyToJulian(int mon, int day, int yea)
{
#ifdef MATRIX
if (!us.fEphemFiles)
return MatrixMdyToJulian(mon, day, yea);
#endif
#ifdef EPHEM
int fGreg = fTrue;
double jd;
if (yea < ciGreg.yea || (yea == ciGreg.yea &&
(mon < ciGreg.mon || (mon == ciGreg.mon && day < ciGreg.day))))
fGreg = fFalse;
#ifdef SWISS
if (!us.fPlacalcPla)
jd = SwissJulDay(mon, day, yea, 12.0, fGreg) + rRound;
#endif
#ifdef PLACALC
if (us.fPlacalcPla)
jd = julday(mon, day, yea, 12.0, fGreg) + rRound;
#endif
return (long)RFloor(jd);
#else
return 0; // Shouldn't ever be reached.
#endif // EPHEM
}
// Like above but return a fractional Julian time given the extra info.
real MdytszToJulian(int mon, int day, int yea, real tim, real dst, real zon)
{
if (dst == dstAuto)
dst = (real)is.fDst;
return (real)MdyToJulian(mon, day, yea) + (tim + zon - dst) / 24.0;
}
// Take a Julian day value, and convert it back into the corresponding month,
// day, and year.
void JulianToMdy(real JD, int *mon, int *day, int *yea)
{
#ifdef EPHEM
double tim;
#endif
#ifdef MATRIX
if (!us.fEphemFiles) {
MatrixJulianToMdy(JD, mon, day, yea);
return;
}
#endif
#ifdef SWISS
if (!us.fPlacalcPla) {
SwissRevJul(JD, JD >= 2299171.0 /* Oct 15, 1582 */, mon, day, yea, &tim);
return;
}
#endif
#ifdef PLACALC
if (us.fPlacalcPla) {
revjul(JD, JD >= 2299171.0 /* Oct 15, 1582 */, mon, day, yea, &tim);
return;
}
#endif
*mon = mJan; *day = 1; *yea = 2024;
}
/*
******************************************************************************
** House Cusp Calculations.
******************************************************************************
*/
// Compute 3D houses for 3D Campanus or the default case where houses are 12
// equal sized wedges covering the celestial sphere. Basically the same as
// doing local horizon, giving coordinates relative to prime vertical.
real RHousePlaceIn3DCore(real rLon, real rLat)
{
real lon, lat;
lon = Tropical(rLon); lat = rLat;
EclToEqu(&lon, &lat);
lon = Mod(cp0.lonMC - lon + rDegQuad);
if (us.nHouse3D == hmPrime) {
if (!us.fRefract)
EquToLocal(&lon, &lat, -Lat);
else {
EquToLocal(&lon, &lat, rDegQuad - Lat);
lat = SwissRefract(lat);
CoorXform(&lon, &lat, -rDegQuad);
}
} else if (us.nHouse3D == hmHorizon)
EquToLocal(&lon, &lat, rDegQuad - Lat);
lon = rDegMax - lon;
return Mod(lon + rSmall);
}
// Compute 3D houses, or the house postion of a 3D location. Given a zodiac
// position and latitude, return the house position as a decimal number, which
// includes how far through the house the coordinates are.
real RHousePlaceIn3D(real rLon, real rLat)
{
real deg, rRet;
int i, di;
// Campanus houses arranged along the prime vertical are equal sized in 3D,
// as are a couple other combinations, and so are a simple case to handle.
deg = RHousePlaceIn3DCore(rLon, rLat);
if ((us.nHouseSystem == hsCampanus && us.nHouse3D == hmPrime) ||
(us.nHouseSystem == hsHorizon && us.nHouse3D == hmHorizon) ||
(us.nHouseSystem == hsMeridian && us.nHouse3D == hmEquator))
return deg;
// Determine which 3D house the prime vertical degree falls within.
di = MinDifference(chouse3[1], chouse3[2]) >= 0.0 ? 1 : -1;
i = 0;
do {
i++;
} while (!(i >= cSign ||
(deg >= chouse3[i] && deg < chouse3[Mod12(i + di)]) ||
(chouse3[i] > chouse3[Mod12(i + di)] &&
(deg >= chouse3[i] || deg < chouse3[Mod12(i + di)]))));
if (di < 0)
i = Mod12(i - 1);
rRet = Mod(ZFromS(i) + MinDistance(chouse3[i], deg) /
MinDistance(chouse3[i], chouse3[Mod12(i + 1)]) * 30.0);
return rRet;
}
// This is a subprocedure of ComputeInHouses(). Given a zodiac position,
// return which of the twelve houses it falls in. Remember that a special
// check has to be done for the house that spans 0 degrees Aries.
int NHousePlaceIn(real rLon, real rLat)
{
int i, di;
// Special processing for 3D houses.
if (us.fHouse3D && rLat != 0.0)
return SFromZ(RHousePlaceIn3D(rLon, rLat));
// This loop also works when house positions decrease through the zodiac.
rLon = Mod(rLon + rSmall);
di = MinDifference(chouse[1], chouse[2]) >= 0.0 ? 1 : -1;
i = 0;
do {
i++;
} while (!(i >= cSign ||
(rLon >= chouse[i] && rLon < chouse[Mod12(i + di)]) ||
(chouse[i] > chouse[Mod12(i + di)] &&
(rLon >= chouse[i] || rLon < chouse[Mod12(i + di)]))));
if (di < 0)
i = Mod12(i - 1);
return i;
}
// For each object in the chart, determine what house it belongs in.
void ComputeInHouses(void)
{
int i;
// First determine 3D house cusp offsets.
if ((us.nHouseSystem == hsCampanus && us.nHouse3D == hmPrime) ||
(us.nHouseSystem == hsHorizon && us.nHouse3D == hmHorizon) ||
(us.nHouseSystem == hsMeridian && us.nHouse3D == hmEquator)) {
// 3D Campanus cusps are always equal sized wedges when distributed
// along the prime vertical, as are a couple of other combinations.
for (i = 1; i <= cSign; i++)
chouse3[i] = ZFromS(i);
} else
for (i = 1; i <= cSign; i++)
chouse3[i] = RHousePlaceIn3DCore(chouse[i], 0.0);
// Loop over each object and place it.
for (i = 0; i <= is.nObj; i++)
inhouse[i] = NHousePlaceIn(planet[i], planetalt[i]);
// Avoid roundoff error by setting houses of objects known definitively.
if (us.fHouse3D) {
// 3D wedges that are equal sized should always be in corresponding house.
if ((us.nHouseSystem == hsCampanus && us.nHouse3D == hmPrime) ||
(us.nHouseSystem == hsHorizon && us.nHouse3D == hmHorizon) ||
(us.nHouseSystem == hsMeridian && us.nHouse3D == hmEquator)) {
for (i = cuspLo; i <= cuspHi; i++)
if ((us.nHouse3D == hmPrime || (i != oAsc && i != oDes)) &&
FNearR(chouse[i - cuspLo + 1], planet[i]))
inhouse[i] = i - cuspLo + 1;
// 3D angles for most systems should always be in the corresponding house.
} else if (us.fHouseAngle) {
if (us.nHouse3D == hmPrime) {
for (i = cuspLo; i <= cuspHi; i += 3)
if (FNearR(chouse[i - cuspLo + 1], planet[i]))
inhouse[i] = i - cuspLo + 1;
} else {
for (i = cuspLo+4; i <= cuspHi; i += 6)
if (FNearR(chouse[i - cuspLo + 1], planet[i]))
inhouse[i] = i - cuspLo + 1;
}
}
if (us.nHouse3D == hmHorizon && FNearR(chouse[7], planet[oVtx]))
inhouse[oVtx] = 7;
else if (us.nHouse3D == hmEquator && FNearR(chouse[1], planet[oEP]))
inhouse[oEP] = 1;
}
}
// Generic function to compute any of the various Equal house systems, in
// which all houses are an equal 30 degrees in size.
void HouseEqualGeneric(real rOffset)
{
int i;
for (i = 1; i <= cSign; i++)
chouse[i] = Mod(ZFromS(i) + rOffset);
}
// Compute the cusp positions using the Porphyry house system.
void HousePorphyry(real Asc)
{
int i;
real rQuad, rSeg;
rQuad = MinDistance(is.MC, Asc);
rSeg = rQuad / 3.0;
for (i = 0; i < 3; i++)
chouse[sCap + i] = Mod(is.MC + rSeg*(real)i);
rSeg = (rDegHalf - rQuad) / 3.0;
for (i = 0; i < 3; i++)
chouse[sLib + i] = Mod(Asc + rSeg*(real)i + rDegHalf);
for (i = 1; i <= 6; i++)
chouse[i] = Mod(chouse[6 + i] + rDegHalf);
}
// The Sripati house system is like the Porphyry system except each house
// starts in the middle of the previous house as defined by Porphyry.
void HouseSripati(void)
{
int i;
real rgr[cSign+1];
HousePorphyry(is.Asc);
for (i = 1; i <= cSign; i++)
rgr[i] = chouse[i];
for (i = 1; i <= cSign; i++)
chouse[i] = Midpoint(rgr[i], rgr[Mod12(i-1)]);
}
// Compute the cusp positions using the Alcabitius house system.
void HouseAlcabitius(void)
{
real rDecl, rSda, rSna, r, rLon;
int i;
rDecl = RAsin(RSinD(is.OB) * RSinD(is.Asc));
r = -RTanD(AA) * RTan(rDecl);
rSda = DFromR(RAcos(r));
rSna = rDegHalf - rSda;
chouse[sLib] = is.RA - rSna;
chouse[sSco] = is.RA - rSna*2.0/3.0;
chouse[sSag] = is.RA - rSna/3.0;
chouse[sCap] = is.RA;
chouse[sAqu] = is.RA + rSda/3.0;
chouse[sPis] = is.RA + rSda*2.0/3.0;
for (i = sLib; i <= sPis; i++) {
r = RFromD(Mod(chouse[i]));
// The transformation below is also done in CuspMidheaven().
rLon = RAtn(RTan(r)/RCosD(is.OB));
if (rLon < 0.0)
rLon += rPi;
if (r > rPi)
rLon += rPi;
chouse[i] = Mod(DFromR(rLon)+is.rSid);
}
for (i = sAri; i <= sVir; i++)
chouse[i] = Mod(chouse[i+6]+rDegHalf);
}
// This is a newer house system similar in philosophy to Porphyry houses, and
// therefore (at least in the past) has also been called Neo-Porphyry. Instead
// of just trisecting the difference in each quadrant, do a smooth sinusoidal
// distribution of the difference around all the cusps. Note that middle
// houses become 0 sized if a quadrant is <= 30 degrees.
void HousePullenSinusoidalDelta(real Asc)
{
real rQuad, rDelta;
int iHouse;
// Solve equations: x+n + x + x+n = q, x+3n + x+4n + x+3n = 180-q.
rQuad = MinDistance(is.MC, Asc);
rDelta = (rQuad - rDegQuad)/4.0;
chouse[sLib] = Mod(Asc+rDegHalf); chouse[sCap] = is.MC;
if (rQuad >= 30.0) {
chouse[sAqu] = Mod(chouse[sCap] + 30.0 + rDelta);
chouse[sPis] = Mod(chouse[sAqu] + 30.0 + rDelta*2.0);
} else
chouse[sAqu] = chouse[sPis] = Midpoint(chouse[sCap], Asc);
if (rQuad <= 150.0) {
chouse[sSag] = Mod(chouse[sCap] - 30.0 + rDelta);
chouse[sSco] = Mod(chouse[sSag] - 30.0 + rDelta*2.0);
} else
chouse[sSag] = chouse[sSco] = Midpoint(chouse[sCap], chouse[sLib]);
for (iHouse = sAri; iHouse < sLib; iHouse++)
chouse[iHouse] = Mod(chouse[iHouse+6] + rDegHalf);
}
// This is a new house system very similar to Sinusoidal Delta. Instead of
// adding a sine wave offset, multiply a sine wave ratio.
void HousePullenSinusoidalRatio(real Asc)
{
real qSmall, rRatio, rRatio3, rRatio4, xHouse, rLo, rHi;
int iHouse, dir;
// Start by determining the quadrant sizes.
qSmall = MinDistance(is.MC, Asc);
dir = qSmall <= rDegQuad ? 1 : -1;
if (dir < 0)
qSmall = rDegHalf - qSmall;
#if TRUE
// Solve equations: rx + x + rx = q, xr^3 + xr^4 + xr^3 = 180-q. Solve
// quartic for r, then compute x given 1st equation: x = q / (2r + 1).
if (qSmall > 0.0) {
rLo = (2.0*pow(qSmall*qSmall - 270.0*qSmall + 16200.0, 1.0/3.0)) /
pow(qSmall, 2.0/3.0);
rHi = RSqr(rLo + 1.0);
rRatio = 0.5*rHi +
0.5*RSqr(-6.0*(qSmall-120.0)/(qSmall*rHi) - rLo + 2.0) - 0.5;
} else
rRatio = 0.0;
rRatio3 = rRatio * rRatio * rRatio; rRatio4 = rRatio3 * rRatio;
xHouse = qSmall / (2.0 * rRatio + 1.0);
#else
// Can also solve equations empirically. Given candidate for r, compute x
// given 1st equation: x = q / (2r + 1), then compare both against 2nd:
// 2xr^3 + xr^4 = 180-q, to see whether current r is too large or small.
// Before binary searching, first keep doubling rHi until too large.
real qLarge = rDegHalf - qSmall;
flag fBinarySearch = fFalse;
rLo = rRatio = 1.0;
loop {
rRatio = fBinarySearch ? (rLo + rHi) / 2.0 : rRatio * 2.0;
rRatio3 = rRatio * rRatio * rRatio; rRatio4 = rRatio3 * rRatio;
xHouse = qSmall / (2.0 * rRatio + 1.0);
if ((fBinarySearch && (rRatio <= rLo || rRatio >= rHi)) || xHouse <= 0.0)
break;
if (2.0 * xHouse * rRatio3 + xHouse * rRatio4 >= qLarge) {
rHi = rRatio;
fBinarySearch = fTrue;
} else if (fBinarySearch)
rLo = rRatio;
}
#endif
// xHouse and rRatio have been calculated. Fill in the house cusps.
if (dir < 0)
neg(xHouse);
chouse[sAri] = Asc; chouse[sCap] = is.MC;
chouse[sLib] = Mod(Asc + rDegHalf);
chouse[sCap + dir] = Mod(chouse[sCap] + xHouse * rRatio);
chouse[sCap + dir*2] = Mod(chouse[Mod12(sCap + dir*3)] - xHouse * rRatio);
chouse[sCap - dir] = Mod(chouse[sCap] - xHouse * rRatio3);
chouse[sCap - dir*2] = Mod(chouse[Mod12(sCap - dir*3)] + xHouse * rRatio3);
for (iHouse = sTau; iHouse < sLib; iHouse++)
chouse[iHouse] = Mod(chouse[iHouse+6] + rDegHalf);
}
// Compute the cusp positions using the Equal (Ascendant) house system.
#define HouseEqual() HouseEqualGeneric(is.Asc)
// This house system is just like the Equal system except that we start our 12
// equal segments from the Midheaven instead of the Ascendant.
#define HouseEqualMC() HouseEqualGeneric(is.MC + rDegQuad)
// The "Whole" house system is like the Equal system with 30 degree houses,
// where the 1st house starts at zero degrees of the sign of the Ascendant.
#define HouseWhole() HouseEqualGeneric((real)((SFromZ(is.Asc)-1)*30))
// Like "Whole" houses but the 10th house starts at the sign of the MC.
#define HouseWholeMC() \
HouseEqualGeneric((real)((SFromZ(is.MC)-1)*30) + rDegQuad)
// The "Vedic" house system is like the Equal system except each house starts
// 15 degrees earlier. The Asc falls in the middle of the 1st house.
#define HouseVedic() HouseEqualGeneric(is.Asc - 15.0)
// Like "Vedic" houses bit the MC falls in the middle of the 10th house.
#define HouseVedicMC() HouseEqualGeneric(is.MC + rDegQuad - 15.0)
// Balanced Equal house systems split the difference between Asc and MC.
#define HouseEqualBalanced() HouseEqualGeneric(Midpoint(is.Asc, is.MC) + 45.0)
#define HouseWholeBalanced() HouseEqualGeneric((real)\
((SFromZ(Midpoint(is.Asc, is.MC) + 15.0)-1)*30 + 30.0))
#define HouseVedicBalanced() HouseEqualGeneric(Midpoint(is.Asc, is.MC) + 30.0)
// East Point Equal house systems are based around the East Point.
#define HouseEqualEP() HouseEqualGeneric(is.EP)
#define HouseWholeEP() HouseEqualGeneric((real)((SFromZ(is.EP)-1)*30))
#define HouseVedicEP() HouseEqualGeneric(is.EP - 15.0)
// Vertex Equal house systems are based around the Antivertex.
#define HouseEqualVertex() HouseEqualGeneric(is.Vtx + rDegHalf)
#define HouseWholeVertex() \
HouseEqualGeneric((real)((SFromZ(is.Vtx + rDegHalf)-1)*30))
#define HouseVedicVertex() HouseEqualGeneric(is.Vtx + rDegHalf - 15.0)
// In "Null" houses, the cusps are fixed to start at their corresponding sign,
// i.e. the 1st house is always at 0 degrees Aries, etc.
#define HouseNull() HouseEqualGeneric(0.0)
// Calculate the house cusp positions, using the specified system. Note this
// is only called when Swiss Ephemeris is NOT computing the houses.
void ComputeHouses(int housesystem)
{
char sz[cchSzDef];
real Vtx;
// Don't allow polar latitudes if system not defined in polar zones.
if ((housesystem == hsPlacidus || housesystem == hsKoch) &&
RAbs(AA) >= rDegQuad - is.OB) {
sprintf(sz,
"The %s system of houses is not defined at extreme latitudes.",
szSystem[housesystem]);
PrintWarning(sz);
housesystem = hsPorphyry;
}
// Flip the Ascendant or MC if it falls in the wrong half of the zodiac.
if (MinDifference(is.MC, is.Asc) < 0.0) {
if (us.fPolarAsc)
is.MC = Mod(is.MC + rDegHalf);
else
is.Asc = Mod(is.Asc + rDegHalf);
}
Vtx = Mod(is.Vtx + rDegHalf);
switch (housesystem) {
#ifdef MATRIX
case hsPlacidus: HousePlacidus(); break;
case hsKoch: HouseKoch(); break;
case hsCampanus: HouseCampanus(); break;
case hsMeridian: HouseMeridian(); break;
case hsRegiomontanus: HouseRegiomontanus(); break;
case hsMorinus: HouseMorinus(); break;
case hsTopocentric: HouseTopocentric(); break;
#endif
case hsEqual: HouseEqual(); break;
case hsPorphyry: HousePorphyry(is.Asc); break;
case hsAlcabitius: HouseAlcabitius(); break;
case hsEqualMC: HouseEqualMC(); break;
case hsSineRatio: HousePullenSinusoidalRatio(is.Asc); break;
case hsSineDelta: HousePullenSinusoidalDelta(is.Asc); break;
case hsWhole: HouseWhole(); break;
case hsVedic: HouseVedic(); break;
case hsSripati: HouseSripati(); break;
// New experimental house systems follow:
case hsWholeMC: HouseWholeMC(); break;
case hsVedicMC: HouseVedicMC(); break;
case hsEqualBalanced: HouseEqualBalanced(); break;
case hsWholeBalanced: HouseWholeBalanced(); break;
case hsVedicBalanced: HouseVedicBalanced(); break;
case hsEqualEP: HouseEqualEP(); break;
case hsWholeEP: HouseWholeEP(); break;
case hsVedicEP: HouseVedicEP(); break;
case hsEqualVertex: HouseEqualVertex(); break;
case hsWholeVertex: HouseWholeVertex(); break;
case hsVedicVertex: HouseVedicVertex(); break;
case hsPorphyryEP: HousePorphyry(is.EP); break;
case hsPorphyryVtx: HousePorphyry(Vtx); break;
case hsSineRatioEP: HousePullenSinusoidalRatio(is.EP); break;
case hsSineRatioVtx: HousePullenSinusoidalRatio(Vtx); break;
case hsSineDeltaEP: HousePullenSinusoidalDelta(is.EP); break;
case hsSineDeltaVtx: HousePullenSinusoidalDelta(Vtx); break;
default: HouseNull();
housesystem = hsNull;
}
is.nHouseSystem = housesystem;
}
/*
******************************************************************************
** Star Position Calculations.
******************************************************************************
*/
// This is used by the chart calculation routine to calculate the positions
// of the fixed stars. Since stars don't move much in the sky over time,
// getting their positions is mostly just reading info from an array and
// converting it to the correct reference frame. However, have to add in
// the correct precession for the tropical zodiac.
void ComputeStars(real t, real Off)
{
#ifdef MATRIX
int i;
real x, y, z;
#endif
// Read in star positions.
#ifdef SWISS
if (FCmSwissStar())
SwissComputeStars(t, fFalse);
else
#endif
{
#ifdef MATRIX
for (i = 1; i <= cStar; i++) {
x = rStarData[i*6-6]; y = rStarData[i*6-5]; z = rStarData[i*6-4];
planet[oNorm+i] = x*rDegMax/24.0 + y*15.0/60.0 + z*0.25/60.0;
x = rStarData[i*6-3]; y = rStarData[i*6-2]; z = rStarData[i*6-1];
if (x < 0.0) {
neg(y); neg(z);
}
planetalt[oNorm+i] = x + y/60.0 + z/60.0/60.0;
// Convert to ecliptic zodiac coordinates.
EquToEcl(&planet[oNorm+i], &planetalt[oNorm+i]);
planet[oNorm+i] = Mod(planet[oNorm+i] + rEpoch2000 + Off);
if (!us.fSidereal)
ret[oNorm+i] = !us.fVelocity ? rDegMax/25765.0/rDayInYear : 1.0;
SphToRec(cp0.dist[oNorm+i], planet[oNorm+i], planetalt[oNorm+i],
&space[oNorm+i].x, &space[oNorm+i].y, &space[oNorm+i].z);
}
#endif
}
}
// Given the list of computed planet positions, sort and compose the final
// index list based on what order the planets are supposed to be printed in.
void SortPlanets()
{
int i, j;
#ifdef EXPRESS
real rgrSort[oNorm1];
flag fCare1, fCare2;
#endif
// By default, objects are displayed in object index order.
for (i = 0; i <= cObj; i++)
rgobjList[i] = rgobjList2[i] = i;
#ifdef EXPRESS
// Adjust indexes used for display with AstroExpressions.
if (FSzSet(us.szExpSort)) {
for (i = 0; i <= oNorm; i++) {
ExpSetN(iLetterZ, i);
ParseExpression(us.szExpSort);
rgrSort[i] = RExpGet(iLetterZ);
}
// Sort adjusted list to determine final display ordering.
for (i = 1; i <= oNorm; i++) {
j = i-1;
loop {
fCare1 = !ignore[rgobjList[j]] || !ignore2[rgobjList[j]];
fCare2 = !ignore[rgobjList[j+1]] || !ignore2[rgobjList[j+1]];
if (!(j >= 0 && ((!fCare1 && fCare2) || (fCare1 == fCare2 &&
rgrSort[rgobjList[j]] > rgrSort[rgobjList[j+1]]))))
break;
SwapN(rgobjList[j], rgobjList[j+1]);
j--;
}
}
}
#endif
// Now take the list of computed star positions, and sort and compose the
// final index list based on what order the stars are supposed to be printed
// in. Only sort if one of the special -U subswitches is in effect.
if (us.nStarSort > 0)
for (i = starLo+1; i <= starHi; i++) {
j = i-1;
// Compare star names for -Un switch.
if (us.nStarSort == 'n') while (j >= starLo && NCompareSz(
szObjDisp[rgobjList[j]], szObjDisp[rgobjList[j+1]]) > 0) {
SwapN(rgobjList[j], rgobjList[j+1]);
j--;
// Compare star brightnesses for -Ub switch.
} else if (us.nStarSort == 'b') while (j >= starLo &&
rStarBright[rgobjList[j]-oNorm] > rStarBright[rgobjList[j+1]-oNorm]) {
SwapN(rgobjList[j], rgobjList[j+1]);
j--;
// Compare star zodiac locations for -Uz switch.
} else if (us.nStarSort == 'z') while (j >= starLo &&
planet[rgobjList[j]] > planet[rgobjList[j+1]]) {
SwapN(rgobjList[j], rgobjList[j+1]);
j--;
// Compare star latitudes for -Ul switch.
} else if (us.nStarSort == 'l') while (j >= starLo &&
planetalt[rgobjList[j]] < planetalt[rgobjList[j+1]]) {
SwapN(rgobjList[j], rgobjList[j+1]);
j--;
// Compare star distances for -Ud switch.
} else if (us.nStarSort == 'd') while (j >= starLo &&
cp0.dist[rgobjList[j]] > cp0.dist[rgobjList[j+1]]) {
SwapN(rgobjList[j], rgobjList[j+1]);
j--;
// Compare star velocities for -Uv switch.
} else if (us.nStarSort == 'v') while (j >= starLo &&
ret[rgobjList[j]] < ret[rgobjList[j+1]]) {
SwapN(rgobjList[j], rgobjList[j+1]);
j--;
}
}
// Produce reverse lookup table mapping object index to its print order.
for (i = 0; i <= cObj; i++)
rgobjList2[rgobjList[i]] = i;
}
/*
******************************************************************************
** Chart Calculation.
******************************************************************************
*/
// Given a zodiac degree, transform it into its Decan sign, in which each
// sign is trisected into the three signs of its element. For example:
// 1 Aries -> 3 Aries, 10 Leo -> 0 Sagittarius, 25 Sagittarius -> 15 Leo.
real Decan(real deg)
{
int sign;
real unit;
sign = SFromZ(deg);
unit = deg - ZFromS(sign);
sign = Mod12(sign + 4*((int)RFloor(unit/10.0)));
unit = (unit - RFloor(unit/10.0)*10.0)*3.0;
return ZFromS(sign)+unit;
}
// Given a zodiac degree, transform it into its Dwad sign, in which each
// sign is divided into twelfths, starting with its own sign. For example:
// 15 Aries -> 0 Libra, 10 Leo -> 0 Sagittarius, 20 Sagittarius -> 0 Leo.
real Dwad(real deg)
{
int sign;
real unit;
sign = SFromZ(deg);
unit = deg - ZFromS(sign);
sign = Mod12(sign + ((int)RFloor(unit/2.5)));
unit = (unit - RFloor(unit/2.5)*2.5)*12.0;
return ZFromS(sign)+unit;
}
// Given a zodiac degree, transform it into its Navamsa position, in which
// each sign is divided into ninths, which determines the number of signs
// after a base element sign to use. Degrees within signs are unaffected.
real Navamsa(real deg)
{
int sign, sign2;
real unit;
sign = SFromZ(deg);
unit = deg - ZFromS(sign);
sign2 = Mod12(((sign-1 & 3)^(2*FOdd(sign-1)))*3 + (int)(unit*0.3) + 1);
return ZFromS(sign2) + unit;
}
CONST int rgnTermEgypt[cSign*2] = {
0x66855, 0x64357, 0x86853, 0x43675, 0x66576, 0x36457, 0x76584, 0x54367,
0x65766, 0x64735, 0x7a472, 0x34657, 0x68772, 0x73645, 0x74856, 0x54367,
0xc5454, 0x64375, 0x77844, 0x36475, 0x76755, 0x34657, 0xc4392, 0x46357};
CONST int rgnTermPtolemy[cSign*2] = {
0x68754, 0x64357, 0x87744, 0x43675, 0x77745, 0x36475, 0x67773, 0x56347,
0x67665, 0x73465, 0x76566, 0x34675, 0x65856, 0x74635, 0x68763, 0x56437,
0x86565, 0x64375, 0x66765, 0x43657, 0x66855, 0x73465, 0x86664, 0x46357};
// Return the planet associated with a degree of the zodiac. Can do decan
// rulerships, Chaldean decans, Egyptian terms, or Ptolemaic terms.
int ObjTerm(real pos, int nType)
{
CONST int *rgRules, *rgTerm;
int sig = SFromZ(pos) - 1, deg, i, d = 0, n;
if (nType <= 0) {
if (ignore7[rrStd] && ignore7[rrEso] && !ignore7[rrHie])
rgRules = rgSignHie1;
else if (ignore7[rrStd] && !ignore7[rrEso])
rgRules = rgSignEso1;
else
rgRules = rules;
return rgRules[SFromZ(Decan(pos))];
} else if (nType == 1) {
n = ((int)pos)/10%7;
return (0x5143276 >> (6-n)*4) & 15;
} else if (nType >= 2) {
rgTerm = (nType == 2 ? rgnTermEgypt : rgnTermPtolemy);
deg = (int)pos - sig*30;
for (i = 0; i < 5; i++) {
n = (rgTerm[sig*2] >> (4-i)*4) & 15;
d += n;
if (deg < d)
return (rgTerm[sig*2+1] >> (4-i)*4) & 15;
}
Assert(fFalse);
}
return 0;
}
// Transform rectangular coordinates in x, y to polar coordinates.
void RecToPol(real x, real y, real *a, real *r)
{
*r = RLength2(x, y);
*a = RAngle(x, y);
}
// Transform spherical to rectangular coordinates in x, y, z.
void SphToRec(real r, real azi, real alt, real *rx, real *ry, real *rz)
{
real rT;
*rz = r *RSinD(alt);
rT = r *RCosD(alt);
*rx = rT*RCosD(azi);
*ry = rT*RSinD(azi);
}
// Convert 3D rectangular to spherical coordinates.
void RecToSph3(real rx, real ry, real rz, real *azi, real *alt)
{
real ang, rad;
RecToPol(rx, ry, &ang, &rad);
*azi = DFromR(ang);
ang = RAngleD(rad, rz);
// Ensure latitude is from -90 to +90 degrees.
if (ang > rDegHalf)
ang -= rDegMax;
*alt = ang;
}
// Do a coordinate transformation: Given a longitude and latitude value,
// return the new longitude and latitude values that the same location would
// have, were the equator tilted by a specified number of degrees. In other
// words, do a pole shift! This is used to convert among ecliptic, equatorial,
// and local coordinates, each of which have zero declination in different
// planes. In other words, take into account the Earth's axis.
void CoorXform(real *azi, real *alt, real tilt)
{
real x, y, a1, l1;
real sinalt, cosalt, sinazi, sintilt, costilt;
*azi = RFromD(*azi); *alt = RFromD(*alt); tilt = RFromD(tilt);
sinalt = RSin(*alt); cosalt = RCos(*alt); sinazi = RSin(*azi);
sintilt = RSin(tilt); costilt = RCos(tilt);
x = cosalt * sinazi * costilt - sinalt * sintilt;
y = cosalt * RCos(*azi);
l1 = RAngle(y, x);
a1 = cosalt * sinazi * sintilt + sinalt * costilt;
a1 = RAsin(a1);
*azi = DFromR(l1); *alt = DFromR(a1);
}
// Fast version of CoorXForm() in which the slow trigonometry values have
// already been computed. Useful when doing many transforms in a row.
void CoorXformFast(real *azi, real *alt, real sinazi, real cosazi,
real sinalt, real cosalt, real sintilt, real costilt)
{
real x, y, a1, l1;
x = cosalt * sinazi * costilt - sinalt * sintilt;
y = cosalt * cosazi;
l1 = RAngle(y, x);
a1 = cosalt * sinazi * sintilt + sinalt * costilt;
a1 = RAsin(a1);
*azi = DFromR(l1); *alt = DFromR(a1);
}
// Another subprocedure of the ComputeEphem() routine. Convert the final
// rectangular coordinates of a planet to zodiac position and latitude.
void ProcessPlanet(int ind, real aber)
{
real ang, rad;
RecToPol(space[ind].x, space[ind].y, &ang, &rad);
planet[ind] = Mod(DFromR(ang) - aber + is.rSid);
RecToPol(rad, space[ind].z, &ang, &rad);
if (us.objCenter == oSun && ind == oSun)
ang = 0.0;
ang = DFromR(ang);
// Ensure latitude is from -90 to +90 degrees.
while (ang > rDegQuad)
ang -= rDegHalf;
while (ang < -rDegQuad)
ang += rDegHalf;
planetalt[ind] = ang;
}
#ifdef EPHEM
#ifdef JPLWEB
CONST int rgObjJPL[cThing+1] = {0/*399*/, 10, 301,
199, 299, 499, 599, 699, 799, 899, 999, nMillion + 2060,
nMillion + 1, nMillion + 2, nMillion + 3, nMillion + 4, 0, 0, 0};
#define FJPL(f) (f)
#else
#define FJPL(f) fFalse
#endif
// Compute the positions of the planets at a certain time using the Swiss
// Ephemeris accurate formulas. This will supersede the Matrix routine values
// and is only called when the -b switch is in effect. Not all objects or
// modes are available using this, but some additional values such as Moon and
// Node velocities not available without -b are. (This is the main place in
// Astrolog which calls the Swiss Ephemeris functions.)
void ComputeEphem(real t)
{
int objCentCalc, objOrbit, imax, i, j;
real r1, r2, r3, r4, r5, r6, dist1, dist2, objPla, altPla, objEar, altEar,
rT;
flag fSwiss = !us.fPlacalcPla, fJPLPla, fJPL, fRet;
PT3R ptPla, ptEar, vEar;
#ifdef JPLWEB
flag fSav;
#endif
// Can compute the positions of Sun through Pluto, Chiron, the four
// asteroids, Lilith, North Node, and Uranians using ephemeris files.
fJPLPla = fSwiss && us.nSwissEph == 3;
objCentCalc = us.objCenter;
if (objCentCalc > oNorm || FNodal(objCentCalc) ||
(!fSwiss && objCentCalc != oEar) || (fJPLPla && us.objCenter > oSun) ||
FJPL(FCust(objCentCalc) && rgTypSwiss[objCentCalc - custLo] == 4))
objCentCalc = oSun;
imax = Min(oNorm, is.nObj); imax = Max(imax, oSun);
for (i = oEar; i <= imax; i++) {
if ((ignore[i] && i > oMoo && (i != oNod || ignore[oSou])) ||
!FThing(i) ||
(i == objCentCalc && !fJPLPla &&
!(fSwiss && objCentCalc == oEar && us.fBarycenter)) ||
(!fSwiss && (i >= oFor ||
(us.fPlacalcAst && FBetween(i, oCer, oVes)))) ||
(fJPLPla && i == oEar))
continue;
// Calculate planet using Swiss Ephemeris, Placalc, or JPL Horizons
fRet = fFalse;
fJPL = FJPL((FCust(i) && rgTypSwiss[i - custLo] == 4) ||
(fJPLPla && FBetween(i, 0, cThing) && rgObjJPL[i] > 0));
#ifdef JPLWEB
if (fJPL) {
fSav = us.fTruePos;
if (us.objCenter != oEar)
us.fTruePos = fTrue;
j = FCust(i) ? rgObjSwiss[i - custLo] :
(i == oSun && us.fBarycenter ? 0 : rgObjJPL[i]);
fRet = GetJPLHorizons(j, &r1, &r2, &r3, &r4, &r5, &r6, NULL);
us.fTruePos = fSav;
} else
#endif
{
#ifdef SWISS
if (fSwiss) {
objOrbit = us.fMoonMove ? ObjOrbit(i) : -1;
if (objOrbit < 0 || objOrbit == oSun)
objOrbit = objCentCalc;
fRet = FSwissPlanet(i, JulianDayFromTime(t), objOrbit,
&r1, &r2, &r3, &r4, &r5, &r6);
}
#endif
#ifdef PLACALC
if (!fSwiss)
fRet = FPlacalcPlanet(i, JulianDayFromTime(t), objCentCalc != oEar,
&r1, &r2, &r3, &r4, &r5, &r6);
#endif
}
if (!fRet)
continue;
// Store positions and velocities in object array.
planet[i] = Mod(r1 + is.rSid);
planetalt[i] = r2;
ret[i] = r3;