3

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? enter image description here

Teddy38
  • 3,309

3 Answers3

4

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

Amin
  • 2,103
1

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.

enter image description here

Piquito
  • 29,594
  • 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. – jonsno Nov 07 '17 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? – Piquito Nov 07 '17 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. – Piquito Nov 07 '17 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 – jonsno Nov 08 '17 at 10:44
  • Agree. I added the illustration. Regards. – Piquito Nov 08 '17 at 12:29
0

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.

jonsno
  • 7,521