Saturday, May 10, 2014

Converting Between Radians and Degrees

Angles are normally measured in one of two units, either degrees (°) or radian (rad), from which probably the first one is used more commonly. For example a right angle equals 90°, a complete circle 360°. On the radian scale a complete circle equals 2 π.
This directly leads to the following conversion functions in C#:

        private double ToDegrees(double rad)
        {
            return (rad / (2 * Math.PI) * 360);
        }

        private double ToRadians(double deg)
        {
            return (2 * Math.PI / 360 * deg);
        }

No comments:

Post a Comment