如何找到沿航向距线段指定距离的第一个点?

发布于 2024-08-20 02:31:07 字数 666 浏览 12 评论 0原文

给定起点、航向、距离和线段,找到沿该航向距该线段指定距离的第一个点。

我报道了两个案例,但我没能报道最后一个。

第一种情况:偏离线路。即使起点在指定距离内,也忽略它。

第二种情况:与直线相交。我用三角函数和三角形解决了这个问题。最初没有考虑下一种情况。

第三种情况:它正在朝着直线前进,但没有与直线相交。我认为如果做得正确的话,这也可以解决第二种情况。

三种子情况:

  1. 最小线距离大于指定距离。忽略它。

  2. 最小线距等于指定距离。已找到点。

  3. 最小线距小于指定距离。这意味着从沿航向到线段端点的垂直线小于所需的距离。这也意味着在这条垂直线的两侧将有两条所需距离的线。一个垂直于航向,而另一个最接近同一端点但不垂直于航向。只需找到这些点并查看哪一个距离起点更近即可。

这就是我今天被困的地方。绘制它很容易,但进行矢量计算或其他任何事情却很棘手。

可以将其改写为:

在什么时间 P(t) = P0 + t*v 距离线段 L 的距离为 D ((x1,y1),(x2,y2))?

v=(sin(heading), -cos(heading)) 在我的例子中。

Given a starting point, a heading, a distance, and a line segment, find the first point along this heading that is the specified distance away from this line segment.

I covered two cases, but I haven't been able to cover the last one.

First case: heading away from the line. Ignore it even if the starting point is within the specified distance.

Second case: It intersects the line. I solved it using trig and triangles. Initially didn't consider the next case.

Third case: It is heading towards the line, but it does not intersect it. I think this will solve the second case as well if it's done correctly.

Three subcases:

  1. The minimum line distance is greater than the specified distance. Ignore it.

  2. The minimum line distance is equal to the specified distance. Found the points already.

  3. The minimum line distance is less than the specified distance. This means there is a perpendicular line from the along the heading to an endpoint of the line segment that is less than the distance needed. This also means that on either side of this perpendicular line will be two lines of the distance needed. One is perpendicular to the heading, while the other is closest to the same endpoint and not perpendicular to the heading. Just a matter of finding those points and seeing which one is closer to the start point.

This is where I am stuck today. Drawing it up was easy, but doing the vector calc or whatever turned out tricky.

It's possible to rephrase this as:

At what time(s) is P(t) = P0 + t*v at a distance D from the line segment L((x1,y1), (x2,y2))?

v=(sin(heading), -cos(heading)) in my case.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

陌上芳菲 2024-08-27 02:31:07

射击你的解决方案并不总是有效。我找到了一个反例:

Line Segment = (0,0) -> (0,14)

起点 = (19, 6) @ 向西/逆时针方向-159.5 或 200.5

它将与线相交于 (2.952, 0.0) 所以我问,它在 0.0 距离内的位置。

我得到的结果是不正确的。

http://img5.imageshack.us/i/failuref.png/

如何我可以判断哪些解决方案可以使用您的解决方案,哪些不起作用取决于点和线段之间的最小起始距离是否创建垂直线。

如果我可以在下一篇文章中再贴一张图片,我会放上成功的例子。

我本来想发布一些生成这些图像的 Sage 代码,但不幸的是代码标签接受 python。

Shoot mang your solution doesn't always work. I found a counter example:

Line Segment = (0,0) -> (0,14)

Start Point = (19, 6) @ heading -159.5 or 200.5 in west/counter-clockwise

It will intersect the line at (2.952, 0.0) so I ask, where does it it come within a distance of 0.0.

The result I get is incorrect.

http://img5.imageshack.us/i/failuref.png/

How I can tell which ones will work using your solution and which ones do not work depends whether the minimum starting distance between the point and the line segment creates a perpendicular line.

If I can post another picture in the next post, I will put the successful example.

I would have liked to post some code for Sage which produced those images, but the code tags are accepting python unfortunately.

昨迟人 2024-08-27 02:31:07

点与线段之间的最小起始距离垂直于线段的成功结果:

http://img46.imageshack.us/i/success.png/

A successful result where the minimum starting distance between the point and the line segment is perpendicular to the line segment:

http://img46.imageshack.us/i/success.png/

好倦 2024-08-27 02:31:07

嗨,我最终想出了解决方案。

  1. 射线是否与平行且距线段指定距离 D 的线段相交。只需绘制一个矩形并检查与线段平行的边。

  2. 射线是否在线段的每个端点处与半径为 D 的圆相交。

  3. 最小化总单位时间以找到沿射线距线段 D 的第一个点。

可能的边界情况:起点是否在 D 范围内并且远离线?由用户如何处理这种情况。

Hi the solution I eventually came up with.

  1. Does the ray intersect line segments that are parallel and the specified distance D away from the line segment. Just drawing a rectangle and checking the sides parallel to the line segment.

  2. Does the ray intersect circles of radius D at each end point of the line segment.

  3. Minimize for total unit time to find the first point along the ray that is D away from the line segment.

Possible Border case: Is the start point within D and heads away from the line? Up to the user how to handle this case.

骄兵必败 2024-08-27 02:31:07

谢谢,这有效。
我这样找到了阿尔法:

heading = 45.0*pi/180. #heading 45 degrees.
if x1 > x2: #line segment (x1,y1)<->(x2,y2)
    dx = x2 - x1
    dy = y2 - y1
else:
    dx = x1 - x2
    dy = y1 - y2

segmentHeading = atan2(dx, dy)

if heading > 0:
    alpha = segmentHeading + heading
else:
    alpha = -segmentHeading + heading

t = abs( (dStart - D) / -cos(alpha) ) #-cos in python, sin in C.

Thanks, that works.
I found the alpha this way:

heading = 45.0*pi/180. #heading 45 degrees.
if x1 > x2: #line segment (x1,y1)<->(x2,y2)
    dx = x2 - x1
    dy = y2 - y1
else:
    dx = x1 - x2
    dy = y1 - y2

segmentHeading = atan2(dx, dy)

if heading > 0:
    alpha = segmentHeading + heading
else:
    alpha = -segmentHeading + heading

t = abs( (dStart - D) / -cos(alpha) ) #-cos in python, sin in C.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文