Creating a Polygon with n sides
I need help with coming up with the algorithm that is required to create a ngon. The user gives the center of the polygon (x, y), the distance to the vertices (r), and the number of sides.
So for say a pentagon i would get the users information and i can from there go to the first point of the polygon (x+r,y) (this must be one of the point of the polygon) so the pentagon is going to be sideways.
I can get the side length by taking the inner angle (360 / n) which in this case is 72 degrees. i convert that to radians. then i also find degree of the other two equal angles by taking (180 - 72)/2 which gives 54 and convert that to radians. I then use the formula
r/sin(54 in radians) = sidelength/sin(72 in radians)
So now i have the side length i just cant figure out the next x and y coordinates to go to. could someone help explain to me how i would go about solving this? the c++ code would be nice but that i can do on my own after i conquer this problem.
cheers.