Draw a multipolygon

95 Views Asked by At

I need to build a shutter like this:

picture of a shutter

What is the formulas to draw each vertex?

Suppose I have num which is the number of triangles (in this case num=7) and the radius of the circle. How can I obtain the coordinates of each vertex of each triangle of the shutter?

I don't know how to obtain these coordinates.

Thank you very much

2

There are 2 best solutions below

2
On

$$x=r\cos(\theta), y=r\sin(\theta), \theta = \frac{360i + offset}{num}$$

Where $i = 0,...,num-1$, and offset can 'rotate' the starting point. Look up polar coordinates or circle parametric equation.

0
On

I'll use the name $n$ instead of num for the number of triangles because it works better in math formulas. You can translate back when using it in your software.

In the "shutter" we can see an outer $n$-gon (containing all the rest of the figure) and an inner $n$-gon (the white or empty region in the middle). The inner $n$-gon is smaller than the outer $n$-gon and is rotated so that each edge of the inner $n$-gon, extended in a clockwise direction relative to the center of the $n$-gon, intersects a vertex of the outer $n$-gon.

The regions bounded by these extended edges and the edges of the outer $n$-gon are the triangles you want to draw.

One edge of a triangle is simply one of the edges of the outer $n$-gon, which is easy enough to plot. Assuming you are using standard Cartesian coordinates (perpendicular $x$ and $y$ axes, and the positive $y$ axis is counterclockwise from the positive $x$ axis), if the center of the shutter is to be at the point $O = (x_0,y_0),$ you can plot the vertices of side $k$ of the $n$-gon at $$ A = \left(x_0 + R\cos\left(\theta_0 + \frac{2\pi}n k\right), y_0 + R\sin\left(\theta_0 + \frac{2\pi}n k\right)\right) $$ and $$ B = \left(x_0 + R\cos\left(\theta_0 + \frac{2\pi}n (k + 1)\right), y_0 + R\sin\left(\theta_0 + \frac{2\pi}n (k + 1)\right)\right), $$ where $\theta_0$ is an angle that determines how the entire shutter is oriented relative to your drawing; increasing $\theta_0$ will rotate the entire shutter counterclockwise.

Now let $M$ be the midpoint of the segment $AB.$ Then $\triangle OMA$ is a right triangle with its right angle at $M.$ The hypotenuse $OA$ has length $R$ and the angle at $O$ is $\pi/n,$ so $OM = R \cos(\pi/n).$

If $C$ is the third vertex of the triangle that you want to draw adjacent edge $AB,$ if $D$ is the vertex of the inner $n$-gon between $A$ and $C,$ and if $P$ is the midpoint of $CD,$ then $\triangle OPA$ is a right triangle with its right angle at $P,$ again with hypotenuse $OA.$

The next part depends on how you want to set the inner shape of the shutter. You can specify the angle $\alpha$ at $A$ in the triangle $\triangle ABC,$ you can specify the distance from the center to one of the vertices of the inner $n$-gon (that is, specify the length $OC$), or you can specify the distance from the center to the midpoint of a side of the inner $n$-gon (that is, specify the length $OP$).

Any one of these measurements gives you the other two. When we know either $OC$ or $OP,$ we can derive the other value using the formula $$ OP = OC \cos(\pi/n). $$ When we know either $\alpha$ or $OP$ we can derive the other value from the formula $$ OP = R \cos\left(\frac\pi n + \alpha\right), $$ because $\angle POM = \alpha.$

So let's suppose you specified the inner shape of the shutter somehow and that you now have the values of $\alpha$ and $OC.$ Then the coordinates of $C$ are obtained by a formula similar to the one for $B,$ but scaled down (because it is a vertex of a smaller $n$-gon) and rotated by the angle $\alpha$: $$ C = \left(x_0 + OC\cos\left(\theta_0 + \frac{2\pi}n (k + 1) + \alpha\right), y_0 + OC\sin\left(\theta_0 + \frac{2\pi}n (k + 1) + \alpha\right)\right). $$

If you would like to know the sides and angles of triangle $\triangle ABC,$ they are \begin{align} AB &= 2R \sin\left(\frac\pi n\right), \\ AC &= R \left(\sin\left(\frac\pi n + \alpha\right) + \sin\left(\frac\pi n\right)\cos\left(\frac\pi n + \alpha\right)\right),\\ BC &= R \left(\sin\left(\frac\pi n + \alpha\right) - \sin\left(\frac\pi n\right)\cos\left(\frac\pi n + \alpha\right)\right),\\ \angle BAC &= \alpha, \\ \angle ACB &= \frac{2\pi}n, \\ \angle ABC &= \pi - \frac{2\pi}n - \alpha. \end{align}