**GIVEN**: that there is a line L that is defined by two points, **P**_{1} and **P**_{2}, and a point **Q** not on L.

**FIND**:

- the point
**Q**_{0} that is the closest point to **Q** on the line L.
- the parametric equation of the second line L
_{2} that contains points **Q** and **Q**_{0}.
- the distance between the point
**Q** and the line L.

**SOLUTION**:

The parametric equation of L is:

**P** = **P**_{1} + k * (**P**_{2} - **P**_{1})

where k is a scalar parameter that is equal to 0 when **P** = **P**_{1} and 1 when b>P = **P**_{2}. The parameter value k can have positive or negative values.

The parametric equation of the second line L_{2} is:

**R** = **Q** + k_{2} * (**Q**_{0} - **Q**)

where k_{2} is the scalar parameter of L_{2} that is equal to 0 when **R** = **Q** and 1 when **R** = **Q**_{0}. The parameter value k_{2} can also have positive and negative values.

Now you are ready to solve equations. The first equation is driven by the condition of normalcy. Since L_{2} ⊥ L, then

(**Q**_{0} - **Q**) • (**P**_{2} - **P**_{1}) = 0

where • is the dot product. The second condition is that **Q**_{0} is a point on L:

(**Q**_{0} = **P**_{1} + k * (**P**_{2} - **P**_{1})

Solving for k:

k_{*} = ((**Q** - **P**_{1}) * (**P**_{2} - **P**_{1}))/ |**P**_{2} - **P**_{1}|^{2} ...or...

k_{*} = ((Q_{x}-P_{1x})(P_{2x}-P_{1x})+(Q_{y}-P_{1y})(P_{2y}-P_{1y})) / ((P_{2x}-P_{1x})^{2} +(P_{2y}-P_{1y})^{2})

Now k_{*} is that value of the line parameter k on line L which yields the coordinates of the point of intersection **Q**_{0}, the point that lies on both lines L and L_{2}. So we have our answer:

**SOLUTION**:

The point of intersection (which is also the point on the line L closest to point **Q**) is given by:

k_{*} = ((**Q** - **P**_{1}) * (**P**_{2} - **P**_{1}))/ |**P**_{2} - **P**_{1}| ...or...

k_{*} = ((Q_{x}-P_{1x})(P_{2x}-P_{1x})+(Q_{y}-P_{1y})(P_{2y}-P_{1y})) / ((P_{2x}-P_{1x})^{2} +(P_{2y}-P_{1y})^{2})

and therefore the point of intersection is

**Q** = **P**_{1} + k_{*} * (**P**_{2} - **P**_{1})

The parametric equation of the normal line L_{2} is:

**R** = **Q** + k_{2} * (**Q**_{0} - **Q**)

Finally, the distance between the point and the line is equal to

|**Q**_{0} - **Q**|

= SQRT((Q_{0x}-Q_{x})^{2} +(Q_{0y}-Q_{y})^{2})