Skip to content

Instantly share code, notes, and snippets.

@haydenholligan
Last active May 12, 2016 20:51
Show Gist options
  • Select an option

  • Save haydenholligan/c4d1044e4bea692643f54623437b2daf to your computer and use it in GitHub Desktop.

Select an option

Save haydenholligan/c4d1044e4bea692643f54623437b2daf to your computer and use it in GitHub Desktop.
func pointPairToDegrees(from: CGPoint, to: CGPoint) -> Double {
let origin = CGPointMake(to.x - from.x, to.y - from.y)
let bearingRadians = Double(atan2f(Float(origin.y), Float(origin.x)))
let bearingDegrees = bearingRadians * (180 / M_PI)
return modulus(bearingDegrees, modulo: 360)
}
func modulus(number: Double, modulo: Double) -> Double {
var result = number % modulo
if result < 0 {
result += modulo
}
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment