Hello everybody, i need a polygon formula to draw one. I want to make a function that will draw a polygon , depending on how many vertex's it has. I'm not good at math so i can't figure it out how to do it. Though, i do understand that it should look something like: pass=360/vertex , then calculate some end points of lines that are 'pass' degrees from each other; but i don't know how to do that.
Can someone help?Pls!

If my math is correct,

x(n) = x + r*cos(a + n*pass)
y(n) = y + r*sin(a + n*pass)

where 0 <= n < vertex , x and y is the center point, a is the angle of the first point to the right of the center point from the horizontal(counter-clockwise) and r is the distance from the center point to each of the vertices(the "radius"). Let me know if this is what you were looking for.

Good formulas!

Also note that you have to use radians (not degrees) for your angles, so pass = 2 * M_PI / vertex (M_PI is in math.h) .

Thank you for telling me about radians!

Sort of ! But not really..
This is what i wrote

void polygon(int x, int y, int n, int r){
int k=0, *poly;
double pass= 360/n, _n=0,pass2=n*pass;
poly=new int[n];
   	     poly[k++]=x +r * cos(pass2);
	     poly[k++]=y +r * sin(pass2);

as i understood , a is a=a+a; at each iteration? If it is so, it is not really what i expected, though it's better than nothing. Thx!
This is the output,at:

a is constant, but n*pass changes because n changes
i dont know why do you use double pass = 360 / n
and after that pass2 = n * pass, do you mean pass2 = 360?
and why do you use _n?
dont forget about radians, because, i think, sin() and cos() use radians as input parameters
this is not about your previous post but one before it

double pass2 = a; //where a is angle between line (first point of polygon joined with centre of polygon) and x axis.....you might like to set pass2 to 0 in the beginning
poly[k++]=x +r * cos(pass2);
poly[k++]=y +r * sin(pass2);
pass2 += pass;
this is how it goes i think

Thank you for making clear the formulas!

Woaaah! That did it! I am very thankfull!! Super, just what i need!

no prob, just dont forget to give the credits to a man who gave you the formula in the first place ;) (nmaillet)

This question has already been answered. Start a new discussion instead.