两条线段之间的最短距离 [英] Shortest distance between two line segments
问题描述
我需要一个函数来找出两条线段之间的最短距离。线段由两个端点定义。因此,例如我的一条线段(AB)将由两个点A(x1,y1)和B(x2,y2)定义,另一个(CD)将由两个点C(x1,y1)定义。和D(x2,y2)。
随意用任何你想要的语言编写解决方案,我可以把它翻译成javascript。请记住我的几何技能非常生锈。我已经看过 here 我不知道如何将其转换为函数。非常感谢你的帮助。
这是2维吗?如果是这样,答案只是A点和CD线段,B和CD,C和AB或D和AB之间的最短距离。所以这是一个非常简单的点与线之间的距离计算(如果距离完全相同,那么这些线是平行的)。
它在三维方面稍微有些棘手,因为线条不一定在同一个平面上,但在这里似乎并不是这种情况?
I need a function to find the shortest distance between two line segments. A line segment is defined by two endpoints. So for example one of my line segments (AB) would be defined by the two points A (x1,y1) and B (x2,y2) and the other (CD) would be defined by the two points C (x1,y1) and D (x2,y2).
Feel free to write the solution in any language you want and I can translate it into javascript. Please keep in mind my geometry skills are pretty rusty. I have already seen here and I am not sure how to translate this into a function. Thank you so much for help.
Is this in 2 dimensions? If so, the answer is simply the shortest of the distance between point A and line segment CD, B and CD, C and AB or D and AB. So it's a fairly simple "distance between point and line" calculation (if the distances are all the same, then the lines are parallel).
This site explains the algorithm for distance between a point and a line pretty well.
It's slightly more tricky in the 3 dimensions because the lines are not necessarily in the same plane, but that doesn't seem to be the case here?
这篇关于两条线段之间的最短距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!