• 11
• 9
• 10
• 9
• 10

polygon rotation aound their own centers

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

Recommended Posts

Okay, first of all, this is for an assignment, so don't give me the answer straight out if you can avoid it (this is only a small part of the assignment). Most of the assignment background doesn't matter but I basically have an array of points that represent polygons. Eg, depending on the number of points each polygon has, the first n points is the first polygon, the next n points is the second polygon, etc, etc. I need to be able to rotate each of the polygons around their own center by the same amount. I didn't think it would be that hard, but I'm hitting some roadblocks. At the moment, it's a large triangle and I'm creating <insert name here I can't remember>'s Gasket, where the whole shape is subdivided into smaller and smaller shapes of the same type and I need all of the smaller ones to rotate constantly.
// if we are rotating the individual polys of the gasket
if( rotateMode ){
//	glPushMatrix();
// set rotation on the z axis

// increase the individual poly rotation

// restrict it to [0,360]
}

// because every 'num_poly_points' is a single polygon. I have to draw each poly seperately.
for(int i=0; i < vertexList[gasket_depth].getSize(); i+=num_polygon_points){

if( rotateMode ){
glPushMatrix();
}

// draw a single polygon
glBegin(draw_mode);
for(int j=0; j < num_polygon_points; ++j)
glEnd();

if( rotateMode )
glPopMatrix();
}


So what I'm ending up doing is just rotating the whole thing. Any hints? Edit:: I was hoping that I wouldn't have to do something like keep seperate translation info on each of the polys. [Edited by - Endar on April 6, 2006 3:15:16 AM]

Share on other sites
u will need to translate first to the center of each polygon before u do rotation
u will need to store/restor the matrix state for each polygon (push/pop)

Share on other sites
I was afraid of that.

Any idea how to find the center of a polygon given it's points?

Share on other sites
Quote:
 Original post by EndarAny idea how to find the center of a polygon given it's points?

Assuming all the points lie within a single plane, and the polygon is convex, simply averaging them might work...

Share on other sites
Really? I mean, currently all the points are an equal distance away from the center (the distance and angles for each edge are the same), but later on we have to make it possible to change that.

Won't this have an impact on this?

Share on other sites
Finding the centre of the polygon depends on the polygon itself. For eg:- if you have a square or rectangle then the interesectiong of the diagonals will be its centre. Similary for a triangle the centre would be the intersection of the lines drawn from the centre of line to its opposite vertex. It would be easier to push and pop actually than trying to find the centre of a polygon because then instead of finding the centre, you already have it - i.e. at 0, 0, 0.

Share on other sites
Quote:
 Original post by CRACK123It would be easier to push and pop actually than trying to find the centre of a polygon because then instead of finding the centre, you already have it - i.e. at 0, 0, 0.

Yeah, but won't I have to know the center point for each polygon so I can translate it by it's center to it's correct position?

Share on other sites
Sounds like a Sierpinski Gasket to me.

bpoint is correct about averaging the vertices of a planar convex polygon. It also works on things like parallelograms and trapezoids which don't have vertices that are equally spaced from the center and the angles are not the same.

DG

Share on other sites
Quote:
 Original post by Disgruntled GamerSounds like a Sierpinski Gasket to me.bpoint is correct about averaging the vertices of a planar convex polygon. It also works on things like parallelograms and trapezoids which don't have vertices that are equally spaced from the center and the angles are not the same.DG

Yep, that's the one. Thanks guys. Do you want credit in my assignment for this?

Share on other sites
Paul Bourke's geometry page has equations describing how to calculate the centroid of a polygon, in case you need it.

Quote:
 Do you want credit in my assignment for this?

For me, it's not necessary. I come here helping out for fun. :)