确定一个点是否在道路上
如果我有一条描述道路的折线,并且我知道道路所有部分的宽度,是否有一种算法可以用来确定一个点是否在道路上?我不完全确定如何执行此操作,因为该线本身的宽度为 1px。
谢谢,
杰夫
If I have a polyline that describes a road and I know the road width at all parts, is there an algorithm I can use to determine if a point is on the road? I'm not entirely sure how to do this since the line itself has a width of 1px.
thanks,
Jeff
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
找到点到线的最小距离(它将是垂直于线的向量)。实际计算中,P0为路段的第一个点,v为路段向量,w为从P0到该点的向量。您必须迭代折线中的每条边。如果距离小于该路段的宽度,则该路段“在”道路上。
拐角可能会很棘手,具体取决于您将它们视为圆形(恒定半径)还是有角度。
Find the minimum distance of the point to the line (it will be a vector perpendicular to the line). Actual calculation where P0 is the first point of the road segment, v is the road segment vector and w is the vector from P0 to the point in question. You will have to iterate over each edge in the polyline. If the distance is less than the width of that segment, then it is "on" the road.
The corners might be tricky depending on if you treat them as rounded (constant radius) or angular.
也许您可以获取每个线段,构建线段的矩形+其宽度,并使用矩形/点碰撞算法来确定矩形是否包含该点。一个好的算法会考虑 width = 1 的情况,它应该简单地尝试构建线段的反函数并确定 y-1(point.y) 是否是 line_segment.x1 和 line_segment.x2 之间的 x
Perhaps you could take each line segment, build the rectangle of the line segment + its width, and use rectangle/point collision algorithms to determine if the rectangle contains the point. A good algorithm will account for the width = 1 scenario, which should simply attempt to build the inverse function of the line segment and determine if y-1(point.y) is an x between line_segment.x1 and line_segment.x2