I have a matrix containing data for points on a vector v = [x;y]. let's say:
%
M = [v1_x1 v1_x2 v1_y1 v1_y2; v2_x1 v2_x2 v2_y1 v2_y2; v3_x1 v3_x2 v3_y1 v3_y2]
Where v1_x1 and v1_y1 are points of a the vector v1. v1_x2 and v1_y2 are the coördinates of the other point of the vector v1. For every vector there are two points known.
Now I want to find if any of those vectors intersect.
there is an intersection point when:
det(v1-v3,v2-v3)*det(v1-v4,v2-v4) < 0
or
det(v3-v1,v4-v1)*det(v3-v2,v4-v2) < 0
Where v1 = [x1;y1]
How can I implement this in a code

댓글 수: 7

Jan
Jan 2017년 9월 20일
편집: Jan 2017년 9월 20일
I do not see any lines. Do you mean if the rows share a common element?
If you want to use a determinant, what about using a determinant? See det. Or in other words: What is your actual question?
Joanie
Joanie 2017년 9월 20일
I edited my question.
Jan
Jan 2017년 9월 20일
Do you mean lines or vectors? Are these "lines" limited by the points or do they have an infinite length?
Joanie
Joanie 2017년 9월 20일
well let's call it a vector so it's limited by the points.
Joanie
Joanie 2017년 9월 20일
편집: Joanie 2017년 9월 20일
there is an intersection point when:
det(v1-v3,v2-v3)*det(v1-v4,v2-v4) < 0
or
det(v3-v1,v4-v1)*det(v3-v2,v4-v2) < 0
Where v1 = [x1;y1] (those are known points)
Walter Roberson
Walter Roberson 2017년 9월 20일
Roger Stafford has posted the code to determine intersection of line segments. It was probably about 16 months ago. I am on my phone so I cannot easily search for the post
Richard
Richard 2019년 4월 19일
I am unable to locate any code by Roger Stafford to determine line intersection. Based on other web searching, I believe the code might include a sweeping algorithm for intersection of 3D line segments. Can anyone help here?

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

답변 (1개)

Jan
Jan 2017년 9월 20일

1 개 추천

Do you have the mapping toolbox? If so, try https://www.mathworks.com/help/map/ref/polyxpoly.html.
But perhaps you do not mean the lines through the 2 points, but only the section from one point to the other.

댓글 수: 2

Joanie
Joanie 2017년 9월 20일
편집: Joanie 2017년 9월 20일
Thank you for the reaction. I eddited my question again because I meant the section from one point to the other. Now I explained the formula I want to use. I already used the function intersect([v1 v2], [v3 v4]) and it works but now i want to try it by using the determinant.
there is an intersection point when:
det(v1-v3,v2-v3)*det(v1-v4,v2-v4) < 0
or
det(v3-v1,v4-v1)*det(v3-v2,v4-v2) < 0
Where v1 = [x1;y1]
How can I write this into a matlab code
Jan
Jan 2017년 9월 21일
intersect compares the elements of the input vectors. This is not the intersection of the lines. You did not explain until now, if you mean the lines limited by the points, or the lines with infinite length through these points.

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

카테고리

도움말 센터 및 File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

질문:

2017년 9월 20일

댓글:

2019년 4월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by