Hi, I have four coplanar points P1, P2, P3 and P4 in 3d. I would like to calculate the intersection point among the line passing through P1 and P2 and that passing through P3 and P4.
Moreover I would like to evaluate the angle between the vector connecting such intersection and the origin with z-axis and then plot the vector.

 採用された回答

Matt J
Matt J 2021 年 9 月 21 日
編集済み: Matt J 2021 年 9 月 21 日

0 投票

You need a least squares solution, since lines in 3D do not generally intersect. Assuming your point data are in column-vector form, this is,
c=[P2-P1,P3-P4]\(P3-P1);
P_intersection=P1+c(1)*(P2-P1)
angle=acos(P_intersection(3)/norm(P_intersection))

6 件のコメント

Gaetano Pavone
Gaetano Pavone 2021 年 9 月 21 日
編集済み: Gaetano Pavone 2021 年 9 月 21 日
I have edited my question @Matt J
Matt J
Matt J 2021 年 9 月 21 日
編集済み: Matt J 2021 年 9 月 21 日
I don't see anything new in the phrasing of the post that would change my answer. Did you try it?
You seem to have added that your 4 points are ideally coplanar, but that simply isn't a reliable assumption, in general. If P1...P4 were generated by floating point calculations, they will contain floating point errors that effectively render the points non-coplanar. It doesn't matter, though. My solution should work whether the data is ideally coplanar or not.
Gaetano Pavone
Gaetano Pavone 2021 年 9 月 21 日
I have added a request: plot the vector from the origin to the intersection point
Matt J
Matt J 2021 年 9 月 21 日
You can use the line() command to plot the vector. If you want the vector to appear as an arrow, you can use
or other similar File Exchange offerings.
Gaetano Pavone
Gaetano Pavone 2021 年 9 月 21 日
For
P1=[735;234;1397];
P2=[234;735;1397];
P3=[-265;234;1397];
P4=[234;-265;1397];
c=[P2-P1,P3-P4]\[-P1,P3];
P_intersection=P1+c(1)*(P2-P1);
angle=acos(P_intersection(3)/norm(P_intersection));
it doesn't give me the correct answer.
P_intersection should be [234;234;1397].
Matt J
Matt J 2021 年 9 月 21 日
編集済み: Matt J 2021 年 9 月 21 日
You seem to have had P2 and P3 interchanged.
P1=[735;234;1397];
P3=[234;735;1397];
P2=[-265;234;1397];
P4=[234;-265;1397];
c=[P2-P1,P3-P4]\(P3-P1); %edited
P_intersection=P1+c(1)*(P2-P1)
P_intersection = 3×1
234 234 1397

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

その他の回答 (0 件)

カテゴリ

製品

リリース

R2020a

タグ

質問済み:

2021 年 9 月 21 日

編集済み:

2021 年 9 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by