Angle betwen two 3d vectors in the range 0-360 degree

156 ビュー (過去 30 日間)
UWM
UWM 2020 年 1 月 22 日
コメント済み: Jan 2022 年 2 月 23 日
I have set of two 3d vectors lying on the same plane. I would like to calculate
angles betwen each of these pairs, but in the "full" angle range: from 0 to 360 degree.
Using formula:
Angle = atan2d(norm(cross(v1,v2)),dot(v1,v2));
give me always angle in the rang from 0 to 180 degree, even if the second vector lies
on the right side of the first one.
How could this be improved?
  4 件のコメント
James Tursa
James Tursa 2020 年 1 月 22 日
@UWM: You will need to define the method for calculating this full range angle. I.e., you need to pick a normal vector on one side of the plane and use that to determine this full range angle, along with a method for choosing which vector is "first". Have you done that?
UWM
UWM 2020 年 1 月 23 日
Thanks for clarification. I will try to do this according your tips.

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

採用された回答

James Tursa
James Tursa 2020 年 1 月 23 日
編集済み: James Tursa 2020 年 1 月 23 日
E.g., here is one method:
function a = vecangle360(v1,v2,n)
x = cross(v1,v2);
c = sign(dot(x,n)) * norm(x);
a = atan2d(c,dot(v1,v2));
end
This is a simple (non-vectorized) function that takes two input vectors v1 and v2, and a vector n that is not in the plane of v1 & v2. Here n is used to determine the "direction" of the angle between v1 and v2 in a right-hand-rule sense. I.e., cross(n,v1) would point in the "positive" direction of the angle starting from v1. A sample run:
>> v1 = [2; 0; 0];
>> v2 = [1; 1; 0];
>> p = [0; 0; 1]; % The v1 & v2 plane normal vector
>> vecangle360(v1,v2,p)
ans =
45
>> vecangle360(v1,v2,-p)
ans =
-45
>> vecangle360(v2,v1,p)
ans =
-45
>> vecangle360(v2,v1,-p)
ans =
45
So you can see that the method returns an angle "from" the first vector "to" the second vector using a right-hand-rule with the n vector. It will be in the range -180 to 180, so if you really need 0 - 360 you will need to modify the result.
  3 件のコメント
Erik
Erik 2022 年 2 月 23 日
I have found several examples of this solution online through searching but they never explain how you get the plane normal vector.
>> p = [0; 0; 1]; % The v1 & v2 plane normal vector
Where does this come from? How do I calculate it?
Jan
Jan 2022 年 2 月 23 日
The vector cross(x,y) is perpendicular to the vectors x and y. If you normalize it, it is the orthonormal vector to the plane built by the vectors x and y.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDiscrete Data Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by