# How to rotate a rectangle body around a fixed point?

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.

• I fix the picture. Now my problem is clear? – RedYellowGreen Oct 11 '17 at 11:27
• Yes, as in "What have you tried to do to fix the issue described in the question?". – Vaillancourt Oct 11 '17 at 11:45
• Ohh, sorry. I will prepare a demo based on JS, but first I need to understand trigonometry. The problem is that I do not have knowledge in mathematics for such a simple task. Believe me, I'm not a lazy ass. – RedYellowGreen Oct 11 '17 at 12:08
• @RedYellowGreen gamedev.stackexchange.com/questions/9607/… set the position first. Then using the position and quaternions - rotate an object. Calculate direction from object to point then Quaternion.LookRotation(direction); Make sure pivot is set right for the object you are trying to rotate and its initial rotation. – Candid Moon _Max_ Oct 11 '17 at 12:16

## 1 Answer

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.