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

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;
        }
    }
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值