How can I find the points at which two 2D lines are a specific distance apart? I have two infinite lines in 2-dimensional space that are each defined by two $(x, y)$ points that they run through. The equations of the lines are:
$$\mathbf{P_a} = \mathbf{P1} + u_a(\mathbf{P2} - \mathbf{P1})$$
$$\mathbf{P_b} = \mathbf{P3} + u_b(\mathbf{P4} - \mathbf{P3})$$
Assuming these lines are not parallel, then for any given positive distance $D$, there will be exactly two points on each line where the closest point on the other line is exactly $D$ distance away, as seen on the below diagram. (For clarity/simplicity, only the points on the $\mathbf{P1} \to \mathbf{P2}$ line are shown, but they of course exist on the other line as well.) (If the lines are parallel, then there will be either zero or infinity such points. If $D$ is zero, then there will only be one point; i.e. the actual intersection point.)

So my question is, given these two lines and a desired distance $D$, how do I calculate the two $u_a$ values corresponding to the points on the $\mathbf{P1} \to \mathbf{P2}$ line at which the closest point on the other line is exactly $D$ distance apart? (I am specifically interested in the $u_a$ values; I do not need the actual $(x, y)$ points for my purposes, and if I did they would be trivial to calculate by substituting $u_a$ into the above equation. Obviously I can calculate the $u_a$ value from an $(x, y)$ point, but since this will ultimately be used in performance-critical computer code, I would prefer to not have to do that calculation if I can avoid it.)
Here's what you can assume:

*

*The lines are not parallel or coinciding. (Though if the solution can "let me know" when the lines are parallel, that would be ideal.)

*That $\mathbf{P1} \neq \mathbf{P2}$ and $\mathbf{P3} \neq \mathbf{P4}$

*That $D > 0$. (Though I'm guessing most solutions will also work for $D = 0$ and the two output $u_a$ values will simply be equal.)

This question is the closest I've found to mine, but there are a couple of key differences:

*

*That question is about lines in 3D space, and my question is about lines in 2D space. (Which I assume makes the answer significantly simpler.)

*My lines are specifically defined by pairs of points that they run through.

 A: 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.
A: 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$.
A: 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$.

