Given the end-vertices of two line segments, how do you calculate the point at which they intersect?

40 Views Asked by At

Given only the vertices of each line segment, and it's assumed they intersect, how do I calculate the point at which they intersect (in two and additionally three dimensions)?

1

There are 1 best solutions below

0
On

Suppose that the vertices of the first segment are $A$ and $B$. Let $P$ and $Q$ be those of the second segment.

Write $tA+(1-t)B=sP+(1-s)Q$ and build a system of equations. One equation for each coordinate. So, you will get two equations for 2D and three equations for 3D. Solve for $t$ and $s$, if possible. Note that in 3D there are more equations than unknowns, so the general case is that there is no solution (if you have problems to decide whether such a system is compatible or not, just tell).

If the system is compatible and the values obtained for both $t$ and $s$ are between $0$ and $1$ (this means that the lines containing the segments intersect between the vertices in both lines), the segments intersect. Otherwise they don't. You can find the intersention substituting, for example, the obtained value for $t$ in $tA+(1-t)B$.