Algorithm to construct irregular polygon

185 Views Asked by At

I have number of line segments (they represent walls in floor scheme) each accompanied with length and adjacent angle. What sequence of steps should my algorithm perform in order to obtain set of vertices for irregular polygon which will correspond to given side lengths and angles?

1

There are 1 best solutions below

1
On BEST ANSWER

enter image description here

Suppose that the floor plan of your room is a polygon with $n$ sides and vertices $A_1,A_2,\dots A_{n}$. The length of segments are:

$$l_1=\overline{A_1A_2}, \ l_2=\overline{A_2A_3}, \ \dots \ l_i=\overline{A_iA_{i+1}}, \ \dots \ l_{n-1}=\overline{A_{n-1}A_{n}}, \ l_n=\overline{A_nA_{1}}$$

These lengths are given as well as internal angles of the polygon. Denote angle at point $A_i$ with $\alpha_i$. Basically, on input you have a set of values $l_i,\alpha_i$ for $i=1,2,\dots n$. Your task is to compute coordinates of all vertices.

Suppose that you have already caclulated coordinates $A_i(x_i,y_i)$ and angle $\beta_{i-1}$ between segment $A_{i-1}A_i$ and $x$-axis.

Coordinates of point $A_{i+1}$ are given with the following expressions:

$$\beta_i=\beta_{i-1}+\pi-\alpha_i\tag{1}$$

$$x_{i+1}=x_i+l_i\cos\beta_{i}\tag{2}$$

$$y_{i+1}=y_i+l_i\sin\beta_{i}\tag{3}$$

You need a starting point. You are free to choose $A_1$ to be the orgin of your coordinate system:

$$x_1=y_1=0 \tag{4}$$

You can orient your $x$-axis along the segment $A_1A_2$ which means that:

$$x_2=l_1, \ y_2=0, \ \beta_1=0\tag{5}$$

With initial conditions set as in (4) and (5) you just need to repeat steps (1), (2) and (3) exactly $n-2$ times to calculate coordinates of the remaining $n-2$ polygon vertices:

$$\beta_2=\beta_1+\pi-\alpha_2$$

$$x_3=x_2+l_2\cos\beta_{2}$$

$$y_3=y_2+l_2\sin\beta_2$$

$$\beta_3=\beta_2+\pi-\alpha_3$$

$$x_4=x_3+l_3\cos\beta_3$$

$$y_4=y_3+l_3\sin\beta_3$$

$$\dots$$