Find lines segment portions close together
Here is a derivation that shows how to solve this problem, using a bit of vector arithmetic.

You can project a point $P$ onto the line $A_1B_1$ using vector arithmetic; in particular, the projection of $P$ is $${(B_1-A_1)^\top (P-A_1) \over \|B_1-A_1\|_2^2} (B_1-A_1) + A_1,$$ where $v^\top$ denotes the transpose of vector $v$, so the vector measuring the orthogonal distance from $A_1B_1$ to $P$ is

$$D=P-{(B_1-A_1)^\top (P-A_1) \over \|B_1-A_1\|_2^2} (B_1-A_1)  - A_1.$$

Every point $P$ on the line segment $A_2B_2$ has the form $P=\alpha A_2 + (1-\alpha)B_2$, for some $\alpha \in [0,1]$.  So, we can write $D$ in the form

$$
\begin{align*}
D=\;&amp;\alpha A_2 + (1-\alpha)B_2 - A_1\\
 &amp;- {(B_1-A_1)^\top (\alpha A_2 + (1-\alpha)B_2-A_1) \over \|B_1-A_1\|_2^2} (B_1-A_1).
\end{align*}
$$

Notice that this is a linear function of $\alpha$, when $A_1,B_1,A_2,B_2$ are fixed.



Let the $x,y$-coordinates of $D$ be $x_D,y_D$, i.e., $D=(x_D,y_D)$.  The above equation implies that there are constants $a_0,a_1,a_2,a_3$ such that

$$x_D=a_0 \alpha + a_1, y_D = a_2 \alpha + a_3.$$

The $a_0,\dots,a_3$ depend only on $A_1,A_2,B_1,B_2$ (but not on $\alpha$) and can be readily computed using the formula above.

Now we want this vector $D$ to be of length at most $\tau$, i.e., $\|D\|_2 \le \tau$.  In other words, we want

$$x_D^2 + y_D^2 \le \tau.$$

This is equivalent to

$$(a_0 \alpha + a_1)^2 + (a_2 \alpha + a_3)^2 \le \tau.$$

That is a quadratic in the unknown $\alpha$, so we can readily find the range of $\alpha$ where this inequality holds by using the quadratic formula (basically, find the roots of the quadratic equation $(a_0 \alpha + a_1)^2 + (a_2 \alpha + a_3)^2 = \tau$, and these are the endpoints of that range, except that you should clamp to the range $[0,1]$).  Say that the inequality holds for $\alpha$ in the range $[\alpha_\ell,\alpha_u]$.  Then it follows that the points on the line segment $A_3B_3$ are all of distance at most $\tau$ to the line $A_1B_1$, where $A_3 = \alpha_\ell A_2 + (1-\alpha_\ell) B_2$ and $B_3 = \alpha_u A_2 + (1-\alpha_u) B_2$.

This would describe how to find all points on the line segment $A_2B_2$ that are distance at most $\tau$ from the line connecting $A_1$ and $B_1$.  However, we really want to find all points that are distance at most $\tau$ from the line segment $A_1B_1$.  So, we want to constrain the projection of $P$ to be between $A_1$ and $B_1$, i.e., we want to constrain $D$ to be between $0$ and $B_1-A_1$.  By solving systems of linear equations, you can find $\alpha_0$ such that $(a_0 \alpha_0+a_1,b_0 \alpha_0+b_1)=(0,0)$ and $(a_0 \alpha_1+a_1,b_0 \alpha_1+b_1)=B_1-A_1$.  Then, we replace $[\alpha_\ell,\alpha_u]$ (obtained above by the quadratic formula) with the intersection of ranges $[\alpha_\ell,\alpha_u] \cap [\alpha_0,\alpha_1]$.  This gives us all points on the line segment $A_2B_2$ that are distance at most $\tau$ from the line segment $A_1B_1$.

This solves your question of how to find all points on the line segment $A_2B_2$ that are distance at most $\tau$ from the line segment $A_1B_1$.  You can repeat the same procedure a second time to find all points on the line segment $A_1B_1$ that are distance at most $\tau$ from $A_2B_2$.