球体表面上的射线-多边形交点
我有一个点(纬度/经度)和一个以度为单位的航向(正北),该点沿着该点行进。 我有许多固定多边形(以纬度/经度定义的点),它们可能是凸的,也可能不是凸的。
我的问题是,如何计算与多边形最近的交点(如果有)。 我看过一些关于光线追踪的令人困惑的帖子,但当光线和多边形不在同一平面上并且多边形必须是凸的时,它们似乎都与 3D 相关。
I have a point (Lat/Lon) and a heading in degrees (true north) for which this point is traveling along. I have numerous stationary polygons (Points defined in Lat/Lon) which may or may not be convex.
My question is, how do I calculate the closest intersection point, if any, with a polygon. I have seen several confusing posts about Ray Tracing but they seem to all relate to 3D when the Ray and Polygon are not on the same Plane and also the Polygons must be convex.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
听起来你应该能够做一个简单的二维线相交...
但是我之前曾使用过纬度/经度,并且知道它们对于任何二维坐标系都不完全正确。
我将从通用的“IsPointInPolygon”函数开始,您可以通过谷歌搜索找到一百万个函数,然后在您的多边形上测试它,看看它的工作效果如何。 如果它们足够准确,就使用它。 但由于纬度/经度坐标的非方形性质,您可能需要使用球面几何进行一些修改。
sounds like you should be able to do a simple 2d line intersection...
However I have worked with Lat/Long before and know that they aren't exactly true to any 2d coordinate system.
I would start with a general "IsPointInPolygon" function, you can find a million of them by googling, and then test it on your poly's to see how well it works. If they are accurate enough, just use that. But it is possible that due to the non-square nature of lat/long coordinates, you may have to do some modifications using Spherical geometry.
在 2D 中,计算相当简单......
您始终可以首先检查以确保光线的端点不在多边形内部(因为在这种情况下这是交点)。
如果端点不在直线上,您可以与多边形的每个边界特征进行射线/线段相交,并使用最近找到的位置。 处理凸/凹特征等。
In 2D, the calculations are fairly simple...
You could always start by checking to make sure the ray's endpoint is not inside the polygon (since that's the intersection point in that case).
If the endpoint is out of the line, you could do a ray/line segment intersection with each of the boundary features of the polygon, and use the closest found location. That handles convex/concave features, etc.
使用此技术计算光线是否与多边形中的每条线段相交 。
(我接受的)答案(我称之为
h
)中得到的缩放因子是“沿光线的交点有多远”。 您正在寻找0
和1
之间的值。如果有多个交点,那就没问题了! 如果您想要“第一个”,请使用
h
值最小的那个。Compute whether the ray intersects each line segment in the polygon using this technique.
The resulting scaling factor in (my accepted) answer (which I called
h
) is "How far along the ray is the intersection." You're looking for a value between0
and1
.If there are multiple intersection points, that's fine! If you want the "first," use the one with the smallest value of
h
.