0
$\begingroup$

I have a set of 3d points that form a 2d polygon. They are ordered in either clockwise or counter clockwise order (one or the other, but I don't know which beforehand).

Now, I want to divide the polygon in triangles, which I'm trying to do by using a ear clipping approach. The problem is that, in order for such an algorithm to work, I need to check if a given angle is concave or not.

In 2d space, and given clockwise order, you can use the cross product and see the direction of the resulting arrow to know if the angle is concave (as you're effectively checking if it makes a left or right turn). However, without knowing whether my points are clockwise or counter-clockwise, and without knowing the normal of the plane, I have no idea on how to approach the problem.

There are some similar questions such as this one, but they assume 2d space, which makes things easier.

1 Answers 1

0

Given three consecutive vertices $P_1$, $P_2$ and $P_3$, you can compute sine and cosine of $\theta_2=\angle P_1P_2P_3$ as follows: $$ \cos\theta_2={\vec{P_2P_1}\cdot\vec{P_2P_3}\over |P_2P_1||P_2P_3|}, \quad \sin\theta_2=\pm{|\vec{P_2P_1}\times\vec{P_2P_3}|\over |P_2P_1||P_2P_3|}. $$ To decide the sign of $\sin\theta_2$ you must check whether $\vec{P_2P_1}\times\vec{P_2P_3}$ has the the same direction as a fixed (but arbitrary) normal to the plane of the polygon (you can take, for instance, the cross product of any two sides of the polygon).

From $\sin\theta_k$ and $\cos\theta_k$ you can then find the angle $\theta_k\in(0,2\pi)$ for all the $n$ vertices of your polygon. The only problem is you don't know if you got the inner or outer angles. But it is not difficult to check that: if $\sum_k\theta_k=(n-2)\pi$, then you got all inner angles, and that's fine. If, on the other hand, $\sum_k\theta_k=(n+2)\pi$, then you got all outer angles, but from them you can readily compute the inner angles as $2\pi-\theta_k$. That should solve your problem.