在测量程序设计中,常常会遇到角度弧度转换问题,在这里编写了一个角度弧度转换的类,可以直接拿来用。
在进行程序设计的时候可以先将“”° ′ ″“”单位制通过 public double HUDU(string s) 转换为弧度制进行角度运算,
运算完之后可以通过 ***public string jiaodu(double jiao)***或者 public string jiaomiao(double jiao) 这两个函数将弧度转换为“ ° ′ ″”形式输出。
代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace jiaohu
{
public class Jiaohu
{
public double HUDU(string s)
{
string[] A = s.Split(new string[] { "\t", " ", " ", " ", " ", " ", " ", " ", " ", ",", " ", "°", "′", "″" }, StringSplitOptions.RemoveEmptyEntries);
//分割字符串
double jiao = (double.Parse(A[0]) + double.Parse(A[1]) / 60 + double.Parse(A[2]) / 3600) * Math.PI / 180;
//化为弧度//
return jiao;
}
public string jiaodu(double jiao)
{
string jiadu;
double du, fen, miao;
miao = (3600 * jiao * 180 / Math.PI) % 60;
fen = ((3600 * jiao * 180 / Math.PI - miao) % 3600) / 60;
du = (3600 * jiao * 180 / Math.PI - fen * 60 - miao) / 3600;
//j弧度换为角度输出//
jiadu = du.ToString() + "°" + fen.ToString() + "′" + miao.ToString() + "″";
return jiadu;
}
public string jiaomiao(double jiao)
{
string jiadu;
double du, fen, miao;
miao = (3600 * jiao * 180 / Math.PI) % 60;
fen = ((3600 * jiao * 180 / Math.PI - miao) % 3600) / 60;
du = (3600 * jiao * 180 / Math.PI - fen * 60 - miao) / 3600;
jiadu = miao.ToString() + "″";
return jiadu;
//改正数较少,化为秒//
}
}
}