Microsoft's .Net Framework comes with a light, useful Math class built in. One of the most common fuctions used are the Trigonometry functions: sin, cos, and trig. However, if you remember from math class, the trig functions are good for two kinds of numbers: radians and degrees.
First let's review radians and degrees. Both are traced out in what is called a unit circle, which is simply a circle with its center at the origin (0,0) and with a radius of 1. Degrees are more commonly used; they simply go from 0 to 360. Well in the unit circle there is a radian "degree" so to speak that matches each actual degree. The most important equality is 180 degrees equals pi. As a reference, degrees go from 0 to 360 and radians go from 0 to 2*pi.
Online Degree
So which of the two does the .Net Framework use? In short, the answer is radians. The functions Math.Cos, Math.Sin, Math.Tan (and the other trig functions in the Math class) all take in a single double varible as parameter. The reason being radians are almost always dealt in decimal points.
In order to use degrees then, we must first convert the degree value to radians, and then input it into the Math function. Luckily radians and degrees have the same scale, thus we need only do simple cross multiplication to convert:
180/Pi = [degrees]/x
x will be the value in radians. After simplifying it comes out to
x = (Pi * [degrees])/180.0
To convert radians back to degrees for whatever reason, we can apply the same principle:
180/pi = x/[radians]
x = (180.0 / Pi) * [radians]
Remember to use doubles in your coding!
Radians And Degrees In C#
No comments:
Post a Comment