Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

map degrees to 0 - 360 in python

is it possible to map a value of rotation to be inside the range of 0-360 degrees?

For example:

  • a angle of -10° should be 350°
  • a angle of 760° should be 40° degrees?

Is there an easy solution? Maybe in mathutils?

best, chris

like image 476
Christoph Müller Avatar asked Aug 04 '15 22:08

Christoph Müller


People also ask

Is 360 degrees equal to 0 degrees?

Zero Angle. A 360 degree angle and a zero angle might look the same. This is because if an object rotates zero degrees or degrees, the end result is the same.

How do you find the degree of an angle in Python?

The angle is calculated by the formula tan-1(x/y). Parameters : z : [array_like] A complex number or sequence of complex numbers. deg : [bool, optional] Return angle in degrees if True, radians if False (default).

How do you normalize an angle?

Normalization of angles can be performed in two different ways. One method normalizes angles in the manner that longitudinal angles are normalized i.e., [0, 360.0) or [0, 2π) or [0, 24.0). The other method normalizes angles in the manner that latitudinal angles are normalized i.e., [-90, 90] or [-π/2, π/2].

What is the difference between 0 and 360?

For the purposes of designating a point in the plane, yes, 0 degrees equals 360 degrees.


1 Answers

You can use the modulo operator % for this:

>>> print -10 % 360
350
>>> print 760 % 360
40
like image 104
juanchopanza Avatar answered Sep 21 '22 18:09

juanchopanza