TITLE: Angle Between Two Vectors Facing A Point
QUESTION [8 upvotes]: I need a mathematical algorithm for finding the angle, formed by three points, which is open toward a fourth point. 
For example, in Fig1 below I desire angle $\theta$ because it is "facing" point $P$. However, the formula for the angle between two vectors, $$\theta=\cos^{-1}\Big(\frac{\vec{u}\cdot\vec{v}}{uv}\Big)$$ gives angle $\alpha$ because the above relation always returns the angle which is less than 180 degrees. 
(Fig1)
In contrast, in Fig2 I desire angle $\alpha$ because this time it is "facing" point $P$. 
(Fig2)
As a final example, in Fig3 below I need angle $\theta$, because it is still technically "facing" point $P$.
(Fig3)
This problem can occur in any orientation, making it difficult to say, for example, "If point $P$ is to the left of points $A, B, C$, use the leftmost angle, otherwise use the right" or something like that. 
Any help would be appreciated!

My Attempted Solution
If anyone's interested, my current solution is to split the angle facing the point $P$ in half and add those two together.
In Fig4 below, I use the grey line to split the angle in half, find $s$ and $t$ using dot product, then add $s$ and $t$ to get the angle facing $P$.
(Fig4)
This works until I reach a situation like that in Fig5. What I need is $s+t$, but what I get is $q+t$ because the dot product gives $q$ (since $s$ is greater than $180$ degrees). 
(Fig5)
It's a conundrum.

REPLY [2 votes]: You can sort this out by comparing the signs of three determinants. Let $$d_0 = \det\begin{bmatrix}B_x&B_y&1\\A_x&A_y&1\\C_x&C_y&1\end{bmatrix}.$$ This tells you the direction in which the vertices of $\triangle{BAC}$ are traversed: positive means counterclockwise, negative clockwise, and the points are colinear if it’s zero. Note that the area of this triangle is equal to $\frac12\lvert d_0\rvert = \frac12\lVert A-B\rVert\,\lVert C-B\rVert\,\lvert\sin\phi\rvert$, with $\lvert\phi\rvert\in[0,\pi)$, so when the points aren’t colinear this is another way to find the angle between them. Moreover, unlike the dot product, this determinant can tell left from right. On the other hand, it can’t tell the order of the points when they’re colinear, which the dot product can.  
Now, assuming that $d_0\ne0$, compare the signs of the corresponding determinants for $\triangle{APB}$ and $\triangle{BPC}$ $$d_A=\det\begin{bmatrix}A_x&A_y&1\\P_x&P_y&1\\B_x&B_y&1\end{bmatrix} \text{ and } d_C=\det\begin{bmatrix}B_x&B_y&1\\P_x&P_y&1\\C_x&C_y&1\end{bmatrix},$$ respectively, to the sign of $d_0$: If they are all the same, then $P$ lies within the “narrow” side and you can use the angle $\theta$ computed in your question; if any differ, then $P$ is on the “wide” side and you want $2\pi-\theta$. If either $d_A$ or $d_C$ is zero, ignore it; if both are zero, then $P=B$ and you might as well use $\theta$.  
If you expand these determinants, you might find that the resulting expressions look familiar. For example, $d_0 = (A-B)\wedge(C-B)$, where $\mathbf v\wedge\mathbf w=v_x w_y-v_y w_x$ is the “two-dimensional cross product” of the vectors.