8.4.2 Fitting Orthogonal Lines

To fit two orthogonal lines we can proceed very similar as in the the case of the parallel lines. If $ (n_1 , n_2 )$ is the normal vector of the first line, then the second line must have the normal vector $ (-n_2, n_1)$ in order to be orthogonal. Therefore again we will have four unknowns: $ c_1$, $ c_2$, $ n_1$ and $ n_2$. If the $ P_i$'s are the points associated with the first line and the $ Q_j$'s are the points associated with the second line, we obtain 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.13)

We only have to change the definition of the matrix $ A$ in mainparallel in order to compute the equations of the two orthogonal lines. To obtain a nicer plot we also chose different values for the second set of points.

  % mainorthogonal.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 = [ 0 1 3 5 6 7]'
   Qy = [12 8 6 3 3 0]'
   A = [ones(size(Px))   zeros(size(Px)) Px  Py
        zeros(size(Qx))  ones(size(Qx))  Qy -Qx  ]
   [c, n] = clsq(A,2)
   clf; hold on;
   axis([-1 11 -1 13])
   axis('equal')
   plotline(Px,Py,'o',c(1),n,'-')
   n2(1) =-n(2); n2(2) = n(1)
   plotline(Qx,Qy,'+',c(2),n2,'-')

The Program mainorthogonal computes the two orthogonal lines

$\displaystyle -0.2527 -0.6384x + 0.7697y$ $\displaystyle =$ $\displaystyle 0,$  
$\displaystyle 6.2271 - 0.7697x -0.6384y$ $\displaystyle =$ $\displaystyle 0.$  

Peter Arbenz 2008-09-24