Skip to content

Moon tilt #2

Description

@furiosFast

Hi,
i've write this function for calculate the moon tilt illusion angle, according to this document: http://master.grad.hr/hdgg/kog_stranica/kog18/06myers-KoG18.pdf

static func moonTilt (date: NSDate, location: CLLocationCoordinate2D) -> (alfa: Double, beta: Double, diff: Double) {      

        let moonAltitude = moonPosition(date: date, location: location).altitude
        let moonAzimuth = moonPosition(date: date, location: location).azimuth
        let sunAltitude = sunPosition(date: date, location: location).altitude
        let sunAzimuth = sunPosition(date: date, location: location).azimuth

        let absAzimMoonSun = abs(sunAzimuth - moonAzimuth)
        let tanAlfa = ((cos(moonAltitude) * tan(sunAltitude)) - (sin(moonAltitude) * cos(absAzimMoonSun))) / sin(absAzimMoonSun)
        let tanBeta = (sin(moonAltitude) - sin(sunAltitude)) / (cos(sunAltitude) * sin(absAzimMoonSun))
        var diff = 0.0
        if (absAzimMoonSun * radiansToDegrees) <= 180 {
            diff = atan(-tanBeta)
        } else {
            diff = atan(tanAlfa)
        }

        return (tanAlfa, -tanBeta, diff)
    }

I use this code to rotate an image of the moon, but it presents a constant error when compared to sites like: https://www.timeanddate.com/astronomy/italy/turin
or
https://www.mooncalc.org/#/45.3502,7.744,13/2018.09.05/09:26/99/0

Can someone tell me what's wrong?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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