Skip to content

Instantly share code, notes, and snippets.

@KyleGoslan
Created February 8, 2017 22:24
Show Gist options
  • Save KyleGoslan/844d61709b70a80685d08c9905751575 to your computer and use it in GitHub Desktop.
Save KyleGoslan/844d61709b70a80685d08c9905751575 to your computer and use it in GitHub Desktop.
Calculate time to move between two points given an arbitrary speed
func getDuration(pointA: CGPoint, pointB: CGPoint, speed: CGFloat) -> TimeInterval {
let xDist = (pointB.x - pointA.x)
let yDist = (pointB.y - pointA.y)
let distance = sqrt((xDist * xDist) + (yDist * yDist));
let duration = TimeInterval(distance/speed)
return duration
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment