Radians to the Rescue!

The word radian comes from radius, which is half the diameter of a circle. If you take a radius and create an arc along the circle of the same length, you get one radian.

Okay. So what?

First, to understand the radian, gander at Figure 1. You see how the radius of the circle on the left is mapped to an arc on the circle. This length is one radian, r.

Figure 1. The relationship between radians and degrees.

The radian is related to π, which is the ratio of the circle’s diameter to its circumference. As the radius is half the diameter, its value is related to π, as you see in the measurements in the circle on the left: For the entire circle, the radian wraps around the circumference 6.2831 times, which is 2π. This number makes sense because the circle’s diameter wraps around the circumference 3.1415 times, which is 1π.

Degrees, shown on the right in Figure 1, were invented to divide a circle into handy portions. No one knows who came up with the idea, but the Babylonians used a base 60 (sexagesimal) numbering system, so they get the credit. Further, 360 is a number than can be divided by many other numbers and you still get a whole number answer.

Second, why do computers use radians and not degrees?

Consider the triangles shown in Figure 2.

Figure 2. How a triangle looks when measured with radians versus degrees.

On the right you see a triangle measured in degrees, which you probably studied in school, the common 30-60-90 triangle. On the left is the same triangle, but with measurements in radians. 30° is π/6 radians, 60° is π/3 radians, and 90° is π/2 radians. As you might suspect, computers find these values far easier to deal with than degrees.

Oh, and 45° is π/4 radians.

It’s not critical to know the specific decimal values of the π ratios when dealing with radians. Instead, as a programmer, you just need to know the translation constants:

To convert degrees to radians, multiply degrees by 0.0174532925. This value is 2π/360.

To convert radians to degrees, multiply radians by 57.2957795. This value is 360/2π.

The following code displays common angles as radians and degrees.

#include <stdio.h>

#define PI 3.1415926

int main()
{
    float degree,radian;

    for(degree=0.0;degree<=360.0;degree+=60.0)
        printf("%.f degrees = %.4f radians\n",
                degree,
                degree*0.0174533
              );

    for(radian=0.0;radian<=PI*2;radian+=(PI/3.0))
        printf("%.4f radians = %.f degrees\n",
                radian,
                radian*57.2958
              );

    return(0);
}

Because of the way the loops work, I’m not able to display π ratios in the code, but you can see the values of π in the output:

0 degrees = 0.0000 radians
60 degrees = 1.0472 radians
120 degrees = 2.0944 radians
180 degrees = 3.1416 radians
240 degrees = 4.1888 radians
300 degrees = 5.2360 radians
360 degrees = 6.2832 radians
0.0000 radians = 0 degrees
1.0472 radians = 60 degrees
2.0944 radians = 120 degrees
3.1416 radians = 180 degrees
4.1888 radians = 240 degrees
5.2360 radians = 300 degrees
6.2832 radians = 360 degrees

Back to the code from last week’s Lesson, here’s the proper way to do the math with radians instead of degrees:

#include <stdio.h>
#include <math.h>

#define DEG2RAD 0.0174532925

int main()
{
    printf("The sine of 45 degrees is %f\n",sin(45*DEG2RAD));
    printf("The cosine of 45 degrees is %f\n",cos(45*DEG2RAD));
    printf("The tan of 45 degrees is %f\n",tan(45*DEG2RAD));

    return(0);
}

In the code, I use the DEG2RAD constant expression to modify 45 from a degree value to radians.

Here’s the proper output:

The sine of 45 degrees is 0.707107
The cosine of 45 degrees is 0.707107
The tan of 45 degrees is 1.000000

That looks better!

5 thoughts on “Radians to the Rescue!

  1. Thanks for the post. I always #define 57.29577951 rather than 0.0174532925, which are just reciprocals of each other. As long as you remember when to multiply and when to divide it doesn’t matter which you use.

    Years ago I actually made the effort to memorize 57.29577951 which probably makes me a nerd. Or a geek. Or both.

  2. So you want me to memorize pi as well? It took me about 2 years to remember my new phone number . . .

    Glad you found my linear regression post useful. I started using Google Search Console a while ago and that post is the most popular, at least in terms of people finding it via Google. (It’s probably mostly students given an assignment Googling and then copy/pasting my code!)

    I also used radians in my Great Circle Distance post. It makes it much more straightforward than using degrees.

    Did you create the first graphic with the two circles or did you “borrow” it from somewhere? The calculations using π seem a bit too complicated, it might be simpler to use:

    0πr
    0.5πr
    1πr
    1.5πr
    2πr
    etc.

  3. I created the graphics myself, which is why the circle on the right isn’t transparent. My Mac doesn’t have a high-contrast monitor, but my laptop does. So when I looked at it after posting, I was like, “Yuck.”

    You’re correct about the decimal notation, which I agree is easier to read. I was thinking more in terms ratio values, as shown on the left in Figure 1.

  4. Reader Jacco made the following keen observations regarding measuring angles in an email to me. The following is reprinted with his permission:

    I was reading your blog a couple of weeks ago, about angles and their units of measurement: radians and degrees. It doesn’t stop there, there are more units and ways the express an angle. The method used depends on the area of application.

    But first, C is not the only programming language that uses radians for its trigonometric functions, almost every language does. And so do spreadsheets like Excel and LibreCalc, but at at least they come with handy built-in functions to convert between the “theoretical” radians and the “practical” degrees. After all, your carpenter understands degrees better than radians.

    In the slipstream of the introduction of the metric system, a new unit for angles was introduced: the decimal degree. There are 400 decimal degrees in a circle, or 100 in a right angle (from the equator to the North Pole). The logic is obvious, but this system never gained enough support to replace the old 360 degree-circle. It is still in use in land surveying.

    I would never have known about the decimal degree (often called gon, gradian or new degree) if it wasn’t for my scientific pocket calculator. It lets you choose the angle mode you want to work in: DEG (degrees), RAD (radians) or GRAD (gradians).
    By the way, my first calculator, a Toshiba SLC-8260, already had those three angle modes. I bought it in 1979 for the price of 79.99 Dutch guilders, about 36 Euros in today’s money. However, today you can buy a similar calculator (Casio fx-82MS) for only 7.99 Euros!

    Back to angles. Another way of expressing an angle is the gradient. You will know this from the road signs with a picture of a slope and a percentage, 10% for example. It means that if you travel a horizontal distance of 10 meters, you will climb, or drop, 10% of that distance, 1 meter in this case. If you draw a picture of this you will see that the gradient is in fact the tangent of the angle of the slope. This is a very practical way of expressing slopes with small angles. A 10% gradient means an angle of 5.71 degrees. It doesn’t seem like a lot, but for most forms of traffic this is quite steep. A slope of 6% is enough to slow a truck down to crawling speed, train tracks are usually limited to 4% to prevent skidding of the wheels on the track. A 15% slope is a very good training exercise on a bicycle.

    The last unit is the mil, or milliradian. Theoretically the mil is 1/1000 of a radian, making about 6280 mils for a full circle. Imagine you are firing an artillery gun at a target at a distance (range) of 1000 meters. Your first shot lands 20 meters left of the target, so you have to adjust the direction of the gun to the right, but how much? Easy , 20 meters to the right is 20/1000 = 0.02 radians, or 20 milliradians.
    In practice armies round the 6280 mils in a circle to 6000 (Russia), 6300 (Sweden), or 6400 (NATO).

    So there are many different units of measure for angles, each with its own application.

    What this means for a programmer is that he/she has to write even more conversion routines. They are very simple, but very easy to do the wrong way around, especially if you want to do them on the fly. So it pays to invest some time into making good conversion routines with strong names. In this case I prefer function-like macros.

    I hope you enjoyed this little elaboration.

    Thank you! I did, and I hope others enjoy it as well.

Leave a Reply