intersection of two triangles (2024)

9 views (last 30 days)

Show older comments

Sososasa on 3 Apr 2014

  • Link

    Direct link to this question

    https://www.mathworks.ca/matlabcentral/answers/124271-intersection-of-two-triangles

  • Link

    Direct link to this question

    https://www.mathworks.ca/matlabcentral/answers/124271-intersection-of-two-triangles

Commented: Yash Jangir on 21 Aug 2020

Accepted Answer: Marta Salas

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.

intersection of two triangles (2)

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

Accepted Answer

Marta Salas on 3 Apr 2014

  • Link

    Direct link to this answer

    https://www.mathworks.ca/matlabcentral/answers/124271-intersection-of-two-triangles#answer_131829

  • Link

    Direct link to this answer

    https://www.mathworks.ca/matlabcentral/answers/124271-intersection-of-two-triangles#answer_131829

% 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 Comments

Show 3 older commentsHide 3 older comments

Sososasa on 3 Apr 2014

Direct link to this comment

https://www.mathworks.ca/matlabcentral/answers/124271-intersection-of-two-triangles#comment_205802

  • Link

    Direct link to this comment

    https://www.mathworks.ca/matlabcentral/answers/124271-intersection-of-two-triangles#comment_205802

Edited: Sososasa on 3 Apr 2014

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 on 3 Apr 2014

Direct link to this comment

https://www.mathworks.ca/matlabcentral/answers/124271-intersection-of-two-triangles#comment_205812

  • Link

    Direct link to this comment

    https://www.mathworks.ca/matlabcentral/answers/124271-intersection-of-two-triangles#comment_205812

Edited: Marta Salas on 3 Apr 2014

You can decide whether it's inside or not checking if the intersection points correspond to the triangle vertexes.

Sososasa on 4 Apr 2014

Direct link to this comment

https://www.mathworks.ca/matlabcentral/answers/124271-intersection-of-two-triangles#comment_206178

  • Link

    Direct link to this comment

    https://www.mathworks.ca/matlabcentral/answers/124271-intersection-of-two-triangles#comment_206178

Ines on 19 Apr 2016

Direct link to this comment

https://www.mathworks.ca/matlabcentral/answers/124271-intersection-of-two-triangles#comment_360084

  • Link

    Direct link to this comment

    https://www.mathworks.ca/matlabcentral/answers/124271-intersection-of-two-triangles#comment_360084

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 on 21 Aug 2020

Direct link to this comment

https://www.mathworks.ca/matlabcentral/answers/124271-intersection-of-two-triangles#comment_981407

  • Link

    Direct link to this comment

    https://www.mathworks.ca/matlabcentral/answers/124271-intersection-of-two-triangles#comment_981407

what if there are no intersection points but the triangle is completely inside the other triangle?

Sign in to comment.

More Answers (1)

Rushabh Khattri on 22 Aug 2017

  • Link

    Direct link to this answer

    https://www.mathworks.ca/matlabcentral/answers/124271-intersection-of-two-triangles#answer_278812

  • Link

    Direct link to this answer

    https://www.mathworks.ca/matlabcentral/answers/124271-intersection-of-two-triangles#answer_278812

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

2 Comments

Show NoneHide None

Jan on 22 Aug 2017

Direct link to this comment

https://www.mathworks.ca/matlabcentral/answers/124271-intersection-of-two-triangles#comment_478753

  • Link

    Direct link to this comment

    https://www.mathworks.ca/matlabcentral/answers/124271-intersection-of-two-triangles#comment_478753

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 on 22 Aug 2017

Direct link to this comment

https://www.mathworks.ca/matlabcentral/answers/124271-intersection-of-two-triangles#comment_478803

  • Link

    Direct link to this comment

    https://www.mathworks.ca/matlabcentral/answers/124271-intersection-of-two-triangles#comment_478803

This is not an answer. It is only a new question, but resurrecting a zombie question, that is only partially related.

Sign in to comment.

Sign in to answer this question.

See Also

Categories

MATLABGraphics2-D and 3-D PlotsSurfaces, Volumes, and PolygonsSurface and Mesh Plots

Find more on Surface and Mesh Plots in Help Center and File Exchange

Tags

  • intersection
  • polygon

Products

  • Mapping Toolbox

Community Treasure Hunt

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

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


intersection of two triangles (12)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

Europe

Asia Pacific

Contact your local office

intersection of two triangles (2024)
Top Articles
Latest Posts
Article information

Author: Moshe Kshlerin

Last Updated:

Views: 5830

Rating: 4.7 / 5 (77 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Moshe Kshlerin

Birthday: 1994-01-25

Address: Suite 609 315 Lupita Unions, Ronnieburgh, MI 62697

Phone: +2424755286529

Job: District Education Designer

Hobby: Yoga, Gunsmithing, Singing, 3D printing, Nordic skating, Soapmaking, Juggling

Introduction: My name is Moshe Kshlerin, I am a gleaming, attractive, outstanding, pleasant, delightful, outstanding, famous person who loves writing and wants to share my knowledge and understanding with you.