C#测绘角度与弧度转换类

C#测绘角度与弧度转换类

class AngleRadian
    {
        /// 
        /// dd.mmssssss格式的角度转换为弧度
        /// 
        /// 
        /// 
        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;
        }
        /// 
        /// 弧度转换为dd.mmssssss格式的角度
        /// 
        /// 
        /// 
        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;
            
        }
        /// 
        /// dd.mmssssss格式的角度转换为°′″形式的字符串
        /// 
        /// 
        /// 
        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;
        }
        /// 
        /// 弧度转换为°′″形式的字符串
        /// 
        /// 
        /// 
        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;
        }
    }

你可能感兴趣的:(C#,测绘弧度角度转换)