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

조회 수: 9 (최근 30일)
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
David Goodmanson
David Goodmanson 2018년 9월 8일
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
K M RIZWANUR RAHMAN 2018년 9월 10일
Thanks a lot guys.. It helped me to find the way to solve the problem.. :) :)

댓글을 달려면 로그인하십시오.

답변 (1개)

James Tursa
James Tursa 2023년 3월 31일

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by