Least-squares equation for line in polar coordinates

least squarespolar coordinates

I'm trying to find (or derive) a formula for the least-squares fitted line in polar coordinates. I've worked out a least-squares formula for a line that passes through the origin, but I'm trying to find the more general solution for a line that doesn't necessarily pass through the origin. In other words, given a set of polar coordinates, I want to find a line expressed by $r(\theta)=p\sec(\theta-\phi)$, where parameters $p$ and $\phi$ are determined by least squares, and represent the point $(p,\phi)$ on the resulting line closest to the origin.

Best Answer

The line equation with homogeneous coordinates $(a,b,c)$ is $$a x + b y + c = 0$$

In polar form with $(x= r \cos \theta, \, y = r \sin \theta)$ the above is

$$ r = \frac{- c}{a \cos \theta + b \sin \theta} $$

This means that $r = p \sec ( \theta - \phi)$ is actually

$$ r = \frac{p}{\cos \phi \cos \theta + \sin \phi \sin \theta} $$

so the homogeneous coordinates of the line is $(a = \cos \phi, b = \sin \phi, c = -p)$

$$ (\cos \phi)\, x + (\sin \phi)\, y = p$$

So do the least squares using $(a) x + (b) y + (c) =0$ and then convert to polar using the polar form from above.


Do the least squares on the canonical form of a line $(a^\star)\, x + (b^\star)\, y = 1$ using a Vandermode matrix.

$$ A = \left| \begin{array}{ccc} x_1 & y_1 \\ x_2 & y_2 \\ \vdots & \vdots \\ x_n & y_n \\ \end{array} \right| $$

$$ b = \left| \begin{array}{c} 1 \\ 1 \\ \vdots \\ 1 \end{array} \right| $$

$$ \pmatrix{a^\star \\ b^\star} = \left( A^\intercal A \right)^{-1} A^\intercal b $$

so $(a=a^\star, b = b^\star, c = -1)$ or in polar form $$(a^\star= \cos \phi, b^\star = \sin \phi, p= \frac{1}{\sqrt{(a^\star)^2 + (b^\star)^2}})$$


In fact, doing the least squares solution directly to the polar equation is equivalent to the above.

This is because the polar form of the i-th point $(r_i, \theta_i)$ can be written as $$ \tfrac{1}{p} \left(r_i \cos \phi \cos \theta_i + r_i \sin \phi \sin \theta_i \right) = 1$$

This produces the following Vandermode matrix (which as you can see contains the cartesian coordinates of each point).

$$ A = \tfrac{1}{p} \left| \begin{array}{ccc} r_i \cos \theta_1 & r_i \sin \theta_1 \\ r_i \cos \theta_2 & r_i \sin \theta_2 \\ \vdots & \vdots \\ r_i \cos \theta_n & r_i \sin \theta_n \\ \end{array} \right| $$

$$ b = \left| \begin{array}{c} 1 \\ 1 \\ \vdots \\ 1 \end{array} \right| $$

with solution

$$ \pmatrix{a^\star \\ b^\star} = \pmatrix{p \cos \phi \\ p \sin \phi} = \left( A^\intercal A \right)^{-1} A^\intercal b $$

Related Question