开发者

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

开发者 https://www.devze.com 2022-12-17 17:47 出处:网络
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 constr

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

精彩评论

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