多个纬度/经度点的半径

时间:2021-10-13 15:06:40

I have a program that takes as input an array of lat/long points. I need to perform a check on that array to ensure that all of the points are within a certain radius. So, for example, the maximum radius I will allow is 100 miles. Given an array of lat/long (coming from a MySQL database, could be 10 points could be 10000) I need to figure out if they will all fit in a circle with radius of 100 miles.

我有一个程序,它将lat / long点数组作为输入。我需要对该数组执行检查以确保所有点都在某个半径范围内。因此,例如,我允许的最大半径是100英里。给定一个lat / long数组(来自MySQL数据库,可能是10个点可能是10000)我需要弄清楚它们是否都适合半径为100英里的圆。

Kinda stumped on how to approach this. Any help would be greatly appreciated.

有点难过如何处理这个问题。任何帮助将不胜感激。

4 个解决方案

#1


5  

Find the smallest circle containing all points, and compare its radius to 100.

找到包含所有点的最小圆,并将其半径与100进行比较。

#2


1  

It's easiest way for me to solve this is by converting the coordinates to (X,Y,Z), then finding the distance along a sphere.

对我来说,解决这个问题的最简单方法是将坐标转换为(X,Y,Z),然后找到沿球体的距离。

Assuming Earth is a sphere (totally untrue) with radius R...

假设地球是一个半径为R的球体(完全不真实)......

X = R * cos(long) * cos(lat)

X = R * cos(长)* cos(纬度)

Y = R * sin(long) * cos(lat)

Y = R * sin(长)* cos(纬度)

Z = R * sin(lat)

Z = R * sin(纬度)

At this point, you can approximate the distance between the points using the extension of the pythagorean theorem for threespace:

此时,您可以使用三面体的毕达哥拉斯定理的扩展来近似点之间的距离:

dist = sqrt((x1-x2)^2 + (y1-y2)^2 + (z1-z2)^2)

dist = sqrt((x1-x2)^ 2 +(y1-y2)^ 2 +(z1-z2)^ 2)

But to find the actual distance along the surface, you're going to need to know the angle subtended by the two points from the origin (center of the Earth).

但要找到沿表面的实际距离,您需要知道原点(地球中心)的两个点所对的角度。

Representing your locations as vectors V1 = (X1, Y1, Z1) and V2 = (X2, Y2, Z2), the angle is:

将您的位置表示为矢量V1 =(X1,Y1,Z1)和V2 =(X2,Y2,Z2),角度为:

angle = arcsin((V1 x V2) / (|V1||V2|)), where x is the cross-product.

angle = arcsin((V1 x V2)/(| V1 || V2 |)),其中x是叉积。

The distance is then:

那么距离是:

dist = (Earth's circumference) * angle / (2 * pi)

dist =(地球周长)*角度/(2 * pi)

Of course, this doesn't take into account changes in elevation or the fact that the Earth is wider at the equator.

当然,这并没有考虑到海拔的变化或地球在赤道上更宽的事实。

Apologies for not writing my math in LaTeX.

抱歉不在LaTeX中写我的数学。

#3


1  

The answer below involves pretending that the earth is a perfect sphere, which should give a more accurate answer than treating the earth as a flat plane.

下面的答案涉及假装地球是一个完美的球体,这应该给出比将地球视为平面更准确的答案。

To figure out the radius of a set of lat/lon points, you must first ensure that your set of points is "hemispherical", ie. all the points can fit into some arbitrary half of your perfect sphere.

要计算一组纬度/经度点的半径,首先必须确保您的点集是“半球形”,即。所有的点都可以适合你完美球体的任意一半。

Check out Section 3 in the paper "Optimal algorithms for some proximity problems on the Gaussian sphere with applications" by Gupta and Saluja. I don't have a specific link, but I believe that you can find a copy online for free. This paper is not sufficient to implement a solution. You'll also need Appendix 1 in "Approximating Centroids for the Maximum Intersection of Spherical Polygons" by Ha and Yoo.

查看Gupta和Saluja撰写的“应用高斯球的某些接近问题的最优算法”一文中的第3节。我没有具体的链接,但我相信你可以在网上免费找到一份。本文不足以实施解决方案。您还需要Ha和Yoo的“逼近球面多边形最大交点的质心”中的附录1。

I wouldn't use Megiddo's algorithm for doing the linear programming part of the hemisphericity testing. Instead, use Seidel's algorithm for solving Linear Programming problems, described in "Small-Dimensional Linear Programming and Convex Hulls Made Easy" by Raimund Seidel. Also see "Seidel’s Randomized Linear Programming Algorithm" by Kurt Mehlhorn and Section 9.4 from "Real-Time Collision Detection" by Christer Ericson.

我不会使用Megiddo的算法来进行半球性测试的线性编程部分。相反,使用Seidel的算法来解决线性规划问题,由Raimund Seidel在“小维线性规划和凸壳变得容易”中描述。另请参阅Kurt Mehlhorn的“Seidel的随机线性规划算法”和Christer Ericson的“实时碰撞检测”的第9.4节。

Once you have determined that your points are hemispherical, move on to Section 4 of the paper by Gupta and Saluja. This part shows how to actually get the "smallest enclosing circle" for the points.

一旦确定您的点是半球形的,请转到Gupta和Saluja的论文第4部分。这部分展示了如何实际获得点的“最小封闭圆”。

To do the required quadratic programming, see the paper "A Randomized Algorithm for Solving Quadratic Programs" by N.D. Botkin. This tutorial is helpful, but the paper uses (1/2)x^T G x - g^T x and the web tutorial uses (1/2)x^T H x + c^T x. One adds the terms and the other subtracts, leading to sign-related problems. Also see this example 2D QP problem. A hint: if you're using C++, the Eigen library is very good.

要进行所需的二次规划,请参阅N.D. Botkin的论文“用于求解二次规划的随机算法”。本教程很有帮助,但本文使用(1/2)x ^ T G x - g ^ T x,网络教程使用(1/2)x ^ T H x + c ^ T x。一个添加术语和其他减法,导致与符号相关的问题。另请参阅此示例2D QP问题。提示:如果您使用的是C ++,那么Eigen库非常好。

This method is a little more complicated than some of the 2D methods above, but it should give you more accurate results than just ignoring the curvature of the earth completely. This method also has O(n) time complexity, which is likely asymptotically optimal.

这种方法比上面的一些2D方法稍微复杂一点,但它应该给你更准确的结果,而不是完全忽略地球的曲率。该方法还具有O(n)时间复杂度,其可能是渐近最优的。

Note: The method described above may not handle duplicate data well, so you may want to check for duplicate lat/lon points before finding the smallest enclosing circle.

注意:上述方法可能无法很好地处理重复数据,因此您可能需要在找到最小的封闭圆之前检查重复的纬度/经度点。

#4


0  

Check out the answers to this question. It gives a way to measure the distance between any two (lat,long) points. Then use a smallest enclosing circle algorithm.

看看这个问题的答案。它提供了一种测量任意两个(纬度,长度)点之间距离的方法。然后使用最小的封闭圆算法。

I suspect that finding a smallest enclosing circle may be difficult enough on a plane, so to eliminate the subtleties of working with latitude and longitude and spherical geometry, you should probably consider mapping your points to the XY plane. That will introduce some amount of distortion, but if your intended scale is 100 miles you can probably live with that. Once you have a circle and its center on the XY plane, you can always map back to the terrestial sphere and re-check your distances.

我怀疑在平面上找到一个最小的封闭圆可能很难,所以为了消除使用纬度和经度以及球面几何的微妙之处,你应该考虑将你的点映射到XY平面。这将引入一些扭曲,但如果你的预期规模是100英里,你可能会接受它。一旦您在XY平面上有一个圆及其中心,您就可以始终映射回地球并重新检查您的距离。

#1


5  

Find the smallest circle containing all points, and compare its radius to 100.

找到包含所有点的最小圆,并将其半径与100进行比较。

#2


1  

It's easiest way for me to solve this is by converting the coordinates to (X,Y,Z), then finding the distance along a sphere.

对我来说,解决这个问题的最简单方法是将坐标转换为(X,Y,Z),然后找到沿球体的距离。

Assuming Earth is a sphere (totally untrue) with radius R...

假设地球是一个半径为R的球体(完全不真实)......

X = R * cos(long) * cos(lat)

X = R * cos(长)* cos(纬度)

Y = R * sin(long) * cos(lat)

Y = R * sin(长)* cos(纬度)

Z = R * sin(lat)

Z = R * sin(纬度)

At this point, you can approximate the distance between the points using the extension of the pythagorean theorem for threespace:

此时,您可以使用三面体的毕达哥拉斯定理的扩展来近似点之间的距离:

dist = sqrt((x1-x2)^2 + (y1-y2)^2 + (z1-z2)^2)

dist = sqrt((x1-x2)^ 2 +(y1-y2)^ 2 +(z1-z2)^ 2)

But to find the actual distance along the surface, you're going to need to know the angle subtended by the two points from the origin (center of the Earth).

但要找到沿表面的实际距离,您需要知道原点(地球中心)的两个点所对的角度。

Representing your locations as vectors V1 = (X1, Y1, Z1) and V2 = (X2, Y2, Z2), the angle is:

将您的位置表示为矢量V1 =(X1,Y1,Z1)和V2 =(X2,Y2,Z2),角度为:

angle = arcsin((V1 x V2) / (|V1||V2|)), where x is the cross-product.

angle = arcsin((V1 x V2)/(| V1 || V2 |)),其中x是叉积。

The distance is then:

那么距离是:

dist = (Earth's circumference) * angle / (2 * pi)

dist =(地球周长)*角度/(2 * pi)

Of course, this doesn't take into account changes in elevation or the fact that the Earth is wider at the equator.

当然,这并没有考虑到海拔的变化或地球在赤道上更宽的事实。

Apologies for not writing my math in LaTeX.

抱歉不在LaTeX中写我的数学。

#3


1  

The answer below involves pretending that the earth is a perfect sphere, which should give a more accurate answer than treating the earth as a flat plane.

下面的答案涉及假装地球是一个完美的球体,这应该给出比将地球视为平面更准确的答案。

To figure out the radius of a set of lat/lon points, you must first ensure that your set of points is "hemispherical", ie. all the points can fit into some arbitrary half of your perfect sphere.

要计算一组纬度/经度点的半径,首先必须确保您的点集是“半球形”,即。所有的点都可以适合你完美球体的任意一半。

Check out Section 3 in the paper "Optimal algorithms for some proximity problems on the Gaussian sphere with applications" by Gupta and Saluja. I don't have a specific link, but I believe that you can find a copy online for free. This paper is not sufficient to implement a solution. You'll also need Appendix 1 in "Approximating Centroids for the Maximum Intersection of Spherical Polygons" by Ha and Yoo.

查看Gupta和Saluja撰写的“应用高斯球的某些接近问题的最优算法”一文中的第3节。我没有具体的链接,但我相信你可以在网上免费找到一份。本文不足以实施解决方案。您还需要Ha和Yoo的“逼近球面多边形最大交点的质心”中的附录1。

I wouldn't use Megiddo's algorithm for doing the linear programming part of the hemisphericity testing. Instead, use Seidel's algorithm for solving Linear Programming problems, described in "Small-Dimensional Linear Programming and Convex Hulls Made Easy" by Raimund Seidel. Also see "Seidel’s Randomized Linear Programming Algorithm" by Kurt Mehlhorn and Section 9.4 from "Real-Time Collision Detection" by Christer Ericson.

我不会使用Megiddo的算法来进行半球性测试的线性编程部分。相反,使用Seidel的算法来解决线性规划问题,由Raimund Seidel在“小维线性规划和凸壳变得容易”中描述。另请参阅Kurt Mehlhorn的“Seidel的随机线性规划算法”和Christer Ericson的“实时碰撞检测”的第9.4节。

Once you have determined that your points are hemispherical, move on to Section 4 of the paper by Gupta and Saluja. This part shows how to actually get the "smallest enclosing circle" for the points.

一旦确定您的点是半球形的,请转到Gupta和Saluja的论文第4部分。这部分展示了如何实际获得点的“最小封闭圆”。

To do the required quadratic programming, see the paper "A Randomized Algorithm for Solving Quadratic Programs" by N.D. Botkin. This tutorial is helpful, but the paper uses (1/2)x^T G x - g^T x and the web tutorial uses (1/2)x^T H x + c^T x. One adds the terms and the other subtracts, leading to sign-related problems. Also see this example 2D QP problem. A hint: if you're using C++, the Eigen library is very good.

要进行所需的二次规划,请参阅N.D. Botkin的论文“用于求解二次规划的随机算法”。本教程很有帮助,但本文使用(1/2)x ^ T G x - g ^ T x,网络教程使用(1/2)x ^ T H x + c ^ T x。一个添加术语和其他减法,导致与符号相关的问题。另请参阅此示例2D QP问题。提示:如果您使用的是C ++,那么Eigen库非常好。

This method is a little more complicated than some of the 2D methods above, but it should give you more accurate results than just ignoring the curvature of the earth completely. This method also has O(n) time complexity, which is likely asymptotically optimal.

这种方法比上面的一些2D方法稍微复杂一点,但它应该给你更准确的结果,而不是完全忽略地球的曲率。该方法还具有O(n)时间复杂度,其可能是渐近最优的。

Note: The method described above may not handle duplicate data well, so you may want to check for duplicate lat/lon points before finding the smallest enclosing circle.

注意:上述方法可能无法很好地处理重复数据,因此您可能需要在找到最小的封闭圆之前检查重复的纬度/经度点。

#4


0  

Check out the answers to this question. It gives a way to measure the distance between any two (lat,long) points. Then use a smallest enclosing circle algorithm.

看看这个问题的答案。它提供了一种测量任意两个(纬度,长度)点之间距离的方法。然后使用最小的封闭圆算法。

I suspect that finding a smallest enclosing circle may be difficult enough on a plane, so to eliminate the subtleties of working with latitude and longitude and spherical geometry, you should probably consider mapping your points to the XY plane. That will introduce some amount of distortion, but if your intended scale is 100 miles you can probably live with that. Once you have a circle and its center on the XY plane, you can always map back to the terrestial sphere and re-check your distances.

我怀疑在平面上找到一个最小的封闭圆可能很难,所以为了消除使用纬度和经度以及球面几何的微妙之处,你应该考虑将你的点映射到XY平面。这将引入一些扭曲,但如果你的预期规模是100英里,你可能会接受它。一旦您在XY平面上有一个圆及其中心,您就可以始终映射回地球并重新检查您的距离。