Question
My goal is to robustly estimate a general 2D line from $n$ data points, where the line is parameterized by $\rho > 0$, the distance from the origin to the line and $\varphi$, the angle between the $x$-axis and the perpendicular line (that goes through the origin). This parametrization has been chosen as it requires two parameters only and can also represent vertical lines.
To robustly estimate the two parameters $\rho > 0$ and $\varphi$, I can make use of a general robust linear least-squares solver (RLLS), which solves $\min_\mathbf{c} \vert\vert \mathbf{X}\,\mathbf{c}-\mathbf{y}\vert\vert_2$, where $\mathbf{X}$ is the $n\times p$ regressor matrix and $\mathbf{c}$ is the $p$-dimensional parameter vector.
Is there an elegant way (a special transformation that allows to express the estimation of $\varphi$ and $\rho$ in terms of a linear regression setting) to make use of the RLLS that can handle arbitrary (also vertical) lines?
Attempt
I figured out, that the distance between an arbitrary data point $\left(x_i, y_i\right)$ from a line with $\rho$ and $\varphi$ is given as
$$ x_i\,\cos\left(\varphi\right) + y_i\,\sin\left(\varphi\right) - \rho $$
To get this into the format the RLS solver takes as input, I rearranged the equation to
$$ \begin{bmatrix}\dots&\dots\\x_i&1\\\dots&\dots\end{bmatrix}\begin{bmatrix}-\frac{\cos\left(\varphi\right)}{\sin\left(\varphi\right)}\\\frac{\rho}{\sin\left(\varphi\right)}\end{bmatrix} = \begin{bmatrix}\dots\\y_i\\\dots\end{bmatrix}, $$ The parameters $\mathbf{c} = \left[c_1, c_2\right]^\top$, were then used to compute $\varphi = \mathrm{atan}\left(-\frac{1}{c_1}\right) $ and $\rho = c_2\,\sin\left(\varphi\right)$.
This works but requires some hacks: The solver may return values of $\rho < 0$, which can be handled by taking its negative and shifting $\varphi$ by $\pi$.
However, the greatest issue are straight lines, where $\varphi \approx 0$. To handle horizontal lines I do the following: I solve the problem twice, normally and with swapped $x$ and $y$ axis. The solution with smaller residual means squared error is accepted. This is not elegant and requires solving the least squares problem twice.