Say I have an infinite cylinder that can be defined by its axis $\pmb v$, radius $r$ and a center point $\pmb c$ indicating its position.
Now, say I have many points in 3D and I want to find the model $(\pmb v, \pmb c, r)$ that best fits these points. Does anyone have a simple explanation or straight up implementation of such a method? Also, what is the best method to do this if my points are noisy?
The distance between a point $\mathbf{x}$ and the cylinder is (assuming $\lvert\mathbf{v}\rvert=1$): $$ \left\lvert\sqrt{[\mathbf{x}-\mathbf{c}-(\mathbf{x}- \mathbf{c})\times \mathbf{v}]^2}-r\right\rvert. $$ So we get the naive least square: $$ L(\mathbf{v},\mathbf{c},r;\lambda)=\sum_i (\sqrt{[\mathbf{x}_i-\mathbf{c}-(\mathbf{x}_i-\mathbf{c})\times \mathbf{v}]^2}-r)^2-\lambda_1(\mathbf{v}^2-1)-\lambda_2\mathbf{c}\cdot\mathbf{v} $$ But you need to square root etc. We could try instead $$ L(\mathbf{v},\mathbf{c},r;\lambda)=\sum_i ([\mathbf{x}_i-\mathbf{c}-(\mathbf{x}_i-\mathbf{c})\times \mathbf{v}]^2-r^2)^2-\lambda_1(\mathbf{v}^2-1)-\lambda_2\mathbf{c}\cdot\mathbf{v} $$ at the expense of making it quartic in $\mathbf{x},\mathbf{c},\mathbf{v}$. Neither versions have analytic solution so you need some numerical methods.
Anyway, symmetry suggests we should expect the best-fit axis to pass through $\bar{\mathbf{x}}$. Diagonalise the second central moment tensor (with equal weights $\frac1n$ on the points) $$ \frac1n\sum_i (\mathbf{x}_i-\bar{\mathbf{x}})\otimes(\mathbf{x}_i-\bar{\mathbf{x}})=P\begin{pmatrix}\sigma_1\\&\sigma_2\\&&\sigma_3\end{pmatrix}P^{-1} $$ If we have sampled enough points uniformly on a long cylinder (length $L\gg r$), then $\mathbf{v}$ should correspond to the eigendirection of largest eigenvalue (say $\sigma_1$) and the other two eigenvalues $\sigma_2,\sigma_3$ should be approximately equal (you expect the eigenvalues to be around $\frac1{12}L^2,\frac12r^2,\frac12r^2$). Hence we get $r^2$ as, e.g., $\sigma_2+\sigma_3$ or $2\sqrt{\sigma_2\sigma_3}$. You could use this as the starting point for numerical methods.