forked from sureshdr/mhora
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Balas.cs
283 lines (262 loc) · 7.54 KB
/
Balas.cs
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
/******
Copyright (C) 2005 Ajit Krishnan (http://www.mudgala.com)
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,
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
******/
using System;
using System.Diagnostics;
namespace mhora
{
/// <summary>
/// Summary description for Balas.
/// </summary>
public class ShadBalas
{
Horoscope h;
public ShadBalas(Horoscope _h)
{
h = _h;
}
private void verifyGraha (Body.Name b)
{
int _b = (int)b;
Debug.Assert(_b >= (int)Body.Name.Sun && _b <= (int)Body.Name.Saturn);
}
public double ucchaBala (Body.Name b)
{
this.verifyGraha(b);
Longitude debLon = Body.debilitationDegree (b);
Longitude posLon = h.getPosition(b).longitude;
double diff = posLon.sub(debLon).value;
if (diff > 180) diff = 360 - diff;
return ((diff / 180.0) * 60.0);
}
public bool getsOjaBala (Body.Name b)
{
switch (b)
{
case Body.Name.Moon:
case Body.Name.Venus:
return false;
default:
return true;
}
}
public double ojaYugmaHelper (Body.Name b, ZodiacHouse zh)
{
if (this.getsOjaBala(b))
{
if (zh.isOdd()) return 15.0;
else return 0.0;
}
else
{
if (zh.isOdd()) return 0.0;
else return 15.0;
}
}
public double ojaYugmaRasyAmsaBala (Body.Name b)
{
this.verifyGraha(b);
BodyPosition bp = h.getPosition(b);
ZodiacHouse zh_rasi = bp.toDivisionPosition(new Division(Basics.DivisionType.Rasi)).zodiac_house;
ZodiacHouse zh_amsa = bp.toDivisionPosition(new Division(Basics.DivisionType.Navamsa)).zodiac_house;
double s = 0;
s += this.ojaYugmaHelper(b, zh_rasi);
s += this.ojaYugmaHelper(b, zh_amsa);
return s;
}
public double kendraBala (Body.Name b)
{
this.verifyGraha(b);
ZodiacHouse zh_b = h.getPosition(b).toDivisionPosition(new Division(Basics.DivisionType.Rasi)).zodiac_house;
ZodiacHouse zh_l = h.getPosition(Body.Name.Lagna).toDivisionPosition(new Division(Basics.DivisionType.Rasi)).zodiac_house;
int diff = zh_l.numHousesBetween(zh_b);
switch (diff % 3)
{
case 1: return 60;
case 2: return 30.0;
case 0: default:
return 15.0;
}
}
public double drekkanaBala (Body.Name b)
{
this.verifyGraha(b);
int part = h.getPosition(b).partOfZodiacHouse(3);
if (part == 1 &&
(b == Body.Name.Sun || b == Body.Name.Jupiter || b == Body.Name.Mars))
return 15.0;
if (part == 2 &&
(b == Body.Name.Saturn || b == Body.Name.Mercury))
return 15.0;
if (part == 3 &&
(b == Body.Name.Moon || b == Body.Name.Venus))
return 15.0;
return 0;
}
public double digBala (Body.Name b)
{
this.verifyGraha(b);
int[] powerlessHouse = new int[] { 4, 10, 4, 7, 7, 10, 1 };
Longitude lagLon = h.getPosition(Body.Name.Lagna).longitude;
Longitude debLon = new Longitude(lagLon.toZodiacHouseBase());
debLon = debLon.add(powerlessHouse[(int)b]*30.0+15.0);
Longitude posLon = h.getPosition(b).longitude;
Console.WriteLine("digBala {0} {1} {2}", b, posLon.value, debLon.value);
double diff = posLon.sub(debLon).value;
if (diff > 180) diff = 360 - diff;
return ((diff / 180.0) * 60.0);
}
public double nathonnathaBala (Body.Name b)
{
this.verifyGraha(b);
if (b == Body.Name.Mercury) return 60;
double lmt_midnight = h.lmt_offset * 24.0;
double lmt_noon = 12.0 + h.lmt_offset * 24.0;
double diff = 0;
if (h.info.tob.time > lmt_noon)
diff = lmt_midnight - h.info.tob.time;
else
diff = h.info.tob.time - lmt_midnight;
while (diff < 0) diff += 12.0;
diff = diff / 12.0 * 60.0;
if (b == Body.Name.Moon || b == Body.Name.Mars ||
b == Body.Name.Saturn)
diff = 60-diff;
return diff;
}
public double pakshaBala (Body.Name b)
{
this.verifyGraha(b);
Longitude mlon = h.getPosition(Body.Name.Moon).longitude;
Longitude slon = h.getPosition(Body.Name.Sun).longitude;
double diff = mlon.sub(slon).value;
if (diff > 180) diff = 360.0 - diff;
double shubha = diff / 3.0;
double paapa = 60.0 - shubha;
switch (b)
{
case Body.Name.Sun:
case Body.Name.Mars:
case Body.Name.Saturn:
return paapa;
case Body.Name.Moon:
return shubha *2.0;
default:
case Body.Name.Mercury:
case Body.Name.Jupiter:
case Body.Name.Venus:
return shubha;
}
}
public double tribhaagaBala (Body.Name b)
{
Body.Name ret = Body.Name.Jupiter;
this.verifyGraha(b);
if (h.isDayBirth())
{
double length = (h.sunset - h.sunrise)/3;
double offset = h.info.tob.time - h.sunrise;
int part = (int)(Math.Floor(offset/length));
switch (part)
{
case 0: ret = Body.Name.Mercury; break;
case 1: ret = Body.Name.Sun; break;
case 2: ret = Body.Name.Saturn; break;
}
}
else
{
double length = (h.next_sunrise + 24.0 - h.sunset)/3;
double offset = h.info.tob.time - h.sunset;
if (offset < 0) offset += 24;
int part = (int)(Math.Floor(offset/length));
switch (part)
{
case 0: ret = Body.Name.Moon; break;
case 1: ret = Body.Name.Venus; break;
case 2: ret = Body.Name.Mars; break;
}
}
if (b == Body.Name.Jupiter || b == ret)
return 60;
return 0;
}
public double naisargikaBala (Body.Name b)
{
this.verifyGraha(b);
switch (b)
{
case Body.Name.Sun: return 60;
case Body.Name.Moon: return 51.43;
case Body.Name.Mars: return 17.14;
case Body.Name.Mercury: return 25.70;
case Body.Name.Jupiter: return 34.28;
case Body.Name.Venus: return 42.85;
case Body.Name.Saturn: return 8.57;
}
return 0;
}
public void kalaHelper (ref Body.Name yearLord, ref Body.Name monthLord)
{
double ut_arghana = sweph.swe_julday(1827, 5, 2, - h.info.tz.toDouble() + 12.0/24.0);
double ut_noon = h.baseUT - h.info.tob.time/24.0 + 12.0/24.0;
double diff = ut_noon - ut_arghana;
if (diff >= 0)
{
double quo = Math.Floor(diff/360.0);
diff -= quo * 360.0;
}
else
{
double pdiff = -diff;
double quo = Math.Ceiling(pdiff/360.0);
diff += quo * 360.0;
}
double diff_year = diff;
while (diff > 30.0) diff -= 30.0;
double diff_month = diff;
while (diff > 7) diff -= 7.0;
yearLord = Basics.weekdayRuler((Basics.Weekday)sweph.swe_day_of_week(ut_noon - diff_year));
monthLord = Basics.weekdayRuler((Basics.Weekday)sweph.swe_day_of_week(ut_noon - diff_month));
}
public double abdaBala (Body.Name b)
{
this.verifyGraha(b);
Body.Name yearLord=Body.Name.Sun, monthLord=Body.Name.Sun;
this.kalaHelper(ref yearLord, ref monthLord);
if (yearLord == b) return 15.0;
return 0.0;
}
public double masaBala (Body.Name b)
{
this.verifyGraha(b);
Body.Name yearLord=Body.Name.Sun, monthLord=Body.Name.Sun;
this.kalaHelper(ref yearLord, ref monthLord);
if (monthLord == b) return 30.0;
return 0.0;
}
public double varaBala (Body.Name b)
{
this.verifyGraha(b);
if (Basics.weekdayRuler(h.wday) == b) return 45.0;
return 0.0;
}
public double horaBala (Body.Name b)
{
this.verifyGraha(b);
if (h.calculateHora() == b) return 60.0;
return 0.0;
}
}
}