Intersection of two triangles

7 次查看(过去 30 天)
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.

更多回答(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