WGS84下大地坐标转换为空间直角坐标

在这里插入图片描述在这里插入图片描述在这里插入图片描述
核心代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CoordinateTransform
{
    /// <summary>
    /// WGS84下大地坐标转换
    /// </summary>
    public class WGS84GeodeticCoordinateTransform
    {
        /// <summary>
        /// 大地坐标转换为空间直角坐标
        /// </summary>
        /// <param name="LBH"></param>
        /// <returns></returns>
        public static Point3D GeodeticToSpaceRectangularCoordinates(LBH LBH)
        {
            double L_Rad = LBConversion.DuToRad(LBH.L);
            double B_Rad = LBConversion.DuToRad(LBH.B);
            double H = LBH.H;

            double a = 6378137;
            double b = 6356752.3142451793;
            double e2 = (a * a - b * b) / (a * a);
            double W = Math.Sqrt(1 - e2 * Math.Sin(B_Rad) * Math.Sin(B_Rad));
            double N = a / W;

            double X = (N + H) * Math.Cos(B_Rad) * Math.Cos(L_Rad);
            double Y = (N + H) * Math.Cos(B_Rad) * Math.Sin(L_Rad);
            double Z = (N * (1 - e2) + H) * Math.Sin(B_Rad);

            return new Point3D(X, Y, Z);
        }

        /// <summary>
        /// 大地坐标转换为空间直角坐标
        /// </summary>
        /// <param name="L"></param>
        /// <param name="B"></param>
        /// <param name="H"></param>
        /// <returns></returns>
        public static Point3D GeodeticToSpaceRectangularCoordinates(double L, double B, double H)
        {
            return GeodeticToSpaceRectangularCoordinates(new LBH(L, B, H));
        }


        /// <summary>
        /// 空间直角坐标1转空间直角坐标2-特例1
        /// </summary>
        /// <param name="origin"></param>
        /// <param name="XYZp"></param>
        /// <returns></returns>
        public static double[] SpaceRecCoordinates_1_to_2(LBH origin, Point3D XYZp)
        {
            double Xp = XYZp.X;
            double Yp = XYZp.Y;
            double Zp = XYZp.Z;

            Point3D XYZ = WGS84GeodeticCoordinateTransform.GeodeticToSpaceRectangularCoordinates(origin);
            double Xa = XYZ.X;
            double Ya = XYZ.Y;
            double Za = XYZ.Z;

            double La = LBConversion.DuToRad(origin.L);
            double Ba = LBConversion.DuToRad(origin.B);

            double Ep = -(Xp - Xa) * Math.Sin(Ba) + (Yp - Ya) * Math.Cos(La);
            double Np = -(Xp - Xa) * Math.Sin(Ba) * Math.Cos(La) - (Yp - Ya) * Math.Sin(Ba) * Math.Sin(La) + (Zp - Za) * Math.Cos(Ba);
            double Up = -(Xp - Xa) * Math.Cos(Ba) * Math.Cos(La) - (Yp - Ya) * Math.Cos(Ba) * Math.Sin(La) + (Zp - Za) * Math.Sin(Ba);

            return new double[] { Ep, Np, Up };
        }


    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using MathNet.Numerics.LinearAlgebra.Double;
using MathNet.Numerics.Integration;

namespace CoordinateTransform
{
    /// <summary>
    /// 三维点坐标
    /// </summary>
    public class Point3D
    {
        public double X = 0;//米
        public double Y = 0;//米
        public double Z = 0;//米

        public Point3D(double X, double Y, double Z)
        {
            this.X = X;
            this.Y = Y;
            this.Z = Z;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using MathNet.Numerics.LinearAlgebra.Double;
using MathNet.Numerics.Integration;

namespace CoordinateTransform
{
    /// <summary>
    /// 经纬度坐标转换
    /// </summary>
    public class LBConversion
    {
        /// <summary>
        /// 度转换为弧度
        /// </summary>
        /// <param name="du"></param>
        /// <returns></returns>
        public static double DuToRad(double du)
        {
            return du * Math.PI / 180;
        }

        /// <summary>
        /// 弧度转换为度
        /// </summary>
        /// <param name="rad"></param>
        /// <returns></returns>
        public static double RadToDu(double rad)
        {
            return rad * 180 / Math.PI;
        }

        /// <summary>
        /// 度分秒转度
        /// </summary>
        /// <param name="du"></param>
        /// <param name="fen"></param>
        /// <param name="miao"></param>
        /// <returns></returns>
        public static double ToDu(double du, double fen, double miao)
        {
            return (miao / 60.0 + fen) / 60.0 + du;
        }

    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CoordinateTransform
{
    /// <summary>
    /// 三维点坐标
    /// </summary>
    public class Point3D
    {
        public double X = 0;//米
        public double Y = 0;//米
        public double Z = 0;//米

        public Point3D(double X, double Y, double Z)
        {
            this.X = X;
            this.Y = Y;
            this.Z = Z;
        }
    }
}

  • 6
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值