Check whether three points are clockwise or counter clockwise
We have three points: $ACB$ in
clockwise order
Or Vector
\[
\vec{CA} =
\begin{bmatrix}
1 \\
0
\end{bmatrix} \quad
%
\vec{CB} =
\begin{bmatrix}
0 \\
1
\end{bmatrix}
%
\]
We can use the sign of determinant to check the order of three points:
\[
M = \begin{bmatrix}
1 & 0 \\
0 & 1
\end{bmatrix} \\
\det M = 1 > 0 \\
\]
If we check points: $A, C, B'$ in counter clockwise then we have following two vectors:
\[
\vec{CA} =
\begin{bmatrix}
1 \\
0
\end{bmatrix} \quad
%
\vec{CB'} =
\begin{bmatrix}
0 \\
-1
\end{bmatrix}
\]
we can form a matrix:
\[
M' = \begin{bmatrix}
1 & 0 \\
0 & -1
\end{bmatrix} \\
\det M' = -1 < 0
\]
We can conclude the following:
If the determinant is less than 0 then the three points are counter clockwise or CCW
If the determinant is greater than 0 then the three points are clockwise or CW
Check whether a point is inside a triangle
From above picture:
We can come up some intuition guessing:
$\angle D\color{red}{F}B + \angle A\color{red}{F}D + \angle A\color{red}{F}B > 360$
$\angle C\color{red}{D}B + \angle A\color{red}{D}C + \angle B\color{red}{D}A = 360$
$\angle C\color{red}{E}B + \angle A\color{red}{E}C + \angle A\color{red}{E}B = 360$
Note: if the point $E$ is the same as $A$, $B$ or $C$, then there is "divided by zero" problem
1. Check $E$ is diffed from $A, B, C$
2. Check if they are collinear with segments: $\overline{AB}, \overline{BC}, \overline{AB}$
3. Compute the angles with dot product.
\begin{equation}
\begin{aligned}
\cos \angle CDB &= \frac{\vec{DC} \circ \vec{DB}}{ | \vec{DC} | | \vec{DB}|} \\
\cos \angle ADC &= \frac{\vec{DA} \circ \vec{DC}}{ | \vec{DA} | | \vec{DC}|} \\
\cos \angle BDA &= \frac{\vec{DB} \circ \vec{DA}}{ | \vec{DB} | | \vec{DA}|} \\
2\pi &= \cos \angle CDB + \cos \angle ADC + \cos \angle BDA \\
\end{aligned}
\end{equation}