Hi everybody,
i have two 3D straight lines as follow:
the line "S1" passing through the points A=[3,7,9] and B=[4,5,8]
and the line "S2" passing through the points A=[3,7,9] and C=[4,5,0].
How can i calculate the angle between S1 and S2.
Thank you very much!
Riccardo

 採用された回答

Jan
Jan 2019 年 7 月 16 日
編集済み: Jan 2020 年 10 月 21 日

2 投票

A = [3,7,9];
B = [4,5,8];
C = [4,5,0];
S1 = B - A;
S2 = C - A;
Theta = atan2(norm(cross(S1, S2)), dot(S1, S2));
W. Kahan suggested in his paper "Mindless.pdf":
2 * atan(norm(S1 * norm(S2) - norm(S1) * S2) / ...
norm(S1 * norm(S2) + norm(S1) * S2))
Both methods are more stable than appraoches using ACOS(DOT) or ASIN(CROSS).

4 件のコメント

Riccardo Rossi
Riccardo Rossi 2019 年 7 月 16 日
Thank you for your answer. Result is in degree or radians?
Bruno Luong
Bruno Luong 2019 年 7 月 16 日
This Kahan's formula seems to be clever.
Anthony Dave
Anthony Dave 2020 年 10 月 15 日
Thanks, Jan. The result angle would change if I change the vector's direction. For example, S2 = A - C. And the two angles I got are mutual supplementary angles. But if it is a polygon with several lines, how can I accurately get its internal angles?
Jan
Jan 2020 年 10 月 18 日
@Anthony Dave: The unique definition of a polygon requires the defined order of its vertices. If you e.g. swap two neighboring vertices of a square, the angles are 45° instead of 90°.
This means, that you have to stay at the same order of vertices and changing the view by something like "S2 = A - C" is not allowed. But even then, the included angle is replied and this is < 180 in every case. In a polygon you can have angles > 180 between oriented edges. Then you have to include the information about the polygon's normal N also:
S1xS2 = cross(S1, S2);
Theta = atan2(norm(S1xS2), dot(S1, S2)) * sign(dot(S1xS2, N));

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

製品

リリース

R2018b

質問済み:

2019 年 7 月 16 日

編集済み:

Jan
2020 年 10 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by