How to rotate a body around a point? The body has x, y, speed and angle. Coordinates of the body relative to its center. Additional conditions: point position and distance from body to point.
First off, you have redundancy in your state.
It is enough to track:
- angle (scalar.)
- angular velocity (scalar.)
- centre of rotation (2d vector.)
- radius (scalar.)
from this you can determine:
- the body's position (2d vector.)
- the body's orientation (local frame defined by body-up-vector, a 2d unit vector.)
To rotate it with timestep dt, you would do:
angle += dt * angular_velocity body.up.x = cosf( angle ) body.up.y = sinf( angle ) body.pos.x = centre.x + radius * body.up.x body.pos.y = centre.y + radius * body.up.y
Note that instead of defining the body's rotation with an up-vector, you could use an x-vector, or even just an angle, which in your problem is the same as the angle with which the body is rotated around the centre. But when drawing your object on screen, you need a frame with two axes anyway: an x-axis and an y-axis (object's up vector.) As the axes are perpendicular it is easy to derive the x-axis from the y-axis by simply swapping the components.