How can I find the points at which two 2D lines are a specific distance apart?
Solution 1:
Let the two lines be $\mathbf{P_1}(t) $ and $\mathbf{P_2}(t) $ then we can write
$\mathbf{P_1}(t) = \mathbf{Q_1} + t \mathbf{V_1} $
$\mathbf{P_2} (t) = \mathbf{Q_2} + t \mathbf{V_2} $
It can be assumed that the direction vectors $\mathbf{V_1} $ and $\mathbf{V_2}$ are unit vectors. To obtain the algebraic equations, Let unit vector $\mathbf{U_1} $ be orthogonal to $\mathbf{V_1}$ and unit vector $\mathbf{U_2}$ be orthogonal to $\mathbf{V_2} $, then
$ \mathbf{U_1} \cdot ( (x, y) - \mathbf{Q_1} ) = 0 $
$ \mathbf{U_2} \cdot ( (x, y) - \mathbf{Q_2} ) = 0 $
are the algebraic equations of the two lines. To find which points on the first line are $d$ units from the second line, use the distance formula, and keep in mind that $\mathbf{U_1}, \mathbf{U_2}$ are unit vectors. So now we have,
$ d = | \mathbf{U_2} \cdot (\mathbf{Q_1} - \mathbf{Q_2} + t \mathbf{V_1} ) |$
and this equation is of the form
$ d = | a + b t | $
its $t$ solutions are $t_1 = \dfrac{d - a}{b} $ and $t_2 = \dfrac{ - a - d }{b} $
Plugging these values in the parametric equation of the first line gives the required points.
The same procedure can be repeated for points on the second line that are $d$ units away from the first line, resulting in two solutions as well.
Solution 2:
Suppose you want to find the points on line $\mathbf{P_a}$. You can write two scalar equations for $u_a$ and $u_b$: $$ \cases{ (\mathbf{P_a}-\mathbf{P_b})\cdot(\mathbf{P_4}-\mathbf{P_3})=0\\ (\mathbf{P_a}-\mathbf{P_b})\cdot(\mathbf{P_a}-\mathbf{P_b})=D^2 } $$ Solve the first equation (which is linear) for $u_b$ and substitute into the second equation, to find a resolvent quadratic equation in $u_a$.
Solution 3:
Recall : any line with equation
$$ux+vy+w=0$$ can be written (by dividing by $\sqrt{u^2+v^2}$) under the form (sometimes called the Euler form of the equation)
$$ x \cos \alpha + y \sin \alpha - p = 0$$
with a unique value for $\alpha$ (polar angle of the normal vector) and $p$ which has the interesting meaning of signed (shortest) distance from the origin to the line.
Therefore, there is a simple solution of your problem in 3 steps.
-
obtain the equation of line $P_3P_4$ under its Euler form.
-
consider lines which are offset lines of line $P_3P_4$ (parallel to it) at the desired distance $D$, i.e., with equations :
$$\begin{cases}(L_1): \ \ & x \cos \alpha &+& y \sin \alpha &-& (p+D) &=& 0 \\ (L_2):\ \ & x \cos \alpha &+& y \sin \alpha &-& (p-D)& =& 0\end{cases}$$
- compute the intersections of $(L_1)$ and $(L_2)$ with the second line $P_1P_2$.