# How can I find angle between two vectors in 3D ranging from 0 to 360 or -180 to +180?

22 views (last 30 days)
K M RIZWANUR RAHMAN on 6 Sep 2018
Answered: James Tursa on 31 Mar 2023
I already saw some similar questions and applied those answers. But the problem is that I can't get the angle with directional information. For example, I've used atan2d(norm(cross(v1,v2)),dot(v1,v2)) command, but it gave me the angle in between 0 to 180 degree. I want to get the angle ranging from 0 to 360 (-180 to +180 will also work). I will be really grateful if someone helps me in this regard.
NB: the vectors are in 3D space
##### 3 CommentsShow 1 older commentHide 1 older comment
David Goodmanson on 8 Sep 2018
Hi K M,
How do you define an angle between two 3d vectors to be in the range from -180 to 180? Assume you find the plane such that both vectors lie in that plane. Let's say that in that plane, vector v2 is counterclockwise from vector v1 by 45 degrees. Suppose ccw angles are defined as positive, so the angle is +45. If you go around and look at the plane from the back side, now v2 is clockwise from v1, which is an angle of -45. Both views are equally valid, so how do you distinguish between them?
The only way is to define a unit normal to the plane in some fashion, and to require that the unit normal is pointing e.g. out of the page. The only available unit normal comes from the cross product (v1 x v2). If you orient the plane with that unit normal out of the page, then in that view v2 is always counterclockwise from v1 by an angle between 0 and +180 degrees. A range from -180 to 180 does not happen. Same argument for 0 to 360 since it is merely a constant offset from -180 to 180.
K M RIZWANUR RAHMAN on 10 Sep 2018
Thanks a lot guys.. It helped me to find the way to solve the problem.. :) :)

James Tursa on 31 Mar 2023

### Categories

Find more on Lengths and Angles in Help Center and File Exchange

R2018a

### Community Treasure Hunt

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

Start Hunting!