Is point $p$ in triangle $ABC$?
If I have triangle $ABC$ and point $p$, how I can detect if point $p$ is in the triangle or not?
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It only takes a minute to sign up.
Sign up to join this communityIs point $p$ in triangle $ABC$?
If I have triangle $ABC$ and point $p$, how I can detect if point $p$ is in the triangle or not?
Calculate the area of triangles namely: $\mathcal{A}_{\triangle{ABC}}$, $\mathcal{A}_{\triangle{PAB}}$, $\mathcal{A}_{\triangle{PAC}}$, $\mathcal{A}_{\triangle{PBC}}$, then
$$\text{if:} \quad\mathcal{A}_{\triangle{ABC}} = \mathcal{A}_{\triangle{PAB}}+\mathcal{A}_{\triangle{PAC}}+ \mathcal{A}_{\triangle{PBC}}, \; \text{then}\; P \; \text{is inside}\; {\triangle{ABC}},$$
where $\mathcal{A}_{\triangle{ABC}} = \frac{x_{A} (y_B-y_C)+x_{B} (y_C-y_A) +x_{C} (y_A-y_B)}{2}.$
Hint.- A way is as follows: a point $P$ is inside of a triangle if and only if its distances to the sides of the triangle is less than or equal to the three heights. Forming a new triangle passing by the three vertices and parallel to the sides, the point $P$ should have a distance to one of the three new sides greater than one of the heights of the given (old) triangle.
This is a very crude way to do it, but works:
Let the equation of sides $a,b,c$ be $l_k(x,y)=0$, $k\in \{a,b,c\}$. Then for $P(x_o,y_o)$ to lie inside the triangle, you must have that
$$\text{sgn} \left[ l_k(x_k,y_k) \right] =\text{sgn} \left[ l_k(x_o. y_o) \right]$$
for all $k \in \{a,b,c\}$. Thus we have three conditions to check.
Explanation:
For a line $l(x,y) = 0$, the expression $l(x,y)$ is of same sign for points which lie on same side.
Thus by the above condition, for $P$ to lie inside triangle, it must lie
on that side of $BC$ where $A$ lies
on that side of $AC$ where $B$ lies
on that side of $AB$ where $C$ lies
The intersection of these regions is the triangle.