I want to rotate a CGPoint on the screen depending on the angle and the rotation is anchored on another point. Was wondering what is the most efficient way of doing this?
Swift 5
extension CGPoint {
func rotate(around center: CGPoint, angle: CGFloat) -> CGPoint {
let translate = CGAffineTransform(translationX: -center.x, y: -center.y)
let transform = translate.concatenating(CGAffineTransform(rotationAngle: angle))
let rotated = applying(transform)
return rotated.applying(CGAffineTransform(translationX: center.x, y: center.y))
}
}