Angles calculated using atan function are -ve. How to represent it in terms of pi

조회 수: 3 (최근 30일)
I have used atan function and calculate angle between two vectors. The angle returned by this function is -ve in nature. I want to represent the angle in terms of pi; that is, the value of angle must be between 0 and 2*pi.
What to do?

채택된 답변

Jan
Jan 2011년 3월 17일
I do not know the term "-ve".
You cannot determine the sign of an angle between two vectors without further information. Imagine two 3D vectors: You can measure the enclosed angle only, which is always 0 <= angle <= pi/2. If you want a sign, you need a third vector to define an orientation. If you talk about 2D vectors, the global Z-axis [0, 0, 1] is this third vector usually. Then using ATAN2 is recommended, but replies a signed angle also: -pi <= angle < pi.
To get 0 <= angle < 2*pi, you could add the wanted shift value:
index = (angle < 0);
angle(index) = 2*pi + angle(index);
See also this famous CSSM thread: Angle between two vectors

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Phased Array Design and Analysis에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by