## How do you rotate an object around an arbitrary Point?

### How do you rotate an object around an arbitrary Point?

I've got this far to understanding 2d rotation, the new x is the radius *
the cos of an an angle in radians
plus the radius(same as radius, for a circle) offset by 100 (offset from the
0,0 origin (top left of screen/form). y is similar, but I'm stuck on
The books say move the arbitrary point to the origin, rotate  then translate
the arbitrary point back to the previous location. I'm trying to do this
without matrix calculations.
'clockwise rotation
Any help? Thank you.

### How do you rotate an object around an arbitrary Point?

First do the translation:

x = x + xOffset
y = y + yOffset

then do the rotations, and then finally translate back

x = x - xOffset etc

Jim Deutch
MS Dev MVP

>I've got this far to understanding 2d rotation, the new x is the radius *
>the cos of an an angle in radians
>plus the radius(same as radius, for a circle) offset by 100 (offset from
the
>0,0 origin (top left of screen/form). y is similar, but I'm stuck on
>The books say move the arbitrary point to the origin, rotate  then
translate
>the arbitrary point back to the previous location. I'm trying to do this
>without matrix calculations.
>'clockwise rotation
>Any help? Thank you.

I know that glRotatef rotates around the origin (0,0,0). Now I want to
rotate an object around its own center. Let's say that the object's
center is located at (5,5,0). I should be able to rotate the object
around around the z-axis by first translating the object's center to the
origin, then rotate the object, and then translate the object back to
its original position.

code:

glPushMatrix();
glColor3f(1,0,0);

glTranslatef(-5,-5,0); // Put the fixed point at the origin
glRotatef(45,0,0,1); // Rotate 45 degrees around the z-axis
glTranslatef(5,5,0); // Translate back to original position

glBegin(GL_LINES);
glVertex3f(0,0,0);
glVertex3f(10,0,0);
glVertex3f(0,0,0);
glVertex3f(0,10,0);
glVertex3f(10,0,0);
glVertex3f(0,10,0);
glEnd();
glPopMatrix();

The problem however, is that due to the first translation, the origin
gets translated too! So the object doesn't get rotated around its own
center but still around the origin! How the heck can I get this working?

Any help is appreciated.

Regards,

Boris

6. DOC2TEX