Last active
September 13, 2018 18:21
-
-
Save elijahzarlin/319a63a0bae31545274c99624b451716 to your computer and use it in GitHub Desktop.
world scale ar post
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 azimuthBetween(origin: CLLocation, destination: CLLocation) -> Float { | |
| var azimuth: Float = 0 | |
| let originLatitude = GLKMathDegreesToRadians(Float(origin.coordinate.latitude)) | |
| let originLongitude = GLKMathDegreesToRadians(Float(origin.coordinate.longitude)) | |
| let destinationLatitude = GLKMathDegreesToRadians(Float(destination.coordinate.latitude)) | |
| let destinationLongitude = GLKMathDegreesToRadians(Float(destination.coordinate.longitude)) | |
| let dLon = destinationLongitude - originLongitude | |
| let y = sin(dLon) * cos(destinationLatitude) | |
| let x = cos(originLatitude) * sin(destinationLatitude) - sin(originLatitude) * cos(destinationLatitude) * cos(dLon) | |
| azimuth = atan2(y, x) | |
| if(azimuth < 0) { azimuth += 2 * .pi } // We only use positive values for consistency | |
| return azimuth | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment