用地理坐标(纬度、经度)计算物体的方向

发布于 2024-12-13 03:27:11 字数 116 浏览 0 评论 0原文

我有一个玩家和另一个物体的坐标。两者都带有地理坐标(纬度和经度)。我还有玩家所面对的方向(指南针)。如何计算从玩家方向到另一个物体的角度?例如,我想知道该物体是否位于玩家的右侧/左侧以及多少度。

多谢!

I have the coordinates of a player and another object. Both are with geographical coordinates (Latitude and longitude). I have also the direction in what the player is facing (compass). How can I calculate the angle to the other object from the player direction? e.g. I want to know if the object is to the right/left of the player and how many degrees.

Thanks a lot!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

全部不再 2024-12-20 03:27:11

有一些这取决于,答案本质上是,您想知道如何做

对于短距离(<10公里),您可以忽略地球的曲率,并将其视为二维笛卡尔地图(纬度/经度为 XY)。那么你的问题就变成了基本的三角学。

为了获得更大的距离或提高精度,您可以使用地球的球体模型进行近似(< em>假设地球是一个完美的球体,但事实并非如此)并计算伟大圆 方位距离

或者,您可以将地球建模为椭圆体,并计算其地理导航

两个可能有帮助的网页:使用纬度/经度坐标计算距离的详细信息计算纬度/经度点之间的距离、方位等

注意:atan2Haversine 公式 通常是有用的实现细节。

小补充说明:在此上下文中,bearingheadingdirection 的同义词。

With a few it depends, the answer is in essence, you want to know about how to do geographic navigation. One of the reasons it depends is that the distances involve as well as the accuracy needed may influence the answer.

For short distances (<10km) you may be able to ignore the curvature of the Earth, and treat it like a two dimensional Cartesian map (latitude / longitude as X-Y). Then you question becomes basic trigonometry.

For larger distances, or improved accuracy, you can either approximate using an spheroid model of the Earth (assume the Earth is a perfect sphere, which it is not) and calculate the Great Circle bearing and distance.

Or you can model the Earth as an ellipsoid, and calculate its geographic navigation.

Two web pages that may help: Details for computing distance using lat/long coordinates and Calculate distance, bearing and more between Latitude/Longitude points.

Note: atan2 and Haversine formula are often useful implementation details.

Small added note: bearing is a synonym for heading or direction in this context.

九歌凝 2024-12-20 03:27:11

您需要这个球面三角公式:http://williams.best.vwh.net/avform。 htm#Crs 一旦确定了航向(相对于正北的角度),您可以减去玩家所面向方向的罗盘航向以获得相对航向。

(我不知道 Android 是否会自动补偿磁性变化,但如果没有,您也必须考虑到它才能在所有区域获得正确的角度)

You need this spherical trig formula: http://williams.best.vwh.net/avform.htm#Crs Once you have the course (angle relative to true north), you can subtract off the compass heading of the direction the player is facing to get the relative heading.

(I don't know if Android automatically compensates for magnetic variation or not, but if not you'll have to account for it too to get the angle right in all areas)

对你而言 2024-12-20 03:27:11

API 中有一些工具可以为您执行此操作: Location.bearingTo(Location)GeomagicSensor会给您可以确定从您的位置到目标的方向 - 然后您可以根据设备当前的航向进行调整。

如果您已经运行了 MapView &如果比较懒的话,可以设置一个 MyLocationOverlay、enableCompass并跳过地磁传感器并让 MapView 为您完成。

There are tools in the API to do this for you: Location.bearingTo(Location) and GeomagneticSensor will give you the direction from your position to the target - which you can then adjust based off the devices current heading.

If you've already got a MapView running & are lazy, set up a MyLocationOverlay, enableCompass and skip the GeomagneticSensor and let the MapView do it for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文