PDA

View Full Version : Help in making polygon sharing a common edge



Aycha
02-23-2010, 07:28 AM
if we change the value of n=1,2,3,4....n the vertics should b drwan and make a polygon of that no. of vertics

strattonbrazil
02-23-2010, 10:29 AM
Please don't use cell phone notation. I value the the letter 'e'.

So what are you trying to do? You want to make a polygon that shares a common edge? With what? Another polygon?

You're saying, you want a function that takes a integer n and outputs a polygon with that number of vertices? That's easy enough.



glBegin(GL_POLYGON);
for (int i = 0; i < n; i++)
glVertex3f(0,0,0);
glEnd();


Done! Of course this is pretty worthless. What are you trying to do? You need to define a problem. For example, if n is one or two, what kind of polygon would you expect to get? A polygon is planar and you can't make a plane without at least three points.

Is this supposed to converge on some shape? Should n=3 be a equilateral triangle? n=4 be a square? Should n=1000 look like a nicely-rounded circle?

Aycha
02-24-2010, 09:40 AM
question is that we change value of vertices
3,4,5,6...n
then on the same vertics triangle ,then 4gon then pentagon then hexagon is drawn but on same vertics




i have tried this but itz not working window is drwan but then no shape is drawn

Aycha
02-24-2010, 09:53 AM
just like this

http://img709.imageshack.us/img709/1996/89948245.jpg
i hope u will understand my question

strattonbrazil
02-27-2010, 06:39 PM
That's a much better question and the picture always helps.

As I thought, your shape is going to converge on a circle. Without giving too much code, you basically have a set a of vertices and you need to figure out where to place them.

If you think about this problem in polar coordinates, imagine you want to draw a circle with 3 points (a triangle). Well, you know you're going to need 120 degrees between each direction for each vertex. If I put one vertex on the (1,0) axis, then the next point is going to be 120 degrees rotated around and the next point will be another 120 degrees.

Doing the same thing with 4 points, you will have 90 degrees between each point. You see the pattern...

degrees per vertex = 360 degrees / n vertices