3
$\begingroup$

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

$\endgroup$
5
  • $\begingroup$ 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$. $\endgroup$
    – user312097
    Nov 7, 2017 at 13:44
  • 1
    $\begingroup$ *what is t * P=tA+t1B+t2C for 0≤t,t1,t2≤1 $\endgroup$ Nov 7, 2017 at 13:54
  • $\begingroup$ @SuhaibGhrear $P$ is the coordinate of point $P$ and $A,B,C$ are the coordinates of vertices of the triangle. $\endgroup$
    – user312097
    Nov 7, 2017 at 14:07
  • $\begingroup$ @SuhaibGhrear $t$ is just a real number. $\endgroup$
    – user312097
    Nov 7, 2017 at 14:23
  • $\begingroup$ See math.stackexchange.com/questions/190111/… $\endgroup$ Nov 7, 2017 at 14:29

3 Answers 3

4
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ Much better this way! +1 $\endgroup$
    – jonsno
    Nov 7, 2017 at 14:07
1
$\begingroup$

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

$\endgroup$
5
  • $\begingroup$ 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. $\endgroup$
    – jonsno
    Nov 7, 2017 at 14:19
  • $\begingroup$ 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? $\endgroup$
    – Piquito
    Nov 7, 2017 at 15:53
  • $\begingroup$ @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. $\endgroup$
    – Piquito
    Nov 7, 2017 at 16:12
  • $\begingroup$ 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 $\endgroup$
    – jonsno
    Nov 8, 2017 at 10:44
  • $\begingroup$ Agree. I added the illustration. Regards. $\endgroup$
    – Piquito
    Nov 8, 2017 at 12:29
0
$\begingroup$

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.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged .