Hi,
I have 2 triangles and I would like to know if they are inside each others or they intersect. Like the picture How I can do that ? I read about polyxpoly but to be honest I don't understand how to use it in this scenario.

 채택된 답변

Marta Salas
Marta Salas 2014년 4월 3일

3 개 추천

% 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')

댓글 수: 5

Sososasa
Sososasa 2014년 4월 3일
편집: Sososasa 2014년 4월 3일
Hi Marta,
This gives me the intersection points even when one triangle is lie inside the other. And I only need to get the intersection points if one of them is not contained inside the other.
If I get the intersection point in both situations, then I can not decide if one of them is actually inside the other or not.
Marta Salas
Marta Salas 2014년 4월 3일
편집: Marta Salas 2014년 4월 3일
You can decide whether it's inside or not checking if the intersection points correspond to the triangle vertexes.
Sososasa
Sososasa 2014년 4월 4일
Yap I did that thanks a lot :)
Ines
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. Thanks
Yash Jangir
Yash Jangir 2020년 8월 21일
what if there are no intersection points but the triangle is completely inside the other triangle?

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

추가 답변 (1개)

Rushabh Khattri
Rushabh Khattri 2017년 8월 22일

0 개 추천

I am getting this error :- Undefined function 'polyxpoly' for input arguments of type 'double'.

댓글 수: 2

Jan
Jan 2017년 8월 22일
The first point to start is asking an internet search engine for this term: "Matlab polyxpoly". You will find out, that this command belongs to the Mapping Toolbox: https://www.mathworks.com/help/map/ref/polyxpoly.html. It seems like you do not have a license for this toolbox and then you need a different solution. Please open a new thread then.
John D'Errico
John D'Errico 2017년 8월 22일
This is not an answer. It is only a new question, but resurrecting a zombie question, that is only partially related.

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

카테고리

도움말 센터File Exchange에서 Triangulation Representation에 대해 자세히 알아보기

질문:

2014년 4월 3일

댓글:

2020년 8월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by