Assume we have an arbitrary polygon that has no holes nor self edge intersections, but can otherwise be concave and deformed.

Assume the vertices are ordered either clockwise or ccw.

So for example the following:

enter image description here

The angle at the blue vertex is greater than 180 in this case. Beause that is the angle "inside" the polygon.

Usually when I want to measure angles in a shape I just take the dot product, but that will always give back an angle <180, which is not ideal.

Assuming that all I have is an ordered list of the vertices of the polygon. How can I measure the appropriate angle?


If you have an ordered list of vertices $v_i$, you can generate an ordered list of unit edge vectors $$e_i = \frac{v_{i+1}-v_i}{|v_{i+1}-v_i|},$$ where ($v_{n+1} \equiv v_1$).

Then we calculate the list of rotations $\alpha_i$: $$ \alpha_i=\arccos(e_{i-1}\cdot e_i) \begin{cases}1& \text{if} &e_{i-1}\times e_i>0,\\ -1& \text{if} &e_{i-1}\times e_i<0\end{cases}, $$ where $e_0\equiv e_n$ and $a\times b=a_xb_y-a_yb_x$ is a $z$-component of vector product if one consider $a$ and $b$ in 3d space.

Finally, if $\sum \alpha_i = 2\pi$, then we travelled through vertices counter-clockwise and polygon angles $\beta_i=\pi-\alpha_i$.

If $\sum \alpha_i = -2\pi$, then we travelled through vertices clockwise and polygon angles $\beta_i=\pi+\alpha_i$.

However, if $\sum \alpha_i$ is some other number like $0$ or $-4\pi$, then the polygon has self intersections and without defining what counts as its interior, it's impossible to tell what the angles are.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.