check points inside triangle or on edge with example

조회 수: 26 (최근 30일)
Redwan Dan
Redwan Dan 2016년 4월 8일
답변: Gary Bikini 2021년 6월 12일
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
  댓글 수: 7
Roger Stafford
Roger Stafford 2016년 4월 9일
I've given the necessary expression as an "Answer" here. It doesn't seem like a very slow method to me.
Walter Roberson
Walter Roberson 2016년 4월 9일
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

댓글을 달려면 로그인하십시오.

채택된 답변

Roger Stafford
Roger Stafford 2016년 4월 9일
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.
  댓글 수: 5
T A
T A 2018년 11월 26일
편집: T A 2019년 8월 7일
UPDATED FOR CLARITY
With regard to assessing whether a point is on an edge/edges using the conditional statements given in Roger's answer,
  • P is on a triangle edge when one of the three conditional statements is zero
  • P is on a triangle vertex when two of the three conditional statements are zero
With regard to computational efficiency, the process can be costly if you're searching across many triangles. In such a case, the easiest thing to do is to only perform the calculations when P is within the bounding box of the current triangle:
Ptri=[P1;P2;P3];
if P(1)<=max(Ptri(:,1))&&P(1)>=min(Ptri(:,1))...
&&P(2)<=max(Ptri(:,2))&&P(2)>=min(Ptri(:,2))
%do the suggested calculations...
end
Evaluating this conditional statement is very, very cheap.
Muhamad Amirulfaris Abdullah
Muhamad Amirulfaris Abdullah 2019년 7월 6일
Hi there. what was the conditional statement that you were reffering to?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Gary Bikini
Gary Bikini 2021년 6월 12일
You can use the built-in function
[in,on]=inpolygon(xq,yq,xv,yv)

카테고리

Help CenterFile Exchange에서 Stochastic Differential Equation (SDE) Models에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by