C#测绘角度与弧度转换类
class AngleRadian
{
/// <summary>
/// dd.mmssssss格式的角度转换为弧度
/// </summary>
/// <param name="degrees"></param>
/// <returns></returns>
public double ConvertDegreesToRadians(double degrees)
{
double d = Math.Truncate(degrees);
double m = Math.Truncate((degrees - d) * 100);
double s = ((degrees - d) * 100 - m) * 100;
double radians = (d + m / 60 + s / 3600) / 180 * Math.PI;
return radians;
}
/// <summary>
/// 弧度转换为dd.mmssssss格式的角度
/// </summary>
/// <param name="radians"></param>
/// <returns></returns>
public double ConvertRadiansToDegrees(double radians)
{
double dd = radians / Math.PI * 180;
double d = Math.Truncate(dd);
double m = Math.Truncate((dd - d) * 60);
double s = Math.Round(((dd - d) * 60 - m) * 60, 4);//返回四位小数
double degrees = d + m / 100 + s / 10000;
return degrees;
}
/// <summary>
/// dd.mmssssss格式的角度转换为°′″形式的字符串
/// </summary>
/// <param name="degrees"></param>
/// <returns></returns>
public string ConvertDegreesToString(double degrees)
{
string symbol = "";
if (degrees < 0)
{
degrees = Math.Abs(degrees);
symbol = "-";
}
double d = Math.Truncate(degrees);
double m = Math.Truncate((degrees - d) * 100);
double s = ((degrees - d) * 100 - m) * 100;
string dms = symbol + d.ToString() + "°" + m.ToString() + "′" + s.ToString() + "″";
return dms;
}
/// <summary>
/// 弧度转换为°′″形式的字符串
/// </summary>
/// <param name="radians"></param>
/// <returns></returns>
public string ConvertRadiansToString(double radians)
{
string symbol = "";
if (radians < 0)
{
radians = Math.Abs(radians);
symbol = "-";
}
double dd = radians / Math.PI * 180;
double d = Math.Truncate(dd);
double m = Math.Truncate((dd - d) * 60);
double s = Math.Round(((dd - d) * 60 - m) * 60, 4);//返回四位小数
string dms = symbol + d.ToString() + "°" + m.ToString() + "′" + s.ToString() + "″";
return dms;
}
}