Calculate coordinates of a regular polygon's vertices

后端 未结 7 1854
醉酒成梦
醉酒成梦 2020-12-12 18:30

I am writing a program in which I need to draw polygons of an arbitrary number of sides, each one being translated by a given formula which changes dynamically. There is som

7条回答
  •  执笔经年
    2020-12-12 18:44

    Say the distance of the vertices to the origin is 1. And say (1, 0) is always a coordinate of the polygon.

    Given the number of vertices (say n), the rotation angle required to position the (1, 0) to the next coordinate would be (360/n).

    The computation required here is to rotate the coordinates. Here is what it is; Rotation Matrix.

    Say theta = 360/n;

    [cos(theta) -sin(theta)]
    [sin(theta) cos(theta)]
    

    would be your rotation matrix.

    If you know linear algebra you already know what i mean. If dont just have a look at Matrix Multiplication

提交回复
热议问题