Numbers - Converting Degrees to Radians and Converting Radians to Degrees
(Page 3 of 12 )
1.2 Converting Degrees to Radians
Problem
When using the trigonometric functions of the Math class, all units are in radians. You have one or more angles measured in degrees and want to convert these to radians in order to use them with the members of the Math class.
Solution
To convert a value in degrees to radians, multiply it by π/180 (pi/180):
using System;
public static double ConvertDegreesToRadians (double degrees)
{
double radians = (Math.PI / 180) * degrees;
return (radians);
}
Discussion
All of the static trigonometric methods in the Math class use radians as their unit of measure for angles. It is very handy to have conversion routines to convert between radians and degrees, especially when a user is required to enter data in degrees rather than radians.
The equation for converting degrees to radians is shown here:
radians = (Math.PI / 180) * degrees
The static field Math.PI contains the constant π (pi).
1.3 Converting Radians to Degrees
Problem
When using the trigonometric functions of the Math class, all units are in radians; instead, you require a result in degrees.
Solution
To convert a value in radians to degrees, multiply it by 180/π (180/pi):
using System;
public static double ConvertRadiansToDegrees(double radians)
{
double degrees = (180 / Math.PI) * radians;
return (degrees);
}
Discussion
All of the static trigonometric methods in the Math class use radians as their unit of measure for angles. It is very handy to have conversion routines to convert between radians and degrees, especially when displaying degrees to a user is more informative than displaying radians.
The equation for converting radians to degrees is shown here:
degrees = (180 / Math.PI) * radians
The static field Math.PI contains the constant π (pi).
 | If you've enjoyed what you've seen here, or to get more information, click on the "Buy the book!" graphic. Pick up a copy today!
Visit the O'Reilly Network http://www.oreillynet.com for more online content. |
Next: Using the Bitwise Complement Operator with Various Data Types >>
More C# Articles
More By O'Reilly Media