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?
Use a 2D rotation matrix. If you want to rotate a point counterclockwise about the origin by an angle of angle, then you would do this:
CGPoint RotatePointAboutOrigin(CGPoint point, float angle)
{
float s = sinf(angle);
float c = cosf(angle);
return CGPointMake(c * point.x - s * point.y, s * point.x + c * point.y);
}
If you want to rotate about a point other than the origin, you'll have to first subtract the center of rotation from your point, rotate it using the above, and then add back in the center of rotation (this is called conjugation in matrix theory).