What the Heck is a Radian?

Math should be fun. My observation is that it’s not taught correctly in school, so generations of students get an education, but are weak in math. I’m one of them. As I’ve aged, I’ve grown fond of math, but still struggle with it. That’s disappointing because so much of math is actually kind of cool, just not explained well.

And of course, one of the joys of programming is that you don’t have to do the math; the computer does it for you. You must, however, get the equations right.

As an example, consider trigonometry. It’s all about triangles and the relationship between the sides and angles, which are calculated as the sine, cosine, and tangent. The topic is fascinating and some excellent YouTube videos are available that explain the concepts in a fun and interesting manner.

In C, three functions are defined in math.h that handle computing the sine, cosine, and tangent of an angle: sin(), cos(), and tan(), respectively. Here’s some quick-and-dirty code:

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

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

    return(0);
}

And the output:

The sine of 45 degrees is 0.850904
The cosine of 45 degrees is 0.525322
The tan of 45 degrees is 1.619775

Looks impressive, right? And being a math idiot, it looks fine to me; I see lots of tiny numbers and fractions and, by golly, they must be correct!

Except.

I know that the tangent of the angle 45° is 1, not 1.619755. That's because a triangle with a 45° angle has two equal sides, a ratio of 1-to-1, which makes sense that the tangent is 1. That's how I remember it.

On my phone, I whipped out the calculator app and came up with these results:

sine of 45° is 0.707106781186548
cosine of 45° is 0.707106781186548
tangent of 45° is 1.0

The sine and cosine of a 45° angle are equal. Again, that makes sense as in a triangle with a 45° angle, two sides are equal. Duh.

So why didn't the code run properly? Or did it? What did I do wrong!

If you look at the man page for the sin() function, you find the following description:

The sin() function computes the sine of x (measured in radians).

Radians?

Computer programming uses radians instead of degrees to compute angles. The reason is that radians relate to the value of π, whereas degrees are calculated for humans using a compass or protractor. So every computer program you've used, have written, or will write, must translate between radians and degrees so that the human user gets the proper result.

In next week's Lesson I reveal what a radian is and how it came about, and potentially why it's more useful than degrees when working with trigonometric functions.

Leave a Reply