O'Reilly logo

C# Cookbook by Jay Hilyard, Stephen Teilhet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, 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 π.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required