tags:

views:

84

answers:

2

I am looking to calculate the X and Y points of each point on a polygon, given the number of sides, and the fact that all sides are equal. I would also have the width and height constraints of the entire shape. If it helps any, I would be doing this in Java (most likely using Line2D).

A: 

Becasue all Regular Polygons have a simple formula for the internal angle, all you need is turtle graphics for Java. This one seems well done.

trashgod
+6  A: 

You should first find out the center of the circle (cx, cy) and the radius R by the width and height constraints, which is trivial. Each of the polygon points is equally distributed on the circle and their position can be calculated by:

Xi = cx + R*cos(2.0*PI*i/n)
Yi = cy + R*sin(2.0*PI*i/n)
Long Cheng
Where n is the number of points and i counts from 0 to n-1.
phkahler