如何计算地图上2个坐标之间沿直线的N个等距点的坐标?
How to calculate coordinates of N equidistant points along a straight line between 2 coordinates on a map?
我在地图上有两个点 -
val point1 : LatLng(13.3016139,77.4219107)
val point2 : LatLng(14.1788932,77.7613413)
我想沿着这两个坐标之间的直线计算并找到 100 个等距点。我该怎么做?
ps。我敢肯定这已经被问过,我只是找不到它。
按哪个投影等距,更重要的是直线?
通常,要找到笛卡尔坐标系中的距离 space,人们会使用类似
Haversine formula to find a value, as previously answered in stack answer: How to convert latitude or longitude to meters?
至于等距部分,一旦你根据你对给定点的地球形状和半径的喜好决定了距离,一个简单的除法就可以了。 .
python 3.7
>>> dist = 5427 #just some number
>>> nbr_o_points = 101
>>> points = [(dist/nbr_o_points)*(i+1) for i in range(nbr_o_points)]
>>> [f'{p:.2f}' for p in points]
['53.73', '107.47', '161.20',..., '5319.53', '5373.27', '5427.00']
现在将这些距离从点 a 转移回所需的投影...这不是您问题的一部分...Stack - how-to-determine-vector-between-two-lat-lon-points 可能会有所帮助。
获取向量并乘以以点为单位的距离以获得坐标。
我就是这样解决的 -
fun findEquidistantPoints(latLng1: LatLng, latLng2: LatLng, pointCount: Int): ArrayList<LatLng> {
if (pointCount < 0)
throw IllegalArgumentException("PointCount cannot be less than 0")
val points = ArrayList<LatLng>()
val displacement = latLng1.displacementFromInMeters(latLng2)
val distanceBetweenPoints = displacement / (pointCount + 1)
for (i in 1..pointCount) {
val t = (distanceBetweenPoints * i) / displacement
points.add(LatLng(
(1 - t) * latLng1.latitude + t * latLng2.latitude,
(1 - t) * latLng1.longitude + t * latLng2.longitude
))
}
return points
}
我在地图上有两个点 -
val point1 : LatLng(13.3016139,77.4219107)
val point2 : LatLng(14.1788932,77.7613413)
我想沿着这两个坐标之间的直线计算并找到 100 个等距点。我该怎么做?
ps。我敢肯定这已经被问过,我只是找不到它。
按哪个投影等距,更重要的是直线?
通常,要找到笛卡尔坐标系中的距离 space,人们会使用类似 Haversine formula to find a value, as previously answered in stack answer: How to convert latitude or longitude to meters?
至于等距部分,一旦你根据你对给定点的地球形状和半径的喜好决定了距离,一个简单的除法就可以了。 .
python 3.7
>>> dist = 5427 #just some number
>>> nbr_o_points = 101
>>> points = [(dist/nbr_o_points)*(i+1) for i in range(nbr_o_points)]
>>> [f'{p:.2f}' for p in points]
['53.73', '107.47', '161.20',..., '5319.53', '5373.27', '5427.00']
现在将这些距离从点 a 转移回所需的投影...这不是您问题的一部分...Stack - how-to-determine-vector-between-two-lat-lon-points 可能会有所帮助。
获取向量并乘以以点为单位的距离以获得坐标。
我就是这样解决的 -
fun findEquidistantPoints(latLng1: LatLng, latLng2: LatLng, pointCount: Int): ArrayList<LatLng> {
if (pointCount < 0)
throw IllegalArgumentException("PointCount cannot be less than 0")
val points = ArrayList<LatLng>()
val displacement = latLng1.displacementFromInMeters(latLng2)
val distanceBetweenPoints = displacement / (pointCount + 1)
for (i in 1..pointCount) {
val t = (distanceBetweenPoints * i) / displacement
points.add(LatLng(
(1 - t) * latLng1.latitude + t * latLng2.latitude,
(1 - t) * latLng1.longitude + t * latLng2.longitude
))
}
return points
}