I want to rotate a CGPoint on the screen depending on the angle and the rotation is anchored on another point rather than on itself. Was wondering what is the most efficient way of doing this?
What is the best way to rotate a CGPoint on a grid?
(4 posts) (3 voices)-
Posted 2 years ago #
-
You could use geometry to do the math yourself. Or let CGAffineTransform handle it.
Posted 2 years ago # -
found a solution:
CGAffineTransform translateTransform = CGAffineTransformMakeTranslation(customCenter.x, customCenter.y);
CGAffineTransform rotationTransform = CGAffineTransformMakeRotation(radians(angle));CGAffineTransform customRotation = CGAffineTransformConcat(CGAffineTransformConcat( CGAffineTransformInvert(translateTransform), rotationTransform), translateTransform);
CGPoint = rotatedPoint = CGPointApplyAffineTransform(initialPoint, customRotation);
Posted 2 years ago # -
Hi,
Would it be possible to explain how this works? I think it is moving the point being rotated around back to the origin, doing the rotation transform and then moving the point back off its origin...(?)
Regards
i
Posted 1 year ago #
Reply
You must log in to post.