Skip to content

Commit 7014ff0

Browse files
committed
Fix issue #6
1 parent 6569a43 commit 7014ff0

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/SolarCalculator.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ void calcRiseSetTimes(double (&m)[3], JulianDay jd, double latitude, double long
237237
double H0 = degrees(acos((sin(radians(h0)) - sin(radians(latitude)) * sin(radians(dec))) /
238238
(cos(radians(latitude)) * cos(radians(dec)))));
239239

240-
m[0] = wrapTo360(ra - longitude - GMST + jd.m * 360) / 360;
240+
m[0] = jd.m + wrapTo180(ra - longitude - GMST) / 360;
241241
m[1] = m[0] - H0 / 360;
242242
m[2] = m[0] + H0 / 360;
243243
}
@@ -250,20 +250,20 @@ void calcSunriseSunset(JulianDay jd, double latitude, double longitude,
250250
m[0] = 0.5 - longitude / 360;
251251

252252
for (int i = 0; i <= iterations; i++)
253-
{
254-
for (int j = 0; j < 3; j++)
253+
for (int event = 0; event < 3; event++)
255254
{
256-
jd.m = m[j];
255+
jd.m = m[event];
257256
calcRiseSetTimes(times, jd, latitude, longitude, altitude);
258-
m[j] = times[j];
257+
m[event] = times[event];
259258

260-
if (i == 0) // first iteration
259+
// First iteration, approximate rise and set times
260+
if (i == 0)
261261
{
262-
m[1] = times[1]; m[2] = times[2]; // approximate rise and set times
262+
m[1] = times[1];
263+
m[2] = times[2];
263264
break;
264265
}
265266
}
266-
}
267267

268268
transit = m[0] * 24;
269269
sunrise = m[1] * 24;

0 commit comments

Comments
 (0)