MATLAB Answers


How to get direction for 3d angles between 2 vectors

Archa Rajagopalan さんによって質問されました 2019 年 5 月 10 日
最新アクティビティ Archa Rajagopalan さんによって コメントされました 2019 年 5 月 12 日
I have 2 3D vectors lying on a 3D plane, and I want to find the angle between them.
How can I find both the angles measured clockwise and counterclockwise (a positive and negative angle)?
I've tried using atan2d(norm(cross(v1,v2)), dot(v1,v2)), as to my understanding returns a negative angle if the angle is greater than 180 deg. However, it still only returns the smallest positive angle that is smaller than 180 deg. Changing the order of v1 and v2 doesn't make a difference either.
Thanks for all replies! I greatly appreciate it.

  0 件のコメント

サインイン to comment.


1 件の回答

James Tursa
回答者: James Tursa
2019 年 5 月 10 日

You will need to define in your code which direction is the clockwise and which is counterclockwise. You can do that by defining up front a normal vector to your 3D plane that can be used to distinguish this. E.g., something like
PlaneNorm = a 3-element vector defining the normal to the 3D plane for counterclockwise direction
ang = atan2d(norm(cross(v1,v2)), dot(v1,v2)); % angle without regard to "direction"
if( dot(cross(v1,v2),PlaneNorm) < 0 ) % if v1 X v2 is on the other side of the plane
ang = 360 - ang; % modify based on desired "direction"

  1 件のコメント

Archa Rajagopalan 2019 年 5 月 12 日
Thank you!

サインイン to comment.

Translated by