连接两个线段 [英] Connect two Line Segments
问题描述
考虑你的两条线段A和B分别由两个点表示:
line A表示为A1(x,y) ,A2(x,y)
由B1(x,y)B2(x,y)表示的行B
首先检查两条线是否使用此算法相交。
如果它们相交,那么两条线之间的距离为零,连接它们的线段就是交点。 p>
如果它们不相交,请使用此方法: http://local.wasp.uwa.edu.au/~pbourke/geometry/pointline/ 计算最短距离:
- A1点和B点
- A2点和B点
- 点B1和A线
- 点B2和线A
- 点B1和A线
这四条线段中最短的线段是你的答案。
Given two 2D line segments, A and B, how do I calculate the length of the shortest 2D line segment, C, which connects A and B?
Consider your two line segments A and B to be represented by two points each:
line A represented by A1(x,y), A2(x,y)
Line B represented by B1(x,y) B2(x,y)
First check if the two lines intersect using this algorithm.
If they do intersect, then the distance between the two lines is zero, and the line segment joining them is the intersection point.
If they do not intersect, Use this method: http://local.wasp.uwa.edu.au/~pbourke/geometry/pointline/ to calculate the shortest distance between:
- point A1 and line B
- Point A2 and line B
- Point B1 and line A
- Point B2 and line A
The shortest of those four line segments is your answer.
这篇关于连接两个线段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!