Rotating a Point about Another Point (2D)
To determine the points that define a shape for collision detection, it is necessary to rotate the points around a pivot point. In this case, the pivot point is the center of the shape.
To rotate a point p around another point (cx, cy) by an angle angle in radians, follow these steps:
Translate the point back to the origin by subtracting (cx, cy):
p.x -= cx; p.y -= cy;
Rotate the point counter-clockwise:
float xnew = p.x * cos(angle) - p.y * sin(angle); float ynew = p.x * sin(angle) + p.y * cos(angle);
Translate the point back by adding (cx, cy):
p.x = xnew + cx; p.y = ynew + cy;
Using this method, you can rotate any point around any other point and determine the shape of an object for collision detection.
The above is the detailed content of How do I Rotate a 2D Point Around Another Point?. For more information, please follow other related articles on the PHP Chinese website!