Java:计算大量位置之间的距离和性能
我正在创建一个应用程序,它将告诉用户大量点距其当前位置有多远。
每个点都有一个经度和纬度。
我读过这篇文章 http://www.movable-type.co.uk/scripts/latlong。 html
并看到了这篇文章 当您知道经度时计算距离(以米为单位) java 中的纬度
有许多计算(50-200)需要进行。
如果速度比这些计算的准确性更重要,那么哪一个最好?
I'm creating an application that will tell a user how far away a large number of points are from their current position.
Each point has a longitude and latitude.
I've read over this article
http://www.movable-type.co.uk/scripts/latlong.html
and seen this post
Calculate distance in meters when you know longitude and latitude in java
There are a number of calculations (50-200) that need carried about.
If speed is more important than the accuracy of these calculations, which one is best?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您发布的两个链接使用相同的球面几何公式来计算距离,因此我预计它们的运行速度不会有显着差异。此外,它们的计算成本并不高,因此,如果您在现代硬件上运行,即使在几百次迭代的规模上,我也不认为这会成为问题。
The two links that you posted use the same spherical geometry formula to calculate the distances, so I would not expect there to be a significant difference between their running speed. Also, they are not really computationally expensive, so I would not expect it to be a problem, even on the scale of a few hundred iterations, if you are running on modern hardware.
这是 O(n)
不用担心性能。除非每次计算都花费太长时间(事实并非如此)。
this is O(n)
Dont worry about performance. unless every single calculation takes too long (which it isnt).
正如 Imre 所说,这是 O(n) 或线性的,这意味着无论值如何不同或执行多少次,算法中的计算每次迭代都会花费相同的时间。然而,我不同意余弦球面定律的实际变量较少,算法中执行的计算意味着使用的资源较少。因此,我会选择那个,因为唯一不同的速度是可用的计算机资源。 (注意:尽管除非在非常旧/慢的机器上,否则几乎不会被注意到)
基于意见的判决:余弦球面定律
As Imre said this is O(n), or linear, meaning that no matter how the values differ or how many times you do it the calculations in the algorithm will take the same amount of time for each iteration. However, I disagree in the context that the Spherical Law of Cosines has less actual variables and calculations being performed in the algorithm meaning that less resources are being used. Hence, I would choose that one because the only thing that will differ speed would be the computer resources available. (note: although it will be barely noticable unless on a really old/slow machine)
Verdict based on opinion: Spherical Law of Cosines