Skip to content

Instantly share code, notes, and snippets.

@malcommac
Created October 15, 2015 10:13
Show Gist options
  • Save malcommac/cd8111f71c4e5859b016 to your computer and use it in GitHub Desktop.
Save malcommac/cd8111f71c4e5859b016 to your computer and use it in GitHub Desktop.
Rotate Points
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