-
Notifications
You must be signed in to change notification settings - Fork 0
/
calc.cpp
executable file
·1678 lines (1423 loc) · 53.7 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 6.40) File: calc.cpp
**
** IMPORTANT NOTICE: Astrolog and all chart display routines and anything
** not enumerated below used in this program are Copyright (C) 1991-2018 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. The use of that source code is subject to the license for
** Swiss Ephemeris Free Edition, available at http://www.astro.com/swisseph.
** 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.
**
** 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 7/22/2018.
*/
#include "astrolog.h"
/*
******************************************************************************
** House Cusp Calculations.
******************************************************************************
*/
/* 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 HousePlaceIn(real rLon, real rLat)
{
int i, di;
if (us.fHouse3D) {
i = SFromZ(HousePlaceIn3D(rLon, rLat));
return i;
}
/* 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;
}
/* 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 HousePlaceIn3D(real rLon, real rLat)
{
real lonM, latM, lon, lat;
lonM = Tropical(is.MC); latM = 0.0;
EclToEqu(&lonM, &latM);
lon = Tropical(rLon); lat = rLat;
EclToEqu(&lon, &lat);
lon = Mod(lonM - lon + rDegQuad);
EquToLocal(&lon, &lat, -Lat);
lon = rDegMax - lon;
return Mod(lon + rSmall);
}
/* For each object in the chart, determine what house it belongs in. */
void ComputeInHouses(void)
{
int i;
for (i = 0; i <= cObj; i++)
inhouse[i] = HousePlaceIn(planet[i], planetalt[i]);
if (us.fHouse3D) {
/* 3D Campanus cusps should always be in the corresponding house. */
if (us.nHouseSystem == hsCampanus) {
for (i = cuspLo; i <= cuspHi; i++)
inhouse[i] = i - cuspLo + 1;
/* 3D angles should always be in the corresponding house. */
} else if (us.fHouseAngle) {
for (i = cuspLo; i <= cuspHi; i += 3)
inhouse[i] = i - cuspLo + 1;
}
}
}
/* This house system is just like the Equal system except that we start */
/* our 12 equal segments from the Midheaven instead of the Ascendant. */
void HouseEqualMidheaven(void)
{
int i;
for (i = 1; i <= cSign; i++)
chouse[i] = Mod(is.MC-270.0+30.0*(real)(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] = DFromR(is.RA) - rSna;
chouse[sSco] = DFromR(is.RA) - rSna*2.0/3.0;
chouse[sSag] = DFromR(is.RA) - rSna/3.0;
chouse[sCap] = DFromR(is.RA);
chouse[sAqu] = DFromR(is.RA) + rSda/3.0;
chouse[sPis] = DFromR(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, we 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(void)
{
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, is.Asc);
rDelta = (rQuad - rDegQuad)/4.0;
chouse[sLib] = Mod(is.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], is.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(void)
{
real qSmall, rRatio, rRatio3, rRatio4, xHouse, rLo, rHi;
int iHouse, dir;
/* Start by determining the quadrant sizes. */
qSmall = MinDistance(is.MC, is.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] = is.Asc; chouse[sCap] = is.MC;
chouse[sLib] = Mod(is.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);
}
/* 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. */
void HouseWhole(void)
{
int i;
for (i = 1; i <= cSign; i++)
chouse[i] = Mod((real)((SFromZ(is.Asc)-1)*30) + ZFromS(i));
}
/* 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 iHouse;
real rgr[cSign+1], rQuad;
rgr[sAri] = is.Asc; rgr[sCap] = is.MC;
rQuad = MinDistance(is.Asc, is.MC);
rgr[sAqu] = Mod(is.MC + rQuad/3.0);
rgr[sPis] = Mod(is.MC + rQuad*2.0/3.0);
rQuad = rDegHalf - rQuad;
rgr[sSag] = Mod(is.MC - rQuad/3.0);
rgr[sSco] = Mod(is.MC - rQuad*2.0/3.0);
for (iHouse = sTau; iHouse <= sLib; iHouse++)
rgr[iHouse] = Mod(rgr[Mod12(iHouse+6)] + rDegHalf);
for (iHouse = sAri; iHouse <= sPis; iHouse++)
chouse[iHouse] = Midpoint(rgr[iHouse], rgr[Mod12(iHouse-1)]);
}
/* 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. */
void HouseVedic(void)
{
int i;
for (i = 1; i <= cSign; i++)
chouse[i] = Mod(is.Asc - 15.0 + ZFromS(i));
}
/* 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. */
void HouseNull()
{
int i;
for (i = 1; i <= cSign; i++)
chouse[i] = ZFromS(i);
}
/* 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];
/* 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);
}
switch (housesystem) {
#ifdef MATRIX
case hsPlacidus: HousePlacidus(); break;
case hsKoch: HouseKoch(); break;
case hsEqual: HouseEqual(); break;
case hsCampanus: HouseCampanus(); break;
case hsMeridian: HouseMeridian(); break;
case hsRegiomontanus: HouseRegiomontanus(); break;
case hsPorphyry: HousePorphyry(); break;
case hsMorinus: HouseMorinus(); break;
case hsTopocentric: HouseTopocentric(); break;
#endif
case hsAlcabitius: HouseAlcabitius(); break;
case hsEqualMC: HouseEqualMidheaven(); break;
case hsSinewaveRatio: HousePullenSinusoidalRatio(); break;
case hsSinewaveDelta: HousePullenSinusoidalDelta(); break;
case hsWhole: HouseWhole(); break;
case hsVedic: HouseVedic(); break;
case hsSripati: HouseSripati(); break;
default: HouseNull(); break;
}
}
/*
******************************************************************************
** Star Position Calculations.
******************************************************************************
*/
/* This is used by the chart calculation routine to calculate the positions */
/* of the fixed stars. Since the stars don't move 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, we have to add */
/* in the correct precession for the tropical zodiac, and sort the final */
/* index list based on what order the stars are supposed to be printed in. */
void ComputeStars(real t, real Off)
{
int i, j;
#ifdef MATRIX
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] = rDegMax/25765.0/rDayInYear;
starname[i] = i;
}
#endif
}
/* Sort the index list if -Uz, -Ul, -Un, or -Ub switch in effect. */
if (us.nStar > 1) for (i = 2; i <= cStar; i++) {
j = i-1;
/* Compare star names for -Un switch. */
if (us.nStar == 'n') while (j > 0 && NCompareSz(
szObjDisp[oNorm+starname[j]], szObjDisp[oNorm+starname[j+1]]) > 0) {
SwapN(starname[j], starname[j+1]);
j--;
/* Compare star brightnesses for -Ub switch. */
} else if (us.nStar == 'b') while (j > 0 &&
rStarBright[starname[j]] > rStarBright[starname[j+1]]) {
SwapN(starname[j], starname[j+1]);
j--;
/* Compare star zodiac locations for -Uz switch. */
} else if (us.nStar == 'z') while (j > 0 &&
planet[oNorm+starname[j]] > planet[oNorm+starname[j+1]]) {
SwapN(starname[j], starname[j+1]);
j--;
/* Compare star declinations for -Ul switch. */
} else if (us.nStar == 'l') while (j > 0 &&
planetalt[oNorm+starname[j]] < planetalt[oNorm+starname[j+1]]) {
SwapN(starname[j], starname[j+1]);
j--;
}
}
}
/*
******************************************************************************
** Chart Calculation.
******************************************************************************
*/
/* Given a zodiac degree, transform it into its Decan sign, where 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, where */
/* 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;
}
/* Transform rectangular coordinates in x, y to polar coordinates. */
void RecToPol(real x, real y, real *a, real *r)
{
*r = RSqr(x*x + y*y);
*a = Angle(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);
}
/* Another subprocedure of the ComputeEphem() routine. Convert the final */
/* rectangular coordinates of a planet to zodiac position and declination. */
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);
while (ang > rDegQuad) /* Ensure declination is from -90..+90 degrees. */
ang -= rDegHalf;
while (ang < -rDegQuad)
ang += rDegHalf;
planetalt[ind] = ang;
}
#ifdef EPHEM
/* 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 i;
real r1, r2, r3, r4;
/* We can compute the positions of Sun through Pluto, Chiron, the four */
/* asteroids, Lilith, and the North Node using ephemeris files. */
for (i = oSun; i <= uranHi; i++) {
if ((ignore[i] &&
i != us.objCenter && i > oMoo && (i != oNod || ignore[oSou])) ||
FBetween(i, oFor, cuspHi) ||
(us.fPlacalcPla && i >= oFor) ||
(us.fPlacalcAst && FBetween(i, oCer, oVes)))
continue;
if (
#ifdef EPHEM2
!us.fPlacalcPla ?
#endif
#ifdef SWISS
FSwissPlanet(i, JulianDayFromTime(t), us.objCenter != oEar,
&r1, &r2, &r3, &r4)
#endif
#ifdef EPHEM2
:
#endif
#ifdef PLACALC
FPlacalcPlanet(i, JulianDayFromTime(t), us.objCenter != oEar,
&r1, &r2, &r3, &r4)
#endif
) {
planet[i] = Mod(r1 + is.rSid);
planetalt[i] = r2;
ret[i] = r3;
if (us.fVelocity && i <= oLil)
ret[i] /= (rDegMax / (rObjYear[i == oSun ? oEar : i] * rDayInYear));
} else
r4 = 0.0;
/* Compute x,y,z coordinates from azimuth, altitude, and distance. */
SphToRec(r4, planet[i], planetalt[i],
&space[i].x, &space[i].y, &space[i].z);
}
/* If heliocentric, move Earth position to object slot zero. */
if (!ignore[oSou]) {
space[oSou].x = -space[oNod].x;
space[oSou].y = -space[oNod].y;
space[oSou].z = -space[oNod].z;
ret[oSou] = ret[oNod];
}
if (us.objCenter == oEar) {
if (us.fBarycenter) {
space[oSun].x = -space[oSun].x;
space[oSun].y = -space[oSun].y;
space[oSun].z = -space[oSun].z;
planet[oSun] = Mod(planet[oSun] + rDegHalf);
planetalt[oSun] = -planetalt[oSun];
}
return;
}
planet[oEar] = planet[oSun];
planetalt[oEar] = planetalt[oSun];
ret[oEar] = ret[oSun];
space[oEar] = space[oSun];
planet[oSun] = planetalt[oSun] =
space[oSun].x = space[oSun].y = space[oSun].z = 0.0;
for (i = oNod; i <= oLil; i++) if (!ignore[i]) {
space[i].x += space[oEar].x;
space[i].y += space[oEar].y;
space[i].z += space[oEar].z;
}
if (us.objCenter == oSun)
return;
/* If other planet centered, shift all positions by central planet. */
for (i = 0; i <= oNorm; i++) if (!ignore[i] && i != us.objCenter) {
space[i].x -= space[us.objCenter].x;
space[i].y -= space[us.objCenter].y;
space[i].z -= space[us.objCenter].z;
ProcessPlanet(i, 0.0);
}
planet[us.objCenter] = planetalt[us.objCenter] = space[us.objCenter].x =
space[us.objCenter].y = space[us.objCenter].z = 0.0;
}
#endif
/* This is probably the main routine in all of Astrolog. It generates a */
/* chart, calculating the positions of all the celestial bodies and house */
/* cusps, based on the current chart information, and saves them for use */
/* by any of the display routines. */
real CastChart(flag fDate)
{
CI ciSav;
real housetemp[cSign+1], Off = 0.0, vtx = 0.0, ep = 0.0, j;
int i, k, k2;
/* Hack: Time zone 24 means to have the time of day be in Local Mean */
/* Time (LMT). This is done by making the time zone value reflect the */
/* logical offset from UTC as indicated by the chart's longitude value. */
ciSav = ciCore;
if (ZZ == zonLMT)
ZZ = OO / 15.0;
if (SS == dstAuto)
SS = (real)is.fDst;
if (FNoTimeOrSpace(ciCore)) {
/* Hack: If month is negative, then know chart was read in through a */
/* -o0 position file, so planet positions are already in the arrays. */
is.MC = planet[oMC]; is.Asc = planet[oAsc];
} else {
ClearB((lpbyte)&cp0, sizeof(CP)); /* On ecliptic unless we say so. */
ClearB((lpbyte)space, (oNorm+1)*sizeof(PT3R));
TT = RSgn(TT)*RFloor(RAbs(TT))+RFract(RAbs(TT)) + (ZZ - SS);
AA = Min(AA, rDegQuad-rSmall); /* Make sure chart isn't being cast */
AA = Max(AA, -(rDegQuad-rSmall)); /* on precise North or South Pole. */
/* if parameter 'fDate' isn't set, then we can assume that the true time */
/* has already been determined (as in a -rm switch time midpoint chart). */
if (fDate) {
is.JD = (real)MdyToJulian(MM, DD, YY);
is.T = (is.JD + TT/24.0);
if (us.fProgress && !us.fSolarArc) {
/* Determine actual time that a progressed chart is to be cast for. */
is.T += ((is.JDp - is.T) / us.rProgDay);
}
is.T = (is.T - 2415020.5) / 36525.0;
}
#ifdef SWISS
if (FCmSwissAny()) {
SwissHouse(is.T, OO, AA, us.nHouseSystem,
&is.Asc, &is.MC, &is.RA, &vtx, &ep, &is.OB, &Off);
} else
#endif
{
#ifdef MATRIX
Off = ProcessInput(fDate);
ComputeVariables(&vtx);
if (us.fGeodetic) /* Check for -G geodetic chart. */
is.RA = RFromD(Mod(-OO));
is.MC = CuspMidheaven(); /* Calculate Ascendant & Midheaven. */
is.Asc = CuspAscendant();
ep = CuspEastPoint();
ComputeHouses(us.nHouseSystem); /* Go calculate house cusps. */
#endif
}
#ifdef MATRIX
/* Go calculate planet, Moon, and North Node positions. */
if (FCmMatrix() || (FCmPlacalc() && us.fUranian)) {
ComputePlanets();
if (!ignore[oMoo] || !ignore[oNod] || !ignore[oSou] || !ignore[oFor]) {
ComputeLunar(&planet[oMoo], &planetalt[oMoo],
&planet[oNod], &planetalt[oNod]);
ret[oNod] = -1.0;
}
}
#endif
#ifdef EPHEM
/* Compute more accurate ephemeris positions for certain objects. */
if (us.fEphemFiles)
ComputeEphem(is.T);
#endif
/* Certain objects are positioned directly opposite to other objects. */
i = us.objCenter == oEar ? oSun : oEar;
planet[us.objCenter] = Mod(planet[i]+rDegHalf);
planetalt[us.objCenter] = -planetalt[i];
ret[us.objCenter] = ret[i];
planet[oSou] = Mod(planet[oNod]+rDegHalf);
if (!us.fEphemFiles) {
if (!us.fVelocity) {
ret[oNod] = ret[oSou] = -0.053;
ret[oMoo] = 12.2;
} else
ret[oNod] = ret[oSou] = ret[oMoo] = 1.0;
}
/* Calculate position of Part of Fortune. */
if (!ignore[oFor]) {
j = planet[oMoo]-planet[oSun];
if (us.nArabicNight < 0 || (us.nArabicNight == 0 &&
HousePlaceIn(planet[oSun], planetalt[oSun]) < sLib))
neg(j);
j = RAbs(j) < rDegQuad ? j : j - RSgn(j)*rDegMax;
planet[oFor] = Mod(j+is.Asc);
}
/* Fill in "planet" positions corresponding to house cusps. */
planet[oVtx] = vtx; planet[oEP] = ep;
for (i = 1; i <= cSign; i++)
planet[cuspLo + i - 1] = chouse[i];
if (!us.fHouseAngle) {
planet[oAsc] = is.Asc; planet[oMC] = is.MC;
planet[oDes] = Mod(is.Asc + rDegHalf);
planet[oNad] = Mod(is.MC + rDegHalf);
}
for (i = oFor; i <= cuspHi; i++)
ret[i] = rDegMax;
}
/* Go calculate star positions if -U switch in effect. */
if (us.nStar)
ComputeStars(is.T, (us.fSidereal ? 0.0 : -Off) + us.rZodiacOffset);
/* Transform ecliptic to equatorial coordinates if -sr in effect. */
if (us.fEquator)
for (i = 0; i <= cObj; i++) if (!ignore[i]) {
planet[i] = Tropical(planet[i]);
EclToEqu(&planet[i], &planetalt[i]);
}
/* Now, we may have to modify the base positions we calculated above */
/* based on what type of chart we are generating. */
if (us.fProgress && us.fSolarArc) { /* Are we doing -p0 solar arc chart? */
j = (is.JDp - JulianDayFromTime(is.T) - 0.5) / us.rProgDay;
for (i = 0; i <= cObj; i++)
planet[i] = Mod(planet[i] + j);
for (i = 1; i <= cSign; i++)
chouse[i] = Mod(chouse[i] + j);
}
if (us.rHarmonic != 1.0) /* Are we doing a -x harmonic chart? */
for (i = 0; i <= cObj; i++)
planet[i] = Mod(planet[i] * us.rHarmonic);
/* If -Y1 chart rotation in effect, then rotate the planets accordingly. */
if (us.objRot1 != us.objRot2 || us.fObjRotWhole) {
j = planet[us.objRot2];
if (us.fObjRotWhole)
j = (real)((SFromZ(j)-1)*30);
j -= planet[us.objRot1];
for (i = 0; i <= cObj; i++)
planet[i] = Mod(planet[i] + j);
}
/* If -1 or -2 solar chart in effect, then rotate the houses accordingly. */
if (us.objOnAsc) {
j = planet[NAbs(us.objOnAsc)-1];
if (us.fSolarWhole)
j = (real)((SFromZ(j)-1)*30);
j -= (us.objOnAsc > 0 ? is.Asc : is.MC);
for (i = 1; i <= cSign; i++)
chouse[i] = Mod(chouse[i]+j+rSmall);
}
/* Check to see if we are -F forcing any objects to be particular values. */
for (i = 0; i <= cObj; i++)
if (force[i] != 0.0) {
if (force[i] > 0.0) {
/* Force to a specific zodiac position. */
planet[i] = force[i]-rDegMax;
planetalt[i] = ret[i] = 0.0;
} else {
/* Force to a midpoint of two other positions. */
k = (-(int)force[i])-1;
k2 = k % cObj; k /= cObj;
planet[i] = Midpoint(planet[k], planet[k2]);
planetalt[i] = (planetalt[k] + planetalt[k2]) / 2.0;
ret[i] = (ret[k] + ret[k2]) / 2.0;
}
}
/* If -f domal chart switch in effect, switch planet and house positions. */
if (us.fFlip) {
ComputeInHouses();
for (i = 0; i <= cObj; i++) {
k = inhouse[i];
inhouse[i] = SFromZ(planet[i]);
planet[i] = ZFromS(k)+MinDistance(chouse[k], planet[i]) /
MinDistance(chouse[k], chouse[Mod12(k+1)])*30.0;
}
for (i = 1; i <= cSign; i++) {
k = HousePlaceIn2D(ZFromS(i));
housetemp[i] = ZFromS(k)+MinDistance(chouse[k], ZFromS(i)) /
MinDistance(chouse[k], chouse[Mod12(k+1)])*30.0;
}
for (i = 1; i <= cSign; i++)
chouse[i] = housetemp[i];
}
/* If -3 decan chart switch in effect, edit planet positions accordingly. */
if (us.fDecan)
for (i = 0; i <= cObj; i++)
planet[i] = Decan(planet[i]);
/* If -4 dwad chart switch in effect, edit planet positions accordingly. */
if (us.nDwad > 0)
for (k = 0; k < us.nDwad; k++)
for (i = 0; i <= cObj; i++)
planet[i] = Dwad(planet[i]);
/* If -9 navamsa chart switch in effect, edit positions accordingly. */
if (us.fNavamsa)
for (i = 0; i <= cObj; i++)
planet[i] = Navamsa(planet[i]);
ComputeInHouses(); /* Figure out what house everything falls in. */
ciCore = ciSav;
return is.T;
}
/* Calculate the position of each planet with respect to the Gauquelin */
/* sectors. This is used by the sector charts. Fill out the planet position */
/* array where one degree means 1/10 the way across one of the 36 sectors. */
void CastSectors()
{
int source[MAXINDAY], type[MAXINDAY], occurcount, division, div,
i, j, s1, s2, ihouse, fT;
real time[MAXINDAY], rgalt1[objMax], rgalt2[objMax],
azi1, azi2, alt1, alt2, mc1, mc2, d, k;
/* If the -l0 approximate sectors flag is set, we can quickly get rough */
/* positions by having each position be the location of the planet as */
/* mapped into Placidus houses. The -f flip houses flag does this for us. */
if (us.fSectorApprox) {
ihouse = us.nHouseSystem; us.nHouseSystem = hsPlacidus;
inv(us.fFlip);
CastChart(fTrue);
inv(us.fFlip);
us.nHouseSystem = ihouse;
return;
}
/* If not approximating sectors, then they need to be computed the formal */
/* way: based on a planet's nearest rising and setting times. The code */
/* below is similar to ChartInDayHorizon() accessed by the -Zd switch. */
fT = us.fSidereal; us.fSidereal = fFalse;
division = us.nDivision * 4;
occurcount = 0;
/* Start scanning from 18 hours before to 18 hours after the time of the */
/* chart in question, to find the closest rising and setting times. */
ciCore = ciMain; ciCore.tim -= 18.0;
if (ciCore.tim < 0.0) {
ciCore.tim += 24.0;
ciCore.day--;
}
CastChart(fTrue);
mc2 = planet[oMC]; k = planetalt[oMC];
EclToEqu(&mc2, &k);
cp2 = cp0;
for (i = 0; i <= cObj; i++)
rgalt2[i] = planetalt[i];
/* Loop through 36 hours, dividing it into a certain number of segments. */
/* For each segment we get the planet positions at its endpoints. */
for (div = 1; div <= division; div++) {
ciCore = ciMain;
ciCore.tim = ciCore.tim - 18.0 + 36.0*(real)div/(real)division;
if (ciCore.tim < 0.0) {
ciCore.tim += 24.0;
ciCore.day--;
} else if (ciCore.tim >= 24.0) {
ciCore.tim -= 24.0;
ciCore.day++;
}
CastChart(fTrue);
mc1 = mc2;
mc2 = planet[oMC]; k = planetalt[oMC];
EclToEqu(&mc2, &k);
cp1 = cp2; cp2 = cp0;
for (i = 1; i <= cObj; i++) {
rgalt1[i] = rgalt2[i]; rgalt2[i] = planetalt[i];
}
/* During our segment, check to see if each planet rises or sets. */
for (i = 0; i <= cObj; i++) if (!FIgnore(i) && FThing(i)) {
EclToHorizon(&azi1, &alt1, cp1.obj[i], rgalt1[i], mc1, Lat);
EclToHorizon(&azi2, &alt2, cp2.obj[i], rgalt2[i], mc2, Lat);
j = 0;
if ((alt1 > 0.0) != (alt2 > 0.0)) {
d = RAbs(alt1)/(RAbs(alt1)+RAbs(alt2));
k = Mod(azi1 + d*MinDifference(azi1, azi2));
j = 1 + (MinDistance(k, rDegHalf) < rDegQuad);
}
if (j && occurcount < MAXINDAY) {
source[occurcount] = i;
type[occurcount] = j;
time[occurcount] = 36.0*((real)(div-1)+d)/(real)division*60.0;
occurcount++;
}
}
}
/* Sort each event in order of time when it happens during the day. */
for (i = 1; i < occurcount; i++) {
j = i-1;
while (j >= 0 && time[j] > time[j+1]) {
SwapN(source[j], source[j+1]);
SwapN(type[j], type[j+1]);
SwapR(&time[j], &time[j+1]);
j--;
}
}
/* Now fill out the planet array with the appropriate sector location. */
for (i = 0; i <= cObj; i++) if (!ignore[i] && FThing(i)) {