Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do we use radians in programming?

I like radians just as much as the next guy, and typically prefer to use them over degrees, but why do we use radians in programming?

To rotate something 180 degrees, you need to rotate it by 3.14159265.... Sure, most languages have some kind of constant for pi, but why do we ever want to use irrational numbers like pi when we can instead use integers, especially for simple programs?

We're relying on the computer to say that 3.14159265 is close enough to pi that functions like sine and cosine return the proper values, but if a computer is too accurate, then the values would be slightly off (sin(3.14159265) = 0.00000000358979303). This isn't an issue when using 180 degrees.

like image 463
Tom Marthenal Avatar asked Apr 09 '12 04:04

Tom Marthenal


People also ask

Why do computers use radians?

The radians represent angles as arc lengths that the angles correspond to on an circle of radius=1. 2π is the circumference of such circle, that is also the angle representing the full circle in radians.

What is the advantage of using radians?

Why You Use Radians? The biggest advantage offered by radians is that they are the natural measure for dividing a circle. If you take the radius of a given circle and bend it into an arc that lies on the circumference, you would need just over six of them to go completely around the circle.

How is radian used?

Simply put, a radian is another way to measure an angle instead of using degrees. You are merely switching the unit of measurement. It is like measuring your height in centimeters instead of inches.

What fields use radians instead of degrees?

You should use radians when you are looking at objects moving in circular paths or parts of circular path. In particular, rotational motion equations are almost always expressed using radians. The initial parameters of a problem might be in degrees, but you should convert these angles to radians before using them.


1 Answers

It actually is an issue, it just shows up in different ways, especially if you don't stick to 90 degree increments.

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.

like image 110
geekosaur Avatar answered Nov 15 '22 10:11

geekosaur