如何在距线段指定距离的航向上找到第一个点? [英] How can I find the first point along a heading that is a specified distance away from a line segment?

查看:103
本文介绍了如何在距线段指定距离的航向上找到第一个点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

三个子情况:

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

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

最小行距等于指定距离.已经找到了要点.

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

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

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.

可以将其改写为:

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

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)).

推荐答案

谢谢. 我是这样找到Alpha的:

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.

这篇关于如何在距线段指定距离的航向上找到第一个点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆