PHP 大地坐标转空间直角坐标

公式就不写了,直上代码

<?php

  $a = 6378137;            //长半轴
  $f = 1/298.257223563;    //WGS84 扁率
  $b = $a * (1 - $f);
  $e = sqrt($a * $a - $b * $b) / $a;   //椭球第一偏心率
  
  $lat = 25;
  $lon = 117;
  $h = 100;
  
  $N = $a / sqrt(1 - $e * $e * sin($lat * M_PI / 180) * sin($lat * M_PI / 180));
  $WGS84_X = ($N + $h) * cos($lat * M_PI / 180) * cos($lon * M_PI / 180);
  $WGS84_Y = ($N + $h) * cos($lat * M_PI / 180) * sin($lon * M_PI / 180);
  $WGS84_Z = ($N * (1 - ($e * $e)) + $h) * sin($lat * M_PI / 180);
 
?>

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是大地坐标空间直角坐标换的 Python 代码: ```python import math a = 6378137.0 # 长半轴 f = 1 / 298.257223563 # 扁率 def geodetic_to_ecef(latitude, longitude, height): """大地坐标空间直角坐标""" b = (1 - f) * a # 短半轴 e = math.sqrt(1 - (b / a) ** 2) # 第一偏心率 sin_latitude = math.sin(math.radians(latitude)) cos_latitude = math.cos(math.radians(latitude)) sin_longitude = math.sin(math.radians(longitude)) cos_longitude = math.cos(math.radians(longitude)) N = a / math.sqrt(1 - e ** 2 * sin_latitude ** 2) x = (N + height) * cos_latitude * cos_longitude y = (N + height) * cos_latitude * sin_longitude z = (N * (1 - e ** 2) + height) * sin_latitude return x, y, z def ecef_to_geodetic(x, y, z): """空间直角坐标大地坐标""" b = (1 - f) * a # 短半轴 e = math.sqrt(1 - (b / a) ** 2) # 第一偏心率 p = math.sqrt(x ** 2 + y ** 2) theta = math.atan2(z * a, p * b) sin_theta = math.sin(theta) cos_theta = math.cos(theta) latitude = math.atan2(z + e ** 2 * b * sin_theta ** 3, p - a * e ** 2 * cos_theta ** 3) longitude = math.atan2(y, x) N = a / math.sqrt(1 - e ** 2 * math.sin(latitude) ** 2) height = p / math.cos(latitude) - N latitude = math.degrees(latitude) longitude = math.degrees(longitude) return latitude, longitude, height ``` 其中,`geodetic_to_ecef` 函数将大地坐标换为空间直角坐标,输入参数为纬度、经度和高程,返回值为 X、Y 和 Z 坐标。`ecef_to_geodetic` 函数将空间直角坐标换为大地坐标,输入参数为 X、Y 和 Z 坐标,返回值为纬度、经度和高程。 注意,在这里使用的是 WGS84 椭球体参数。如果需要使用其他椭球体参数进行换,则需要相应地修改代码中的 `a` 和 `f` 值。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值