
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Converting Radians to Degrees
|
5
Solution
To convert a value in degrees to radians, multiply it by π/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. After all, humans understand degrees better 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 π.
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/π:
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; ...