Last active
March 30, 2023 13:31
-
-
Save Joony/b62a1068cf97f267c5e7bba8af3b5d53 to your computer and use it in GitHub Desktop.
Calculate local gravity for a given latitude and elevation
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
func localGravity(latitude: Double, elevation: Double) -> Double { | |
let a: Double = 0.0053024 | |
let b: Double = 0.0000058 | |
let l = latitude * .pi / 180 | |
let sinl: Double = sin(l) | |
let sinl2: Double = sinl * sinl | |
let sin2l: Double = sin(l * 2) | |
let sin2l2: Double = sin2l * sin2l | |
let t: Double = 1 / 1000000 | |
let ab = (1 + a * sinl2 - b * sin2l2) | |
let g = (9.780327 * ab - 3.086 * t * elevation) | |
return g / 10 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment