check points inside triangle or on edge with example

62 views (last 30 days)
Good evening everyone
function or coding for finding point is inside triangle or sub triangle or its on edges
thanks for involving your knowledge to be share to answer question
Walter Roberson
Walter Roberson on 9 Apr 2016
Redwan Dan comments to John D'Errico:
am not here to prove you any thing and the way your answer and close is not nice treat with me if you don't know just don't comment or close

Sign in to comment.

Accepted Answer

Roger Stafford
Roger Stafford on 9 Apr 2016
Suppose P1 = [x1,y1], P2 = [x2,y2], and P3 = [x3,y3] are row vectors giving the coordinates of the three vertices of a triangle, and P = [x,y] is a row vector for the coordinates of a point P. To determine whether P lies inside the triangle P1P2P3 do this:
P12 = P1-P2; P23 = P2-P3; P31 = P3-P1;
t = sign(det([P31;P23]))*sign(det([P3-P;P23])) >= 0 & ...
sign(det([P12;P31]))*sign(det([P1-P;P31])) >= 0 & ...
sign(det([P23;P12]))*sign(det([P2-P;P12])) >= 0 ;
Point P lies within the triangle if and only if t is true.
Muhamad Amirulfaris Abdullah
Hi there. what was the conditional statement that you were reffering to?

Sign in to comment.

More Answers (1)

Gary Bikini
Gary Bikini on 12 Jun 2021
You can use the built-in function


No tags entered yet.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!