Converts degrees to radians.

image_pdfimage_print
   
 
/*
 *  Copyright (C) 2002 Urban Science Applications, Inc. 
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */


#region Using
using System;
#endregion

namespace Geotools.Utilities
{
  /// <summary>
  /// Converts degrees to radians.
  /// </summary>
  public class Degrees
  {
    /// <summary>
    /// Converts degrees to radians.
    /// </summary>
    /// <param name="degrees">The angle in degrees.</param>
    /// <returns>The angle in radians.</returns>
    public static double ToRadians(double degrees)
    {
      return degrees * 0.0174532925199432958;
    }
  }
}

   
     


Converts a radians angle into a degrees angle.

image_pdfimage_print
   
 

    public static class MathUtility
    {
        //-------------------------------------------------------------------------------------
        /// <summary>
        /// Converts a radians angle into a degrees angle.
        /// </summary>
        /// <param name="angle">Angle to convert.</param>
        /// <returns>Angle in degrees.</returns>
        //-------------------------------------------------------------------------------------

        public static float RadiansToDegrees(float angle)
        {
            return angle * (180.0f / (float) System.Math.PI);
        }
    }

   
     


Converts a degrees angle into a radians angle.

image_pdfimage_print
   
 

    public static class MathUtility
    {

        //-------------------------------------------------------------------------------------
        /// <summary>
        /// Converts a degrees angle into a radians angle.
        /// </summary>
        /// <param name="angle">Angle to convert.</param>
        /// <returns>Angle in radians.</returns>
        //-------------------------------------------------------------------------------------

        public static float DegreesToRadians(float angle)
        {
            return angle * ((float) System.Math.PI / 180.0f);
        }

     }

   
     


Math.Abs

image_pdfimage_print
   
  
using System;

public class MainClass {
    public static void Main() {

        Console.WriteLine("Math.Abs(5) = {0}", Math.Abs(5));
        Console.WriteLine("Math.Abs(-5) = {0}", Math.Abs(-5));
        Console.WriteLine("Math.Abs(0) = {0}", Math.Abs(0));
    }
}

   
     


Math.Sign

image_pdfimage_print
   
  
using System;

public class MainClass {
    public static void Main() {
        Console.WriteLine("Math.Sign(1) = {0}", Math.Sign(1));
        Console.WriteLine("Math.Sign(-1) = {0}", Math.Sign(-1));
        Console.WriteLine("Math.Sign(0) = {0}", Math.Sign(0));
    }
}

   
     


Use Math.Round

image_pdfimage_print
   
  

using System;

public class MainClass {
    public static void Main() {

        Console.WriteLine(Math.Round(4.4));
        Console.WriteLine(Math.Round(4.5));
        Console.WriteLine(Math.Round(4.6));
        Console.WriteLine(Math.Round(5.5));
        Console.WriteLine(Math.Round(4.54, 1));
        Console.WriteLine(Math.Round(4.55, 1));
        Console.WriteLine(Math.Round(4.65, 1));
        Console.WriteLine(Math.Round(4.56, 1));
    }
}