Advertisement Jump to content
Sign in to follow this  

Rotating a group of points around a pivot

This topic is 4010 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So simple and yet I'm stumped. I have four points (with x, y, z coordinates) that make up a rectangle. I want to rotate the rectangle around it's own center. How do I do that?

Share this post

Link to post
Share on other sites
Your coordinates should be relative to the center of the rectangle, placed at the origin (so the 4 points are local coordinates, the pivot of the rectangle - its center in your case - is located at 0,0,0).

Transform each point by using a 4x4 matrix which contains the transformation steps you want to apply to the rectangle, for example:

* rotation around the z axis
* followed by a rotation around the y axis
* followed by a rotation around the x axis
* followed by a translation

Share this post

Link to post
Share on other sites
You have to apply a pivot transformation first.
This would translate your vertices so that its center of rotation will be the pivot.

Assuming you only have a translational pivot point, this goes like:

transformMatrix = TranslationMatrix( -pivotPoint ) * RotationMatrix( rotation ) * Translationmatrix( pivotPoint ) * TranslationMatrix( translation )

Where pivotPoint is the center of rotation, rotation is the rotation of your quad and translation its position. Of course you can optimize this, but it shows the idea.

If you have a 10x10 quad with the lower left corner at 0,0,0 and upper right at 10, 10, 0 then your pivotPoint would be 5,5,0 to make it rotate around the center.

Hope that helps :)

Edit: of course I'm assuming you cannot modify the vertex data here. You can also just translate all vertices so that 0,0,0 is the center of rotation. This is also basically what the transform matrix with pivot support does.

Share this post

Link to post
Share on other sites

Basically you define a new coordinate system for the group of points. You would place the origin of the coordniate system at the point of the pivot.

Now incase you don't know, basically a coordinate system defines which way/direction is up/down, which way is left/right, and which way is forwards/backwards.

You will need to have some knowledge of matrices and such also, as coordinate systems are represented with a 4x4 matrix, and are combined (added together) via matrix multiplication. I won't bother going any further into things incase you already know.

So what you do is instead of changing/rotating the points, you just change/rotate each axis of your coordinate system and draw the points relative to it.

I hope this makes some sense.

I quickly put together some pesudo code, I hope it is okay :).


// push current modelview matrix onto stack
// note, I assume the modelview matrix is already set as expected, whether it be in
// world space, or transformed into eyespace by the camera or whatever

// note, if this was a class then you would probably have this matrix defined inside it, and have
// functions to alter it, but I just do these things here to make the example easier to read
CMatrix rectMatrix;
rectMatrix.location = pivot.position; // set origin to position of pivot
rectMatrix.rotate(1, 0, 0, 45.0f); // rotate 45 degrees around X axis

// note, the group of points should be defined in object space
glMultMatrix(rectMatrix.matrix); // multiply/combine with current opengl modelview matrix
OnDrawGroupOfPoints(); // draw group of points

// restore previous modelview matrix from stack


[Edited by - yosh64 on January 28, 2008 5:57:44 PM]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!