开发者

How to draw a Polygon with X sides (all equal length & angles)

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).


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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜