大圆距离问题
我熟悉计算两点之间大圆距离的公式。
即
<?php
$theta = $lon1 - $lon2;
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
//convert degrees to distance depending on units desired
?>
我需要的是相反的。 给定起点、距离和简单的基本 NSEW 方向,计算目的地点的位置。 我已经很久没有上数学课了。 ;)
I am familiar with the formula to calculate the Great Circle Distance between two points.
i.e.
<?php
$theta = $lon1 - $lon2;
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
//convert degrees to distance depending on units desired
?>
What I need though, is the reverse of this. Given a starting point, a distance, and a simple cardinal NSEW direction, to calculate the position of the destination point. It's been a long time since I was in a math class. ;)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
为了回答我自己的问题,为任何好奇的人提供一个从 Chad Birch 提供的 C 函数转换而来的 PHP 类:
To answer my own question just so it's here for anyone curious, a PHP class as converted from the C function provided by Chad Birch:
这是我发现的一个 C 实现,应该相当简单地转换为 PHP:
Here's a C implementation that I found, should be fairly straightforward to translate to PHP:
我认为,撤销半正矢公式然后生成自己的公式会更困难。
首先,通过在地表上行进“直线”,从地核产生的角度(你认为它是直的,但它是弯曲的)。
角度(弧度)= 弧长/半径。
角度 = ArcLen/6371 公里
纬度应该很简单,只需角度的“垂直”(北/南)分量即可。
Lat1 + Cos(方位角) * 角度
经度划分因纬度而异。 所以这就变得更难了。 您可以使用:
Sin(方位角) * 角度(东定义为负)来查找经度方向的角度,但转换回该纬度的实际经度会更加困难。
It would be harder to back out the Haversine fomula, then generate your own, I would think.
First the angle generated from the Earth core by traveling a "straight" line on the surface (you think it is straight, but it is curving).
Angle in Radians = Arc Length / radius.
Angle = ArcLen/6371 km
Latitude should be easy, just the "vertical" (north/south) component of your angle.
Lat1 + Cos(bearing) * Angle
Longitude divisions vary by latitude. So that becomes harder. You would use:
Sin(bearing) * Angle (with East defined as negative) to find the angle in longitude direction, but converting back to actual longitude at that latitude would be more difficult.
请参阅此网站上的给定距离和方位的目的地点部分:http://www.movable-type.co.uk/scripts/latlong.html
See the section Destination point given distance and bearing from start point at this website: http://www.movable-type.co.uk/scripts/latlong.html