Skip to content

error in calculating the parallactic angle of the moon bright limb in MoonPosition.swift #3

@djmlewis

Description

@djmlewis

There is an error in calculating the parallactic angle of the moon bright limb in MoonPosition.swift

In MoonPosition.swift line 88 the closing bracket for the atan2() function comes too early:

88 let pa = atan2(sin(h), tan(phi) * cos(mc.getTheta())) - sin(mc.getTheta()) * cos(h)

The atan2() closing bracket should come after the final cos(h), instead it comes after cos(mc.getTheta()))<== this bracket closes atan2()

This formula (based on formula 14.1 of "Astronomical Algorithms" 2nd edition by Jean Meeus (Willmann-Bell, Richmond) 1998) is correct in the original Javascript by mourner (who confusingly has abbreviated the atan2() function to "atan"):
https://github.com/mourner/suncalc/blob/master/suncalc.js

215 pa = atan(sin(H), tan(phi) * cos(c.dec) - sin(c.dec) * cos(H));

and in the Java translation by shred:
https://github.com/shred/commons-suncalc/blob/master/src/main/java/org/shredzone/commons/suncalc/MoonPosition.java

90 double pa = atan2(sin(h), tan(phi) * cos(mc.getTheta()) - sin(mc.getTheta()) * cos(h));

The pa calculation is omitted in the Swift translation by shanus on which many other Swift versions are based

https://github.com/shanus/suncalc-swift/blob/master/suncalc/suncalc.swift

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions