Why Are Numpy and Math Library Trig Function Arguments in Radians?

Hello,

as I am using trigonometric functions for an app, I find myself converting degrees to radians. Being that humans have a more natural feel for degrees, why are trigonometric arguments required in radians? Now, for any trigonometric function, I have to create an interface function to make the degree to radian conversion.

The C standard library trigonometric functions use radians, and the math module is designed to closely mimic that API. Also, from a maths perspective the radian version of the trigonometric functions is often the most natural version.

1 Like

Can someone move this to Python Help?

The division of one turn into 360 degrees is purely arbitrary.

Mathematically, radians make more sense.

Compare the common logarithm (base 10) with the natural logarithm (base e).

The natural logarithm has a mathematical reason behind it, whereas the common logarithm exists purely because we’re used to working in base 10 because we happen to have 10 fingers (usually).

1 Like

@ajoino / @MRAB

I underestand your arguments. However, from a user (human - app end user), radians is not natural.

Example:

A guy designing a staircase / ramp. He wants the rise over run to be 3 to 8, or 20.6 degrees. He’s not going to think of that as having an angle of 0.3595 radians. Degrees are more intuitive.

trig_conversion

On an unrelated note, when I attempted to enter the Python script via the back-ticks or the preformatted text tool, the portal freezes up. This is why I attached the test script via a screenshot.

Arguing what is most natural from a human perspective is not gonna change things. I think radians is more natural due to my background, others think degrees and for slopes specifically I often hear that described in percentages (I forget that system’s name). No matter what one might think the API is set in stone at this point.

There are a couple of things you can do to, for example you can recreate matlab’s sind, cosd etc functions that are the degree versions of trig functions. You can use the math.radians function if you want the conversion to look nicer.

So for that use case, degrees are just as arbitrary as radians.

4 Likes

Yes, this generally applies to roads built on slopes of hills.

1 Like

The name is “grads”, where 90 degrees is the same as 100 grads. Some “scientific calculators” offer “grad mode” as well as “degree mode” and “radian mode”. The last is usually the default, due to that radians are by far most common in math.

For example, the beautiful and fundamental identity

e^{i\theta} = \cos{\theta} + i \sin{\theta}

is only true if \theta is expressed in radians. Similarly so for many even simpler identities, such as that the derivative of the sine function is the cosine function. Use anything other than radians, and they all get messier with no compensating advantage.

Notwithstanding which, yes, I’m sure that working in degrees would be least astonishing to the bulk of “just folks”. I often use them myself, but typically for the inverse trig functions. After decades, I still find it far easier to picture what 60 degrees means than the equivalent 1.0471975511965976 radians :wink:.

4 Likes

I’m not talking about grads iiuc, I mean rise over run times 100, Wikipedia just calls it slope. Grads is something I’ve never had to use, but it was brought in high school at some point. Also yeah radians in decimal is uhh tricky to interpret to say the least, but when it’s expressed in multiples of pi (or tau for those like it) it’s pretty darn nice.

I think a half-serious proposal would be to add sind and its relatives to the math module. Matlab has them and while I don’t think the existing functions should change, adding new ones could happen.

1 Like

Wouldn’t you get that by calling atan2 (or maybe asin if your definition of “run” is the angled distance)? It shouldn’t matter what the unit of angle is, as long as the module is consistent (which it is).

1 Like

My response was to Tim, I think he misunderstood me or I misunderstood him, but I see I didn’t respond to him directly. Sorry for the confusion!

1 Like

Thanks! I stand corrected. I think another name for that is “percent grade”. For example, a 45 degree angle is 50 grads, but a percent grade (“slope”) of 100.

Let me guess that wasn’t in the US? I don’t think grads ever caught on in America.

Which is yet another way to approach these functions. Some languages and packages offer, e.g., a sinpi() function, where \mathrm{sinpi}\enspace x = \sin{\pi x} but “in effect” using an infinitely precise value for \pi. That also has real benefits for speed, because the internal implementation of “argument reduction” becomes very much simpler.

I expect it’s more likely that the sinpi() (etc) functions will eventually get added, because they were first made optional in the C language (“C99”), and later made mandatory in C23.

OTOH, while Python’s path isn’t nearly so wedded to C’s as it was in the early days, what the C committees do still carry weight. They still haven’t introduced any trig functions (not even optional) that work in degrees.

Pretty much, but

Percent Grade = tan(atan2(rise, run)) * 100

can be simplified to plaln old

Percent Grade = (rise / run) * 100

No “trig functions” of any kind are actually needed.

Yes, but I’m assuming the OP then needs to do other calculations like “how long will the ramp be”, which will need further trig functions. Well, that might not be a good example, since that’s just Pythag, but whatever else you need to calculate might require actual trig.

Actually, given the problem description of building a ramp with a known rise and run, I am having trouble figuring out something that (a) requires trig, but also (b) doesn’t require something more complicated (like “how long a ramp will we need in order to ensure that the vertical curve radius never exceeds X”). But that’s a lack of imagination my part, most likely.

1 Like

Yeah, I’m from Sweden. Although I think the reason it was brought up as a curiosity is that I went to a high school programme in math, I doubt it was mentioned in other programmes.

1 Like

In real life, they’ll certainly need to care about angular units. When it comes time to build that ramp, they’ll need to use surveying implements to guide the construction from start to finish, and those are, at heart, all about measuring angles with precision. Whether they also need “trig functions” isn’t really interesting to me :wink:. AFAIK, for human use most surveying implements report results in “degrees + minutes + seconds” format, based on 360 degrees in a circle, 60 minutes in a a degree, and 60 seconds in a minute. If those are fed into computer programs for “deep analysis”, they’ll get converted to radians.

Sometimes when the decision making is delegated to the contractor, rise over run is practical. When the customer wants more direct control, degrees is the default - they are familiar with degrees (in most cases verses: “I want the ramp / side wall to have a 0.753 radian angle).

A practical example (for those of you stateside and who are familiar with shows like “Flip this House”, and the like), sometimes decisions are made on the fly. You need to build a side wall that is 32 feet in length at an angle of 6 degrees (from an initial starting height offset of say 4 feet), the question posed is then: “How much material in total are we going to need? What would be the final height. Or, given a final height requirement of x feet, and initial height of y feet, what is the required angle"?, …, etc. The questions will vary based on the situation. So needs to be pretty flexible.

No biggie. I know, it is just one extra line of code for each trig function which is not a showstopper. However, I was just wondering as to why there aren’t degree parameter trig functions since that is what the general public is most familar with.

It is true that you can deal with radians. But for me at least, it is for the most common: π, π/2, π/4, 3π/4, etc., that I am ok with. Otherwise, I revert to degrees.

1 Like