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

3 visualizaciones (últimos 30 días)
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?

Respuesta aceptada

Jan
Jan el 17 de Mzo. de 2011
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

Más respuestas (0)

Categorías

Más información sobre Phased Array Design and Analysis en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by