Intersection of two triangles

7 views (last 30 days)
Ines
Ines on 19 Apr 2016
Commented: Ines on 19 Apr 2016
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

Accepted Answer

Roger Stafford
Roger Stafford on 19 Apr 2016
Edited: Roger Stafford on 19 Apr 2016
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 Comment
Ines
Ines on 19 Apr 2016
Thank you so much. It works perfectly :)

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!