@@ -5,19 +5,19 @@ import io.github.cosinekitty.astronomy.Aberration
55import io.github.cosinekitty.astronomy.Body
66import io.github.cosinekitty.astronomy.EquatorEpoch
77import io.github.cosinekitty.astronomy.Observer
8+ import io.github.cosinekitty.astronomy.Refraction
89import io.github.cosinekitty.astronomy.Time
910import io.github.cosinekitty.astronomy.equator
10- import io.github.cosinekitty.astronomy.hourAngle
11+ import io.github.cosinekitty.astronomy.horizon
1112import io.github.cosinekitty.astronomy.illumination
1213import io.github.cosinekitty.astronomy.moonPhase
14+ import io.github.cosinekitty.astronomy.rotationEqdHor
1315import io.github.cosinekitty.astronomy.searchMoonPhase
1416import java.time.ZoneId
1517import java.time.ZoneOffset
1618import java.time.ZonedDateTime
1719import kotlin.math.atan2
18- import kotlin.math.cos
1920import kotlin.math.roundToInt
20- import kotlin.math.sin
2121
2222private const val PHASE_SEARCH_DAYS = 35.0
2323
@@ -51,23 +51,15 @@ class MoonCalculator(
5151 val observer = Observer (latitude, longitude, 0.0 )
5252 val moon = equator(Body .Moon , time, observer, EquatorEpoch .OfDate , Aberration .Corrected )
5353 val sun = equator(Body .Sun , time, observer, EquatorEpoch .OfDate , Aberration .Corrected )
54- val deltaRa = Math .toRadians((sun.ra - moon.ra) * 15.0 )
55- val moonDec = Math .toRadians(moon.dec)
56- val sunDec = Math .toRadians(sun.dec)
57- val brightLimbDeg = Math .toDegrees(atan2(
58- cos(sunDec) * sin(deltaRa),
59- sin(sunDec) * cos(moonDec) -
60- cos(sunDec) * sin(moonDec) * cos(deltaRa),
61- ))
54+ // Keep geometric coordinates: refraction would change the existing tilt.
55+ val moonHorizon = horizon(time, observer, moon.ra, moon.dec, Refraction .None )
6256
63- val hourAngleRad = Math .toRadians(hourAngle(Body .Moon , time, observer) * 15.0 )
64- val latitudeRad = Math .toRadians(latitude)
65- val parallacticAngleDeg = Math .toDegrees(atan2(
66- sin(hourAngleRad) * cos(latitudeRad),
67- sin(latitudeRad) * cos(moonDec) -
68- cos(latitudeRad) * sin(moonDec) * cos(hourAngleRad),
69- ))
70- val trueLimbDeg = - (brightLimbDeg - parallacticAngleDeg).toFloat()
57+ // Point the horizontal frame at the Moon: x toward it, y screen-left, z screen-up.
58+ val moonFrame = rotationEqdHor(time, observer)
59+ .pivot(2 , moonHorizon.azimuth)
60+ .pivot(1 , moonHorizon.altitude)
61+ val sunInMoonFrame = moonFrame.rotate(sun.vec)
62+ val trueLimbDeg = - Math .toDegrees(atan2(sunInMoonFrame.y, sunInMoonFrame.z)).toFloat()
7163
7264 // The base artwork (and the procedural line path) already draws the
7365 // illuminated limb at a canonical orientation: 90deg (right) when the
0 commit comments