Clear Filters
Clear Filters

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

22 views (last 30 days)
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
David Goodmanson
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.

Sign in to comment.

Answers (1)

James Tursa
James Tursa on 31 Mar 2023




Community Treasure Hunt

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

Start Hunting!