How to calculate the spiral around a curve? I have a curve given by a set of points and want to build a spiral around it (like this).



I tried it by

STEP 1:
calculated the vector of each step by

$$v_n = \left&lt;x_n,y_n,z_n\right&gt; - \left&lt;x_{n-1},y_{n-1},z_{n-1}\right&gt;$$

STEP 2:
I assumed a vector/plane of the rotating trajectory as
$$ w_n = \left&lt;\cos(i),1,\sin(i)\right&gt;$$

where $i$ represents the intervals and increases by the point number.

And calculated the perpendicular vector to find the spiral points by

$$X = v_y \cdot w_z - v_z \cdot w_y $$
$$Y = v_z \cdot w_x - v_x \cdot w_z $$
$$Z = v_x \cdot w_y - v_y \cdot w_x $$

And, of course, I normalized the scale.

The spiral is formed, but I have discontinuity or deformation at sharp angles (probably because the vector direction is changed). It is not a matter of smoothness, as the spiral changes its direction to rotate in the opposite direction.

Where did I do wrong?
spiral will evolve according to helical angle $$\phi_n=\phi_{n-1}+2 \pi \frac{|\vec{x}_n-\vec{x}_{n-1}|}{\lambda}$$ where $\lambda$ is the pitch of the helix and is measured relative to an "up" orientation normal vector $\vec{u}$ which is the component of the acceleration vector $\vec{a}_n$ perpendicular to the velocity vector $\vec{v}_n$ $$\vec{u}_n=\hat{a}_n-(\hat{a}_n \cdot \hat{v}_n ) \hat{v}_n$$ where $$ \vec{v}_n=\vec{x}_n-\vec{x}_{n-1}$$ and $$\vec{a}_n=\vec{v}_n-\vec{v}_{n-1}$$ the location of the helix is then given by $$\vec{h}_n=\vec{x}_n+\hat{u}_nR\cos \phi_n+(\hat{u}_n\times\hat{v}_n)R\sin \phi_n$$ where $R$ is the radius of the helix
Probably your steps are too large.  You are rotating a full radian between steps.  If you use finer steps in both directions you will improve things.  If you just divide $i$ by $10$ in the $w$ equation the pitch will increase by a factor $10$.  Maybe you should interpolate $10$ steps between your $v$ points, then divide $i$ by $10$ in $w$.  The most challenging points are those where the axis of the helix bends most.  You need the steps in your helix rather small by comparison with that scale.