0

Why does many programming langues work in radians? It's seems a little counter intuitive and hard to visualize in my opinion, and many beginner's (including my own) questions have to do with not knowing that they return and take arguments in radians.

Edit:

I understand how radians are useful and can be better than degrees, but why in programming? This relies on irrational number constants stored in computers, instead of integers.

When using built in functions, we assume the computer knows that 3.14159265 is close enough to pi that cos and sin will return proper values, but there is still a lot of room for rounding errors, but it isn't an issue with degrees.

As well as this, 270 has an exact representation in binary, 3*pi/2 is an irrational number and can therefore only be approximated to a certain precision.

Kyranstar
  • 1,650
  • 2
  • 14
  • 35

3 Answers3

4

You state:

Why does Java's math lib work in radians? It's seems a little counter intuitive in my opinion,...

I believe that the exact opposite is true since radians are a much more realistic and mathematically appropriate way of describing angles. Degrees define an angle using an arbitrary number, while radians correspond to the length of the arc subtended by the angle. Your argument is thus invalid. Also it's easy to convert via Math.toDegrees(...) or Math.toRadians(...)

Regardless your question is asking for an opinion, for folks to try to read the minds of the creators of Java. Voting to close this question.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
  • @jwd: I don't agree with you, but I do seriously appreciate your posting a comment with your down-vote. We unfortunately don't see much of that happening. – Hovercraft Full Of Eels Jan 20 '14 at 23:42
  • @jwd I see no 'flippant negative attribute towards beginners' here, and in any case the purpose of a downvote here is to express your view that the answer isn't useful: see the flyover text on the button. If you have a difficulty with the wording or the tone you should flag the post for attention by moderators. – user207421 Jan 20 '14 at 23:45
  • @EJP: Telling someone that their question "makes no sense" is flippant. I believe other answers here, which deal directly with answering the question rather then whether the question is valid to be asked, are more useful to the asker and to future searchers. Not that I'm saying this is my favorite question in the world, of course (: – jwd Jan 20 '14 at 23:48
  • @jwd: your second comment is better than the first since it is much more specific and thus allows me to improve my answer, which I have done. – Hovercraft Full Of Eels Jan 21 '14 at 00:05
  • @jwd I disagree. Sometimes it is the only rational response to the question. Flippancy is just your assumption, not an established fact. – user207421 Jan 21 '14 at 05:13
  • There seems to be no feedback for deleted comments, but it would be nice if whoever deleted mine (rendering the above discussion somewhat hard to follow) would at least explain their decision. – jwd Jan 21 '14 at 19:44
4

All math libraries work in radians for trigonometric functions. Java is not exceptional in this respect. 'Counter-intuitive' is strictly in the eye of the beholder. No mathematician would agree.

user207421
  • 305,947
  • 44
  • 307
  • 483
2

From PurpleMath.com:

Each of radians and degrees has its place. If you're describing directions to me, I'd really rather you said, "Turn sixty degrees to the right when you pass the orange mailbox", rather than, "Turn one-third π radians" at that point. but if I need to find the area of a sector of a circle, I'd rather you gave me the numerical radian measure that I can plug directly into the formula, rather than the degree measure that I'd have to convert first.

More or less both measures have value, just depends on the context. As far as how to deal with it in Java, there are built in commands to convert back and forth:

Math.toDegrees(double radians)  

And

Math.toRadians(double degrees)

EDIT:

I don't think I can say it any better than this:

Ultimately, it comes down to the mechanisms used to compute trig functions are defined in terms of radians (even when implemented by a CPU's microcode; you might want to examine a numerical methods text for details, but they really do want to be done in radians) and working in degrees then requires constant conversions between the two, leading to cumulative errors. Since floating point (and transcendental numbers in particular) has plenty of error built into it already, adding that additional conversion on top is both slowing things down and adding even more avoidable error.

Community
  • 1
  • 1
Durandal
  • 5,575
  • 5
  • 35
  • 49