diff --git a/src/main/java/org/shredzone/commons/suncalc/MoonIllumination.java b/src/main/java/org/shredzone/commons/suncalc/MoonIllumination.java index f8b42ed..9bf9f7a 100644 --- a/src/main/java/org/shredzone/commons/suncalc/MoonIllumination.java +++ b/src/main/java/org/shredzone/commons/suncalc/MoonIllumination.java @@ -69,11 +69,15 @@ public MoonIllumination execute() { Vector m = Moon.position(t); double phi = PI - acos(m.dot(s) / (m.getR() * s.getR())); Vector sunMoon = m.cross(s); + double angle = atan2( + cos(s.getTheta()) * sin(s.getPhi() - m.getPhi()), + sin(s.getTheta()) * cos(m.getTheta()) - cos(s.getTheta()) * sin(m.getTheta()) * cos(s.getPhi() - m.getPhi()) + ); return new MoonIllumination( (1 + cos(phi)) / 2, toDegrees(phi * signum(sunMoon.getTheta())), - toDegrees(sunMoon.getTheta())); + toDegrees(angle)); } } diff --git a/src/test/java/org/shredzone/commons/suncalc/MoonIlluminationTest.java b/src/test/java/org/shredzone/commons/suncalc/MoonIlluminationTest.java index 96eb5bb..8617be4 100644 --- a/src/test/java/org/shredzone/commons/suncalc/MoonIlluminationTest.java +++ b/src/test/java/org/shredzone/commons/suncalc/MoonIlluminationTest.java @@ -35,7 +35,7 @@ public void testNewMoon() { .execute(); assertThat(mi.getFraction()).as("fraction").isCloseTo(0.0, ERROR); assertThat(mi.getPhase()).as("phase").isCloseTo(176.0, ERROR); // -180.0 - assertThat(mi.getAngle()).as("angle").isCloseTo(1.8, ERROR); + assertThat(mi.getAngle()).as("angle").isCloseTo(2.0, ERROR); assertThat(mi.getClosestPhase()).as("MoonPhase.Phase").isEqualTo(Phase.NEW_MOON); } @@ -59,7 +59,7 @@ public void testFullMoon() { .execute(); assertThat(mi.getFraction()).as("fraction").isCloseTo(1.0, ERROR); assertThat(mi.getPhase()).as("phase").isCloseTo(-3.2, ERROR); // 0.0 - assertThat(mi.getAngle()).as("angle").isCloseTo(-7.0, ERROR); + assertThat(mi.getAngle()).as("angle").isCloseTo(-7.4, ERROR); assertThat(mi.getClosestPhase()).as("MoonPhase.Phase").isEqualTo(Phase.FULL_MOON); } @@ -71,7 +71,7 @@ public void testWaningHalfMoon() { .execute(); assertThat(mi.getFraction()).as("fraction").isCloseTo(0.5, ERROR); assertThat(mi.getPhase()).as("phase").isCloseTo(90.0, ERROR); - assertThat(mi.getAngle()).as("angle").isCloseTo(68.1, ERROR); + assertThat(mi.getAngle()).as("angle").isCloseTo(68.7, ERROR); assertThat(mi.getClosestPhase()).as("MoonPhase.Phase").isEqualTo(Phase.LAST_QUARTER); }