8.4.1 Fitting two Parallel Lines

To fit two parallel lines, we must have two sets of points. We denote those two sets by $ \{P_i\}, i=1,\ldots,p$, and $ \{Q_j\},
j=1,\ldots,q$. Since the lines are parallel, their normal vector must be the same. Thus the equations for the lines are
$\displaystyle c_1 + n_1 x + n_2 y$ $\displaystyle =$ $\displaystyle 0,$  
$\displaystyle c_2 + n_1 x + n_2 y$ $\displaystyle =$ $\displaystyle 0,$  
$\displaystyle n_1^2 + n_2^2$ $\displaystyle =$ $\displaystyle 1.$  

If we insert the coordinates of the two sets of points into these equations we get the following constrained least squares problem:

$\displaystyle \vert\vert{ \bf r} \vert\vert = \sum_{i=1}^m r_i^2 = \min
$

subject to

$\displaystyle \left( \begin{array}{cccc} 1 & 0 & x_{P_1} & y_{P_1} \\ 1 & 0 & x...
...ght) = \left( \begin{array}{c} r_1\\ r_2\\ \vdots\\ r_{p+q} \end{array} \right)$   $\displaystyle \mbox{and $n_1^2 + n_2^2 = 1$.}$ (8.12)

Again, we can use our function clsq to solve this problem:

   % mainparallel.m
   Px = [1:10]'
   Py = [ 0.2 1.0 2.6 3.6 4.9 5.3 6.5 7.8 8.0 9.0]'
   Qx = [ 1.5 2.6 3.0 4.3 5.0 6.4 7.6 8.5 9.9 ]'
   Qy = [ 5.8 7.2 9.1 10.5 10.6 10.7 13.4 14.2 14.5]'
   A = [ones(size(Px))  zeros(size(Px)) Px Py
       zeros(size(Qx))  ones(size(Qx)) Qx Qy ]
   [c, n] = clsq(A,2)
   clf; hold on;
   axis([-1 11 -1 17])
   plotline(Px,Py,'o',c(1),n,'-')
   plotline(Qx,Qy,'+',c(2),n,'-')
   hold off;

The results obtained by the program mainparallel are the two lines

$\displaystyle 0.5091 -0.7146x + 0.6996y$ $\displaystyle =$ $\displaystyle 0,$  
$\displaystyle -3.5877 -0.7146x + 0.6996y$ $\displaystyle =$ $\displaystyle 0,$  

Peter Arbenz 2008-09-24