and i'm making a 'Body' class which holds a bunch of 2D shapes together to form a single moveable, rotatable body.
What i need to know is how i can rotate each individual shape in a way that makes it look like the whole body is rotating, not each shape doing it's own rotation around it's center. I can't just change each shapes center of rotation to the same point, as this would cause their placement to be affected also.
Therefore i need to find some kind of equation that uses the bodies center to re-position and re-rotate each individual shape in a body in a way that keeps the Body figure undeformed?
How can i do this?
The way to rotate by an arbitrary point is first substract the point coordinates, do the rotation about the origin and then add the point coordinates.
x2 = px + (x1-px)*cos(q)-(y1-py)*sin(q)
y2 = py + (x1-px)*sin(q)+(y1-py)*cos(q)
where px, py are the rotation point coordinates, and x1,y1 the original 2D shape vertex and x2,y2 the rotated coordinates, and q the angle in radians.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With