# Conical Spirals - Arc Length

In the previous notebook,<a href="./0 - conical spirals.ipynb">`0 - conical spirals.ipynb`</a>, we developed the model to trace the Archimedean spiral around the cone. In this notebook, we explore the derivation of the equations to calculate the arc length of the spiral (Archimedean spiral). In practical terms, if we use LED strips to create a sprial around the cone, we can determine the required LED strip length to get the job done.

# Notebook Preamble


```javascript
%%javascript
//Disable autoscroll in the output cells - needs to be in a separate cell with nothing else
IPython.OutputArea.prototype._should_scroll = function(lines) {
    return false;
}
```


    <IPython.core.display.Javascript object>



```python
# decide whether charts will be displayed interactively or in a format that exports to pdf

# Interactive -----------------
# For interactive notebook uncomment:
%matplotlib notebook

# PDF -----------------
# For pdf plotting uncomment:
# %matplotlib inline
# import warnings
# warnings.filterwarnings('ignore')

%config InlineBackend.figure_formats = ['png', 'pdf'] #['svg']

#------------
# Setup matplotlib
import matplotlib.pyplot as plt 
from mpl_toolkits.mplot3d import Axes3D # handle 3D plots
import matplotlib as mpl

mpl.rc('font',family='monospace') # all font on the plot will be monospace
```


```python
import numpy as np

from plots import (
    create_standard_figure, 
    axis_legend_remove_duplicates,
)

from common import (
    plot_cone, 
    plot_spiral,
    plot_center_pole, 
    spiral_arc_length_range,
    plot_cone_and_sprial,
)
```

## Arc Length of a Curve in Polar Coordinates

Now that we can plot the spiral, how long is it? Essentially, we want to determine the length of the vector function:

$$ 
\begin{equation} \tag{1}
\large \vec r \left(t \right) = \left \langle f(t), g(t), h(t) \right \rangle 
\end{equation}
$$

Writing the vector function in parametric form:

$$
\begin{matrix}
\large x = f(t) \\
\large y = g(t) \\
\large z = h(t)
\end{matrix}
$$

In 3 Dimensions, the length of the curve, $ \vec r \left(t \right)$ on the interval $m_1 \le t \le m_2$ is:

$$ 
\large
\begin{equation} \tag{2}
L = \int_{m_1}^{m_1} \sqrt{\left[f'(t)\right]^2 + \left[h'(t)\right]^2 + \left[g'(t) \right]^2} \; \frac{\mathrm{d} }{\mathrm{d} t}
\end{equation}
$$

<div class="alert alert-block alert-info"> <b>NOTE:</b> In the notebook,  <a href="./0 - conical spirals.ipynb">`0 - conical spirals.ipynb`</a>, we represented the angle as $\theta$. For this derivation, consider $t = \theta$. We will continue to use $t$ to represent the polar angle. </div>

The parametric equations for the spiral are:

$$
\large 
\begin{equation} \tag{3}
\begin{matrix}
x(t) = bt \cos t \\ 
y(t) = bt \sin t \\ 
z(t) = kt + z_0
\end{matrix}
\end{equation}
$$

Where $b$ and $k$ are constants that control the shape and height of the spiral and $t$ is the angle in radians controlling the number of `loops`.

<div class="alert alert-block alert-info"> <b>NOTE:</b> In the notebook, <a href="./0 - conical spirals.ipynb">`0 - conical spirals.ipynb`</a>, we represented the shape of the cone with $m$. For this document, consider $k = m$, from this point forward.  </div>

Take the derivative of each equation:

$$
\large
\begin{equation} \tag{4}
\begin{matrix}
x'(t) =  b \left( \cos(t) - t \sin(t) \right) \\ 
y'(t) = b \left(\sin(t) + t \cos(t) \right) \\ 
z'(t) = k
\end{matrix}
\end{equation}
$$

Let's rearrange things to make dealing with the polynomial and the radical easier:

$$ \left[ f'(x) \right]^2 = \left[ b \cdot \left(\cos(t) - t \sin(t) \right) \right]^2$$

$$\left[ f'(x) \right]^2 = b^2 \cos^2 t - b^2 t \sin(2 t) + b^2 t^2 \sin^2 t$$

Where:

$$\sin(2 t) = 2 \sin(t) \cos(t)$$

$$\sin(t) \cos(t) = \frac{1}{2} \cdot \sin(2 t)$$

$$\sin^2 t + \cos^2 t = 1$$

$$ [h'(t)]^2 = \left( b \cdot \left(\sin(t) + t \cdot \cos(t) \right) \right)^2$$

$$ [h'(t)]^2 = b^2 \sin^2 t + b^2 t \sin (2 t) + b^2 t^2 \cos^2 t$$

$$ [g'(t)]^2 = k^2$$

$$ [f'(t)]^2 + h'(t)^2 + g'(t)^2 = b^2 + b^2 t^2 + k^2$$

$$ 
\large 
\begin{equation} \tag{5}
L = \int_{m_1}^{m_1} \sqrt{\left[f'(t)\right]^2 + \left[h'(t)\right]^2 + \left[g'(t) \right]^2} \; \frac{\mathrm{d} }{\mathrm{d} t}
\end{equation}
$$

<div class="alert alert-block alert-info"> <b>NOTE:</b> Solving the integral we made use of :http://www.integral-calculator.com/ </div>

Solve the integral. Substitute:

$$t=\frac{\sqrt{k^2+b^2}\tan\left(u\right)}{b} \rightarrow u=\arctan\left(\frac{bt}{\sqrt{k^2+b^2}}\right)$$

$$ \frac{\mathrm{d}t}{\mathrm{d}u}=\frac{\sqrt{k^2+b^2}\sec^2\left(u\right)}{b}  $$

$$ ={\int}\frac{\sqrt{k^2+b^2}\sec^2\left(u\right)\sqrt{\left(k^2+b^2\right)\tan^2\left(u\right)+k^2+b^2}}{b}\,\mathrm{d}u$$

Simplify using:

$$\left(k^2+b^2\right)\tan^2\left(u\right)+k^2+b^2=\left(k^2+b^2\right)\sec^2\left(u\right)$$

Becomes:

$$=\class{steps-node}{\cssId{steps-node-1}{\frac{k^2+b^2}{b}}}{\int}\sec^3\left(u\right)\,\mathrm{d}u$$

Now Solving:

$${\int}\sec^3\left(u\right)\,\mathrm{d}u$$

Apply reduction formula with $n=3$:

$$\small{{\int}\sec^{\mathtt{n}}\left(u\right)\,\mathrm{d}u=\class{steps-node}{\cssId{steps-node-2}{\frac{\mathtt{n}-2}{\mathtt{n}-1}}}{\int}\sec^{\mathtt{n}-2}\left(u\right)\,\mathrm{d}u+\frac{\sec^{\mathtt{n}-2}\left(u\right)\tan\left(u\right)}{\mathtt{n}-1}}$$

$$=\class{steps-node}{\cssId{steps-node-3}{\frac{1}{2}}}{\int}\sec\left(u\right)\,\mathrm{d}u+\frac{\sec\left(u\right)\tan\left(u\right)}{2}$$

Now Solving:

$${\int}\sec\left(u\right)\,\mathrm{d}u =\ln\left(\tan\left(u\right)+\sec\left(u\right)\right)$$

The solution is a standard integral...

Plugin solved integrals:

$$\class{steps-node}{\cssId{steps-node-4}{\frac{1}{2}}}{\int}\sec\left(u\right)\,\mathrm{d}u+\frac{\sec\left(u\right)\tan\left(u\right)}{2} =\frac{\ln\left(\tan\left(u\right)+\sec\left(u\right)\right)}{2}+\frac{\sec\left(u\right)\tan\left(u\right)}{2}$$

$$\class{steps-node}{\cssId{steps-node-5}{\frac{k^2+b^2}{b}}}{\int}\sec^3\left(u\right)\,\mathrm{d}u =\frac{\left(k^2+b^2\right)\ln\left(\tan\left(u\right)+\sec\left(u\right)\right)}{2b}+\frac{\left(k^2+b^2\right)\sec\left(u\right)\tan\left(u\right)}{2b}$$

Undo substitution:

$$u=\arctan\left(\frac{bt}{\sqrt{k^2+b^2}}\right)$$

Use:

$$\tan\left(\class{steps-node}{\cssId{steps-node-6}{\arctan\left(\frac{bt}{\sqrt{k^2+b^2}}\right)}}\right)=\frac{bt}{\sqrt{k^2+b^2}}$$

$$\sec\left(\class{steps-node}{\cssId{steps-node-7}{\arctan\left(\frac{bt}{\sqrt{k^2+b^2}}\right)}}\right)=\sqrt{\frac{b^2t^2}{k^2+b^2}+1}$$

$$=\frac{\left(k^2+b^2\right)\ln\left(\sqrt{\frac{b^2t^2}{k^2+b^2}+1}+\frac{bt}{\sqrt{k^2+b^2}}\right)}{2b}+\frac{\sqrt{k^2+b^2}t\sqrt{\frac{b^2t^2}{k^2+b^2}+1}}{2}$$

Solution:

$$
\large
\begin{equation} \tag{6}
\begin{split}
\int \sqrt{b^2t^2+k^2+b^2}\,\mathrm{d}t & =  \\
& = \frac{\left(k^2+b^2\right)\ln\left(\left|\sqrt{\frac{b^2t^2}{k^2+b^2}+1}+\frac{bt}{\sqrt{k^2+b^2}}\right|\right)}{2b}+\frac{\sqrt{k^2+b^2}t\sqrt{\frac{b^2t^2}{k^2+b^2}+1}}{2}+C &  \\
& =\frac{\left(k^2+b^2\right)\ln\left(\left|\sqrt{b^2\left(t^2+1\right)+k^2}+bt\right|\right)+bt\sqrt{b^2\left(t^2+1\right)+k^2}}{2b}+C
\end{split}
\end{equation}
$$

<div class="alert alert-block alert-info"> <b>NOTE:</b> Applying the limits will eliminate the constant...</div>


```python
# Cone
r = 0.5 # m
h = 2.5 # m
d = 0.25 # spacing between loops

al = spiral_arc_length_range(r, h, d)

print('Sprial Length = {:.3f}'.format(al))
```

    Sprial Length = 4.236



```python
fig, ax = create_standard_figure(
    'Archimedean Spiral',
    'x',
    'y',
    'z',
    projection='3d',
    figsize=(8, 8),                                                  
    axes_rect=(0.1, 0.1, 0.85, 0.85), # rect [left, bottom, width, height]
) 

# NOTE: Units are in what every system you want as long as all length units are the same (ft, m, inches, mm)

# Cone
r = 2 # m
h = 5 # m
d = 0.25 # spacing between loops

plot_cone_and_sprial(ax, r, h, d)

fig.show()
```


    <IPython.core.display.Javascript object>






    Cone Radius (r) = 2.0000
    Cone Height (h) = 5.0000
    Sprial Distance (d) = 0.2500



```python

```

0fe5525d5890a473e7e632e8cf130600a3e9d223
ipynb
Jupyter Notebook
notebooks/1 - spiral arc length.ipynb
TroyWilliams3687/led_strips
acd95bbc420fd10f6568afd342bb78c986516a05
MIT
notebooks/1 - spiral arc length.ipynb
TroyWilliams3687/led_strips
acd95bbc420fd10f6568afd342bb78c986516a05
MIT
notebooks/1 - spiral arc length.ipynb
TroyWilliams3687/led_strips
acd95bbc420fd10f6568afd342bb78c986516a05
MIT
Qwen/Qwen-72B
1. YES
2. YES