- Main Page
- Packages
- Classes
- Files

- File List
- File Members

# C:/Documents and Settings/student/My Documents/Visual Studio 2008/projects/system_controller/UtmConvert/UtmConvert/ConvertDegRad.cs

Go to the documentation of this file.

    00001 ﻿using System;
    00002 using System.Collections.Generic;
    00003 using System.Linq;
    00004 using System.Text;
    00005
    00006 namespace UtmConvert {
    00007     public static class ConvertDegRad {
    00008
    00009         static string _status = "ok";
    00010         public static string Status {
    00011             get { return ConvertDegRad._status; }
    00012         }
    00013
    00014         // for dd mm ss format
    00015         public static double getRadians(string degrees
    00016             , string minutes, string seconds, char direction) {
    00017             _status = "ok";
    00018             try {
    00019                                 if (direction == 'S' || direction == 'W')
    00020                     return -(Math.PI / 180) * (double.Parse(degrees)
    00021                         + double.Parse(minutes) / 60 + double.Parse(seconds) / 3600);
    00022                 return (Math.PI / 180) * (double.Parse(degrees)
    00023                     + double.Parse(minutes) / 60 + double.Parse(seconds) / 3600);
    00024             } catch (Exception e) {
    00025                 _status = "not a number: " + e.Message;
    00026                 return -1;
    00027             }
    00028         }
    00029         //for dd mm format
    00030         public static double getRadians(string degrees
    00031                         , string minutes, char direction) {
    00032             _status = "ok";
    00033             try {
    00034                                 if (direction == 'S' || direction == 'W')
    00035                     return -(Math.PI / 180) * (double.Parse(degrees)
    00036                         + double.Parse(minutes) / 60);
    00037                 return (Math.PI / 180)*(double.Parse(degrees)
    00038                     + double.Parse(minutes) / 60);
    00039             } catch (Exception e) {
    00040                 _status = "not a number: " + e.Message;
    00041                 return -1;
    00042             }
    00043         }
    00044         //for dd format
    00045                 public static double getRadians(string degrees, char direction) {
    00046             _status = "ok";
    00047             try {
    00048                                 if (direction == 'S' || direction == 'W')
    00049                     return -(Math.PI / 180) * (double.Parse(degrees));
    00050                 return (Math.PI / 180)*(double.Parse(degrees));
    00051             } catch (Exception e) {
    00052                 _status = "not a number: " + e.Message;
    00053                 return -1;
    00054             }
    00055         }
    00056
    00057                 //general purpose degree to radian conversion
    00058                 public static double getRadians(double degrees) {
    00059                         return (Math.PI / 180) * degrees;
    00060                 }
    00061
    00062         public static double getDegrees(double rad) {
    00063             return rad / (Math.PI / 180);
    00064         }
    00065
    00066         public static string getDegreesMin(double rad) {
    00067             string dd_ff = (rad / (Math.PI / 180)).ToString();
    00068             string mm_ff = (double.Parse(dd_ff.Substring(dd_ff.IndexOf(".")
    00069                 , dd_ff.Length - dd_ff.IndexOf("."))) * 60).ToString();
    00070             dd_ff = dd_ff.Substring(0, dd_ff.IndexOf("."));
    00071             return dd_ff + " " + mm_ff;
    00072         }
    00073
    00074         public static string getDegreesMinSec(double rad) {
    00075             string dd_ff = (rad / (Math.PI / 180)).ToString();
    00076             string mm_ff = (double.Parse(dd_ff.Substring(dd_ff.IndexOf(".")
    00077                 , dd_ff.Length - dd_ff.IndexOf("."))) * 60).ToString();
    00078             string ss_ff = (double.Parse(mm_ff.Substring(mm_ff.IndexOf(".")
    00079                 , mm_ff.Length - mm_ff.IndexOf("."))) * 60).ToString();
    00080             dd_ff = dd_ff.Substring(0, dd_ff.IndexOf("."));
    00081             mm_ff = mm_ff.Substring(0, mm_ff.IndexOf("."));
    00082             return dd_ff + " " + mm_ff + " " + ss_ff;
    00083         }
    00084
    00085     }
    00086 }