gpt4 book ai didi

php - 如何获得 2 或 3 个径向位置的中点(纬度、经度)

转载 作者:行者123 更新时间:2023-11-29 01:44:26 25 4
gpt4 key购买 nike

我尝试使用 haversine我没能成功基本上我的问题是我有 3 个 map 位置及其 Lat 和 Long 值。我想做的是得到这个三角形的中点。

这是图片

enter image description here

I 有 H、F 和 I 点的位置。我需要知道问号的位置。41.040035,28.98402641.040868,28.98580741.039136,28.984981

PHP、MYSQL 或 Objective C 中的任何一种语言都可以作为答案。甚至建议表示赞赏。谢谢。

最佳答案

我检查了这个例子:http://geomidpoint.com/example.html

并用PHP写了一个函数,希望对你有帮助...

[edit] 我忘记转换为弧度进行计算,所以它给出了不同的输出,所以现在它应该工作正常......

   <?php

function middlepoint($lat1,$lon1,$lat2,$lon2,$lat3,$lon3){
$w1=1095.75;$w2=730.5;$w3=365.25;$tw=$w1+$w2+$w3; //weighting factors

$x1=cos(floatval(deg2rad($lat1)))*cos(floatval(deg2rad($lon1)));$y1=cos(floatval(deg2rad($lat1)))*sin(floatval(deg2rad($lon1)));$z1=sin(floatval(deg2rad($lat1)));$x2=cos(floatval(deg2rad($lat2)))*cos(floatval(deg2rad($lon2)));$y2=cos(floatval(deg2rad($lat2)))*sin(floatval(deg2rad($lon2)));$z2=sin(floatval(deg2rad($lat2)));$x3=cos(floatval(deg2rad($lat3)))*cos(floatval(deg2rad($lon3)));$y3=cos(floatval(deg2rad($lat3)))*sin(floatval(deg2rad($lon3)));$z3=sin(floatval(deg2rad($lat3))); //convert lat/long to cartesian (x,y,z) coordinates

$x = ($x1*$w1+$x2*$w2+$x3*$w3)/$tw;$y=($y1*$w1+$y2*$w2+$y3*$w3)/$tw;$z=($z1*$w1+$z2*$w2+$z3*$w3)/$tw; //Compute combined weighted cartesian coordinates

$lon=atan2($y,$x);$hyp=sqrt(pow($x,2)+pow($y,2));$lat=atan2($z,$hyp); //Convert cartesian coordinate to latitude and longitude for the midpoint

$midpoint[0] = $lon * (180/pi());$midpoint[1] = $lat * (180/pi()); //Convert from radians to degrees

return $midpoint; //return an array(lat,lon);

}

$test = middlepoint(41.040035,28.984026,41.040868,28.985807,41.039136,28.984981);
print_r($test);

?>

关于php - 如何获得 2 或 3 个径向位置的中点(纬度、经度),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10698391/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com