# Help Needed With Rotating Ellipse

Hi,

I’m trying to draw a series of ellipses that rotate about a point other than their centre. The ellipses are drawn as a series of points.

My problem is, that I can get the ellipses to rotate about their own centre point, however I can’t figure out how to get them to rotate about a different point. Here’s the basic code I’ve tried:

``````  void drawEllipse()
{
int i, j;

glColor3f(1.0, 1.0, 0.0); // Yellow.

glPushMatrix();
glTranslatef(x, 0, z - 4.4); // Ellipse centre.

glRotatef(180-angle*180.0/3.14, 0.0, 1.0, 0.0);

for(j = 0; j < NUM_ELLIPSES; j++)
{
for(i = 0; i < 360; i++)
{

glBegin(GL_POINTS);
glEnd();
}

xradius += 0.25f; // Distance between ellipses.
}

glPopMatrix();
}
``````

Do I need to draw each point in each ellipse with respect to the rotation point (rather than the centre point) or is there another way to do this?

Cheers,

Chris Share

Actually, you’re doing this:

``````
glTranslatef(x, 0, z - 4.4); // Ellipse centre.
glRotatef(180-angle*180.0/3.14, 0.0, 1.0, 0.0);

``````

Which isn’t wrong for rotating the ellipse and placing it at the ellipse’s centre position, but now you want to rotate around a different position instead.

Remember: every vertex is modified in the reverse order of the matrix transformations. In your code, the vertices get rotated around 0,0,0 then they are moved by the ellipse centre position.

Try reversing the translate and the rotate. See what happens. Then adapt that to use the rotation point that you want to use.

(edit) And of course you can still combine that with rotation of the ellipse itself - everything is chained together.

Hi,

Thanks for you help, but I still don’t get it!

I understand what’s going on with my code (I think) and why it doesn’t do what I’d like it to do. In my code, I’m moving to the centre of the ellipse and then drawing and rotating each vertex.

However, I’m not clear about how to fix this. I tried changing the order of operations as suggested but I don’t get how this helps. Where is the centre of rotation being defined now?

Cheers,

Chris

P.S Is there an example anywhere of how to rotate an object about a point other than its centre?

If you want to rotate about a given point p:

``````(first translate object if not located at origin)

glTranslatef(p.x,p.y,p.z);
glRotatef(theta,...)
glTranslatef(-p.x,-p.y,-p.z);
``````

Hi,