# find parametric varable in terms of the distance from a point to a line

I have two lines defined by a point and a vector:

• $Q(s) = A + s\vec{v}$
• $P(t) = B + t\vec{u}$

Suppose distance d is given

I want to know $s$ and $t$ for points $P$ and $Q$ in terms of $d$. $d$ is perpendicular to $line(B, \vec{u})$

so I found out (wikipedia):

\begin{aligned} d & = ||(B - Q) - ((B - Q).\vec{u})\vec{u}|| \\ & = ||(B - A - s\vec{v}) - ((B - A - s\vec{v})\cdot\vec{u})\vec{u}|| \\ & = ||(\vec{w} - s\vec{v}) - ((\vec{w} - s\vec{v})\cdot\vec{u})\vec{u} || \end{aligned}

Can somebody explain the algebra to write $s$ in terms of $d$

$$s = f(d) = \dots$$

-
I wouldn't solve the problem that way, but anyway, your expression can be written as $d=\|[\vec{w} - (\vec{w}\cdot\vec{u})u] - s[\vec{v} - (\vec{v}\cdot\vec{u})u]\|=\|\vec{p}+s\vec{q}\|$ (say). Now, suppose $\vec{q}=a\vec{p}+b\vec{r}$ for some numbers $a,b$ and some $\vec{r}\perp\vec{p}$. Then $d=\|(1+sa)\vec{p}+sb\vec{r}\|$. As $\vec{p}\perp\vec{r}$, we get $d^2=(1+sa)^2\|\vec{p}\|^2+s^2b^2\|\vec{r}\|^2$. Solving this quadratic equation, you get $s$. Now, to find $a,b$ and $\vec{r}$, you may use Gram-Schmidt orthogonalization. –  user1551 Nov 20 '12 at 5:32
How would you solve it then? I want to apply it to the following situation: point $A$ is a ball with radius $d$ travelling a distance $\vec{v}$. It may hit a wall $(B, \vec{u})$. I want to calculate whether and where in its trajectory it hits the wall as well as the point of collision on the wall. –  Jan Nov 20 '12 at 8:53

The problem can be solved in another way. Let $F$ be the foot of perpendicular drawn from $A$ to the line $BP$. Then $$\vec{AF} = \vec{w} - \frac{\vec{w}\cdot\vec{u}}{\|\vec{u}\|^2}\vec{u}.$$ Let $R=A+\lambda\vec{v}$ be the point where the line extending $QA$ meets the line extending $PB$. Then $\vec{AF} \perp \vec{RF} (=\vec{RA}+\vec{AF})$. Hence $$\vec{AF}\cdot(-\lambda\vec{v}+\vec{AF})=0.$$ Solve it to get $\lambda$. Then, by similarity of triangles, we have $$\frac{d}{\|\vec{AF}\|} = \frac{\|\vec{RQ}\|}{\|\vec{RA}\|} \equiv \frac{\lambda-s}{\lambda},\\$$ So you may solve for $s$. Finally, $t$ can be solved by observing that: $$t\vec{u} = \vec{BP} = \textrm{ projection of } \vec{BQ} \textrm{ along } \vec{u} =\left[(s\vec{v}-\vec{w})\cdot\frac{\vec{u}}{\|\vec{u}\|}\right]\frac{\vec{u}}{\|\vec{u}\|}.$$