前言:角度弧度转化是各种测量软件的基本算法,本文将介绍利用C#-WPF技术来实现角度弧度的转化。
界面设计:
核心算法如下:
1 /// <summary> 2 /// 角度转弧度 3 /// </summary> 4 /// <param name="dmsAngle">角度值</param> 5 /// <returns></returns> 6 public static double DMStoRAD(double dmsAngle) 7 { 8 dmsAngle *= 10000; 9 int angle = (int)Math.Round(dmsAngle); 10 int d = angle / 10000; 11 angle -= d * 10000; 12 int m = angle / 100; 13 double s = dmsAngle - d * 10000 - m * 100; 14 return (d + m / 60 + s / 3600.0) * (Math.PI / 180); 15 } 16 /// <summary> 17 /// 弧度转角度 18 /// </summary> 19 /// <param name="radAngle">弧度值</param> 20 /// <returns></returns> 21 public static void RADtoDMS(double radAngle, out int d, out int m, out double s) 22 { 23 radAngle *= 180 * 3600 / Math.PI; 24 int angle = (int)Math.Round(radAngle); 25 d = angle / 3600; 26 angle -= d * 3600; 27 m = angle / 60; 28 s = radAngle - d * 3600 - m * 60; 29 } 30 public static double RADtoDMS(double radAngle) 31 { 32 RADtoDMS(radAngle,out int d, out int m, out double s); 33 return (d + m / 100.0 + s / 10000.0); 34 } 35 public static string RADtoString(double radAngle) //弧度值以字符串形式输出 36 { 37 RADtoDMS(radAngle, out int d,out int m,out double s); 38 return string.Format("{0}°{1:00}′{2:00.0####}″",d,m,s); 39 }
以上代码仍有不足之处,在今后的学习中作者将不断加以改进。