Recipe1.2.Converting Degrees to Radians


Recipe 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 p/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 p.



C# Cookbook
Secure Programming Cookbook for C and C++: Recipes for Cryptography, Authentication, Input Validation & More
ISBN: 0596003943
EAN: 2147483647
Year: 2004
Pages: 424

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net