如何使用Java测试具有lat / lon和radius的区域内的点? [英] How to test if a point inside area with lat/lon and radius using Java?
本文介绍了如何使用Java测试具有lat / lon和radius的区域内的点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要编写一个具有以下签名的方法
I've to write a method that has the following signature
public class Position {
double longitude;
double latitude;
}
boolean isInsideTheArea(Position center, double radius, Position point);
因此,如果点
在<$内c $ c> area 以中心
为中心,半径
为半径在里程,这应该返回 true
, false
否则。
So if point
is inside the area
that has the center
as its center and radius
as its radius in miles, this should return true
, false
otherwise.
推荐答案
使用 Haversine公式来计算中心
和点
之间的距离。如果该距离大于 radius
,则返回 false
;否则返回 true
。
Use the Haversine formula to compute the distance between center
and point
. If that distance is greater than radius
, return false
; otherwise return true
.
伪代码:
def haversineDistance(a, b):
# snip...
return foo
def isInsideTheArea (center, radius, point):
return haversineDistance(center, point) <= radius
这篇关于如何使用Java测试具有lat / lon和radius的区域内的点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文