Intersection of two triangles

7 vues (au cours des 30 derniers jours)
Ines
Ines le 19 Avr 2016
Commenté : Ines le 19 Avr 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

Réponse acceptée

Roger Stafford
Roger Stafford le 19 Avr 2016
Modifié(e) : Roger Stafford le 19 Avr 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 commentaire
Ines
Ines le 19 Avr 2016
Thank you so much. It works perfectly :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Lighting, Transparency, and Shading dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by