フィルターのクリア

Find intersection point of two lines when I have their coordinates ?

68 ビュー (過去 30 日間)
Suman Debnath
Suman Debnath 2017 年 5 月 20 日
コメント済み: Dimitar Slavchev 2021 年 3 月 18 日
I have four COORDINATES of two lines - [x1,y1], [x2,y2], [x3,y3], [x4,y4]. Now, how to get the coordinate of their intersecting point [x,y] ? Any help ??
  4 件のコメント
Suman Debnath
Suman Debnath 2017 年 5 月 22 日
John, I did it. But I think the equation is too long. So, I just wanted to know if there is any short form of that or not.
Jan
Jan 2017 年 5 月 22 日
@Suman: Yes, there is a short form. Did you read the link posted by John? This is an exhaustive solution already. Making an effort means also, to ask an internet search engine.

サインインしてコメントする。

採用された回答

Roger Stafford
Roger Stafford 2017 年 5 月 23 日
編集済み: Roger Stafford 2017 年 5 月 23 日
The result of the three steps I mentioned would be:
xy = [x1*y2-x2*y1,x3*y4-x4*y3]/[y2-y1,y4-y3;-(x2-x1),-(x4-x3)];
I don’t consider that too long or complicated an expression. The xy variable here is a 1-by-2 vector consisting of the x and y coordinates of the intersection.
  1 件のコメント
Dimitar Slavchev
Dimitar Slavchev 2021 年 3 月 18 日
For the edge cases:
Where the two lines are the same line you will get NaNs:
>> LineIntersect(0,0,1,1,0,0,1,1)
Warning: Matrix is singular to working precision.
> In LineIntersect (line 11)
ans =
NaN NaN
And for parallel lines, Infinity:
>> LineIntersect(0,0,1,1,0,1,1,2)
Warning: Matrix is singular to working precision.
> In LineIntersect (line 11)
ans =
-Inf -Inf
LineIntersect is just the above formula from Roger Stafford inside a function. The line is 11, because of comments.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by