Created
February 8, 2017 22:24
-
-
Save KyleGoslan/844d61709b70a80685d08c9905751575 to your computer and use it in GitHub Desktop.
Calculate time to move between two points given an arbitrary speed
This file contains 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 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