[Math] How to fit a set of 3D points to a helical curve

curvesleast squaresparametricregression

suppose I have a set of points in $\mathbb{R}^3$, and I want to find an arbitrary helix which best approximates these points.

An arbitrary helix in $\mathbb{R}^3$ can be parametrized as

$$\vec{r}(t) = t\hat{n} + R\cos(\omega t)\hat{u} + R\sin(\omega t)\hat{v} + \vec{r}_0 $$

where $\hat{n}$ is a unit vector that describes the direction of the helical axis, and $\hat{u}$ and $\hat{v}$ are orthogonal unit vectors such that

$$ \hat{n}\cdot\hat{u} = \hat{n}\cdot\hat{v} = \hat{u}\cdot\hat{v} = 0 $$

$\vec{r}_0$ is just a constant offset, $\omega$ determines the pitch of the helix, and $R$ determines the radius. The specific choice of $\hat{u}$ and $\hat{v}$ will determine the initial phase of the helix at $t=0$.

My question is, how do I use this to fit a helical curve to some discrete set of data points $\{x_i, y_i, z_i\}$?

First, I'm not totally sure the way I've parametrized the helix is the best way if I want to do some kind of least-squares fitting, but it's the only way I could think of.

Second, given this parametrization makes sense, how do I actually fit the data to this curve? I need to obtain the parameters $n_x, n_y, n_z, \omega, R$ and somehow determine the correct $\hat{u}$ such that helix phase is correct, in which case $\hat{v}$ would be given by $\hat{n} \times \hat{u}$ (or vice-versa).

The full set of equations look like

$$ x(t) = n_xt + R\cos(\omega t) u_x + R\sin(\omega t) v_x + x_0 $$
$$ y(t) = n_yt + R\cos(\omega t) u_y + R\sin(\omega t) v_y + y_0 $$
$$ z(t) = n_zt + R\cos(\omega t) u_z + R\sin(\omega t) v_z + z_0 $$
with the constraints
$$ n_x^2 + n_y^2 + n_z^2 = 1$$
$$ u_x^2 + u_y^2 + u_z^2 = 1$$
$$ v_x^2 + v_y^2 + v_z^2 = 1$$
and
$$n_xu_x + n_yu_y + n_zu_z = 0$$
$$n_xv_x + n_yv_y + n_zv_z = 0$$
$$u_xv_x + u_yv_y + u_zv_z = 0$$

for a total of 8 degrees of freedom (5 if I assume $\hat{r}_0$ = 0). I would very much appreciate any help people may have!

Best Answer

It turns out there is some literature available on this subject that I didn't see before. One trick is to first fit a cylinder to the data, then assume the helix lies on that cylinder. For all future helix-fitters out there, check out these links.

http://www.geometrictools.com/Documentation/HelixFitting.pdf

http://www.geometrictools.com/Documentation/CylinderFitting.pdf

I should add that the determination of the helix frequency and phase in the first link is difficult to implement... for an arbitrary set of points, there are infinitely many local minima in the optimization over $w$ and $\phi_0$, and many of them may be very near the global minima. This tends to produce helices with very high frequency, which makes sense because as the frequency gets small your helix begins to fill more and more of the cylinder it lies on....

A better way it to determine, in some way, the phase of each point and then do simple linear regression such that you fit the best line to $\phi_i = \omega z_i + \phi_0$ with the helix axis in the z-direction.

Related Question