Fix: times_rise_transit_set returns phantom rise/set at a grazing crossing#55
Merged
architest merged 1 commit intoJul 7, 2026
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The function that computes when a body rises, crosses the meridian, and sets starts with a good first guess for the setting time, then nudges it a couple of times to sharpen it. Each nudge divides by
sin(H), whereHis how far the body is from due south when it touches the horizon.For a normal setting
His a healthy angle and the nudge is small. But when a body only just barely dips to the horizon (a "grazing" set, common for the Moon seen from far-north latitudes),His almost zero, sosin(H)is almost zero, and dividing by it produces an enormous nudge. One nudge throws the estimate notminutes but days away. The next nudge is then computed from a point so far off that it makes things worse, and the function reports a moonset time like 389 hours (about 16 days) from the requested day, an event that does not exist.
A legitimate nudge can only ever move the guess within the same rise-to-set window, which is at most half a day wide. So any nudge bigger than half a day is not a real correction, it is the calculation breaking down.
Concrete example (Moon, year 13, 22 December, high northern latitude):
Before:
After:
The fix
Remember the original first guess. If a nudge would move the setting time by more than half a day, throw the nudge away, keep the first guess, and stop nudging that value.
The rising time and the setting time are handled separately, and the
meridian-crossing time (which never had this problem) is left alone. For every ordinary rise and set the nudges are tiny, well under the half-day limit, so nothing about the normal results changes.