Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Math
-
Why is it that when programming you have to convert angles to radians before any calculations?
I created an Excel spreadsheet a while ago that holds quite a few engineering calculations (fairly simple) that I use a lot. In doing so, anywhere trig and angles are used I had to convert any angle in degrees to radians to get the answer to come out correctly.
Then today I was creating a similar script in Pythonista and had to do the same thing.
Is there any way to set everything to degrees globally? -
-
I realize there is math.radians and math.degrees that does the same as radians = (degrees * 180)/pi and degrees = (radians * pi)/180.
I also realize that some people say that radians are required for certain calculations. But I’ve worked in engineering for almost 30 years and have done thousands upon thousands of calculations and have never, not even once, had the need to calculate anything using radians. So why are radians so prevalent in coding especially? -
@OkieWolf, degrees are a ”human” measure based on a convention. The number 360 is completely arbitrary, even if it was decided on by ancient Babylonians and by now ”feels right” to most of us, myself included.
There are other systems, for example dividing a quarter of a circle in 100 units instead of 90, but they are equally arbitrary, partly based on the fact that we have 10 fingers.
Radians, on the other hand, are ”scientific”. They are an inherent property of a circle, since the angle of 1 radian corresponds to traveling the distance of the circle’s radius around the circle. Thus radians are radians whatever humans decide.
-
Radians are much more natural when computing sin/cos's.
sin(x) = x - x**3/3! + x**5/5! - ....
So, small angles are easy to work with in radians, because sin(x) = x. Also, from a beauty perspective, sin and cosine are defined this way -- using any other unit results in ugly equations, which therefore are less fundamental.
Consider other branches of physics/engineering where you deal with oscillators/wave equations. There you have sins/cos's of other unitless quantities, such as frequency times time, or distance divided by wavelength -- things get really clumsy if everything must be defined in degrees.
Degrees really only ever make sense when talking about geometrical things, though arguably "revolutions" is a more fundamental / intuitive concept..
-
Btw, you can of course define your own wrappers for sind/cosd (sin or cos in deg)!
sind=lamda x:math.sin(math.radians(x)) print(sind(90))