Intersection of two triangles

조회 수: 7 (최근 30일)
Ines
Ines 2016년 4월 19일
댓글: Ines 2016년 4월 19일
Hi If I have the vertexes of two triangles, how can I check if they intersect or not? I need a function that just gives me true if they intersect and false if not. Iif one of them is inside the other one, it shoud consider it an intersection. I found this coder, but it gives me empty result if one is inside the other one. % this define the vertexes (x,y) of first triangle trian1x =[ 0 0.5 1 0]; trian1y =[ 0 1 0 0]; % this define the vertexes (x,y) of second triangle trian2x =[ 0 0.25 0.5 0]; trian2y =[ 0 0.5 0 0]; % (xi,yi) are the intersection points [xi,yi] = polyxpoly(trian1x,trian1y,trian2x,trian2y,'unique'); figure, plot(trian1x,trian1y,'b') hold on plot(trian2x,trian2y,'r') hold on plot(xi,yi,'*g')
Thanks

채택된 답변

Roger Stafford
Roger Stafford 2016년 4월 19일
편집: Roger Stafford 2016년 4월 19일
Just combine the 'polyxpoly' result with two applications of 'inpoly' to test if either set of triangle vertices lies within the other triangle. If there are no intersection points from 'polyxpoly' and the results of 'inpoly' are all negative, then the triangles don't intersect.
  댓글 수: 1
Ines
Ines 2016년 4월 19일
Thank you so much. It works perfectly :)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by