# Is point $p$ in triangle $ABC$? [duplicate]

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?

• I think point $P$ is inside the triangle if $P = t A + t_1 B + t_2 C$ for $0\le t,t_1, t_2 \le 1$.
– user312097
Nov 7, 2017 at 13:44
• *what is t * P=tA+t1B+t2C for 0≤t,t1,t2≤1 Nov 7, 2017 at 13:54
• @SuhaibGhrear $P$ is the coordinate of point $P$ and $A,B,C$ are the coordinates of vertices of the triangle.
– user312097
Nov 7, 2017 at 14:07
• @SuhaibGhrear $t$ is just a real number.
– user312097
Nov 7, 2017 at 14:23
• Nov 7, 2017 at 14:29

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}.$

• Much better this way! +1 Nov 7, 2017 at 14:07

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 clearly not true. Atleast to me it doesn't seem to hold good for the $P$ shown in figure! Or if you can explain, Ill be happy. Nov 7, 2017 at 14:19
• Why it is not true for the point $P$ in the figure? Can you deny that the distance from $P$ to the parallel to $AB$ passing by the vertex $C$ is greater than the height of the triangle leaving the vertex $C$?. What is it "clearly" for you? Nov 7, 2017 at 15:53
• @samjoe: it could be good for you try to compare my hint with Amin's answer. Both are basically the same if you look at this with enough attention. Nov 7, 2017 at 16:12
• Well I didn't understand the first statement of your hint. But the rest of the answer seems fine to me now. Thanks for replying! I recommend you add an illustration, but I get the idea now! +1 Nov 8, 2017 at 10:44
• Agree. I added the illustration. Regards. Nov 8, 2017 at 12:29

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.