坐标换算和GPS时间计算

/ 0评 / 1

GPS课第一次作业,懒得编2个EXE,全弄一起了,分享下。。。

界面如下:

36075dd22402aaaea8ec9ae4

依照惯例分享下代码。。。BS下无穷无尽的伸手党。。。

/// <summary>
        /// 计算大地经度L
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public double cal_l(double x, double y)
        {
            return Math.Atan(y / x);
        }

        /// <summary>
        /// 计算原始的B
        /// </summary>
        /// <param name="b"></param>
        /// <returns></returns>
        public double cal_orginb(double b)
        {
            return a / Math.Sqrt(1 - e * square(Math.Sin(b)));
        }

        /// <summary>
        /// 计算新的B
        /// </summary>
        /// <param name="n"></param>
        /// <param name="h"></param>
        /// <returns></returns>
        public double cal_nb(double n, double h)
        {
            double a = z * (n + h);
            double ba = Math.Sqrt(square(x) + square(y)) * (n * (1 - e) + h);
            return Math.Atan(a/ba);
        }

        //计算高程
        public double cal_h(double n, double b)
        {
            //double tmp = Math.Sin(b);
            return (z / Math.Sin(b)) - n * (1 - e);
        }

        /// <summary>
        /// 运算过程
        /// </summary>
        /// <param name="err"></param>
        /// <returns></returns>
        public double[] ConvertProcess(double err)
        {
            try
            {

                double[] tmp = new double[3];
                double n = 0;
                double b = originb;
                double h = 0;
                double rb = b;
                tmp[0] = ConvertToDegree(cal_l(x, y));
                if (tmp[0]<0)
                {
                    tmp[0] += 180;
                }
                do 
                {
                    b = rb;
                    n = cal_orginb(b);
                    h = cal_h(n, b);
                    rb = cal_nb(n, h);

                } while (Math.Abs(rb - b) > err);

                tmp[1] = ConvertToDegree(rb);
                tmp[2] = h;

                return tmp;

            }
            catch (System.Exception ex)
            {
                return null;
            }
        }

算B用迭代法,误差以参数形式给出,可以自定义误差范围。

下面是GPS时间的计算:

        /// <summary>
        /// 儒略日的计算
        /// </summary>
        /// <param name="year"></param>
        /// <param name="month"></param>
        /// <param name="day"></param>
        /// <returns></returns>
        public static double jd(double year, double month, double day)
        {
            int G = 0;
            double n = 0;
            if(year * 372 + month *31 +Math.Floor(day)>=588829)
                G=1; //判断是否为格里高利历日1582*372+10*31+15
            if (G==1)
            {
                n = Math.Floor(year / 100); 
                n = 2 - n + Math.Floor(n / 4); //加百年闰
            }
            if (month == 1 || month == 2)
            {
                month += 12;
                year -= 1;
            }
            return Math.Floor(365.25 * (year + 4716)) + Math.Floor(30.6001 * (month + 1)) + day + n - 1524.5;
            //return Convert.ToInt64(day - 32075 + 1461 * (year + 4800 + (month - 14) / 12) / 4 + 367 * (month - 2 - (month - 14) / 12 * 12) / 12 - 3 * ((year + 4900 + (month - 14) / 12) / 100) / 4);
        }

        public static string weekday(double jd) 
        {
            int no = Convert.ToInt32(Math.Floor((jd + 1.5) % 7));
            switch(no)
            {
            case 0:
                return "星期日";
            case 1:
                return "星期一";
            case 2:
                return "星期二";
            case 3:
                return "星期三";
            case 4:
                return "星期四";
            case 5:
                return "星期五";
            case 6:
                return "星期六";
            default:
                return null;
            }
        }

 

作业都要编程。。。真费事。。。THU坑爹。。。

发表评论

邮箱地址不会被公开。 必填项已用*标注