Created
October 15, 2015 10:13
-
-
Save malcommac/cd8111f71c4e5859b016 to your computer and use it in GitHub Desktop.
Rotate Points
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
public static func rotate(points: [StrokePoint], byRadians radians: Double) -> [StrokePoint] { | |
let centroid = StrokePoint.centroid(points) | |
let cosvalue = cos(radians) | |
let sinvalue = sin(radians) | |
var newPoints: [StrokePoint] = [] | |
for point in points { | |
let qx = (point.x - centroid.x) * cosvalue - (point.y - centroid.y) * sinvalue + centroid.x | |
let qy = (point.x - centroid.x) * sinvalue + (point.y - centroid.y) * cosvalue + centroid.y | |
newPoints.append(StrokePoint(x: qx, y: qy)) | |
} | |
return newPoints | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment