+ 1

Radians & Degrees. Python math library.

I like to use Degrees, but Python's math library likes to use Radians, is there any shortcuts for math to be able to make it receive Degrees instead, I don't like to convert Degrees to Radians when I use math's trigonometric methods.

9th Jan 2019, 9:12 PM
Seb TheS
Seb TheS - avatar
5 Respuestas
+ 3
One way is to use decorators to make "modifications" of original functions. You can create your own module to reuse it. There are about 10 trigonometric functions in 'math', so it won't be a problem.
9th Jan 2019, 10:06 PM
portpass
+ 2
It's better to just get used it, it's that way in pretty much any programming language! It's super straightforward if you create a constant `pi2 = math.pi * 2`. Then all you have to do is think in *fractions of a whole circle* instead of steps of 90 degrees or whatever. A right angle? That's 1/4th of a whole circle, or `1/4 * pi2`. 45 degrees? That's 1/8th of a whole circle, or `1/8 * pi2`. It's even easier than degrees.
9th Jan 2019, 10:03 PM
Schindlabua
Schindlabua - avatar
+ 1
portpass That's how I would have done it.
11th Jan 2019, 9:29 AM
Seb TheS
Seb TheS - avatar
+ 1
Schindlabua Maybe it could be good choise aswell, when I quickly want to do some testings with the trigonometric functions I rather not fumble with radians.
11th Jan 2019, 9:32 AM
Seb TheS
Seb TheS - avatar
+ 1
math library has 2 methods: radians and degrees, which can be used to convert them to each others.
24th Feb 2019, 1:39 PM
Seb TheS
Seb TheS - avatar