Loading web-font TeX/Math/BoldItalic

Euler Spiral Animation [gnuplot]

Friday, June 12, 2020

Curve gnuplot Mathematics YouTube

t f B! P L

YouTube

 

Formulation

Parametric equations [1] [2]

\begin{align*} x(t) &= \int_0^t \cos\theta^2\,\diff\theta\\ y(t) &= \int_0^t \sin\theta^2\,\diff\theta \end{align*}
The limits of x(t), y(t) as t\rightarrow\pm\infty are known: \begin{align*} \lim_{t\rightarrow\pm\infty}x(t) &= \int_0^{\pm\infty} \cos\theta^2\,\diff\theta = \pm\frac{1}{2}\sqrt{\frac{\pi}{2}}\\ \lim_{t\rightarrow\pm\infty}y(t) &= \int_0^{\pm\infty} \sin\theta^2\,\diff\theta = \pm\frac{1}{2}\sqrt{\frac{\pi}{2}} \end{align*}

Curvature and osculating circle

Let \begin{align*} \bm{r} = \left[x(t), y(t)\right]^T \end{align*}
Then \begin{align*} \frac{\diff\bm{r}}{\diff t} &= \left[\cos t^2, \sin t^2\right]^T \\ \frac{\diff s}{\diff t} &= \left|\frac{\diff\bm{r}}{\diff t}\right| = 1\ \ (s:\text{Arc length paramenter}) \end{align*}

Unit tangential vector \bm{t}

\begin{align*} \bm{t} = \frac{\diff \bm{r}}{\diff s}=\frac{\diff\bm{r}}{\diff t}\frac{\diff t}{\diff s}=\left[\cos t^2, \sin t^2\right]^T \end{align*}

Curvature \kappa

\begin{align*} \frac{\diff\bm{t}}{\diff s} &= \frac{\diff\bm{t}}{\diff t}\frac{\diff t}{\diff s} = \left[-2t\sin t^2, 2t\cos t^2\right]^T\\ \kappa &= \left|\frac{\diff\bm{t}}{\diff s}\right| = \sqrt{(-2t\sin t^2)^2+(2t\cos t^2)^2} = \sqrt{(2t)^2}=2|t| \end{align*}

Unit principal normal vector \bm{n}

\begin{align*} \bm{n} = \frac{1}{\kappa}\frac{\diff\bm{t}}{\diff s} =\frac{1}{2|t|}\left[-2t\sin t^2, 2t\cos t^2\right]^T =\left[-\frac{t}{|t|}\sin t^2, \frac{t}{|t|}\cos t ^2\right]^T \end{align*}

Radius of curvature \rho

\begin{align*} \rho = \frac{1}{\kappa} = \frac{1}{2|t|} \end{align*}

Center of curvature \bm{c}

\begin{align*} \bm{c} &= \bm{r}+\rho\bm{n}\\ &= \left[x(t), y(t)\right]^T+\frac{1}{2|t|}\left[-\frac{t}{|t|}\sin t^2, \frac{t}{|t|}\cos t^2\right]^T\\ &= \left[x(t)-\frac{1}{2t}\sin t^2, y(t)+\frac{1}{2t}\cos t^2\right]^T\ \ (\because |t|^2=t^2) \end{align*}

Simulation [gnuplot]

Source code (PLT file)

reset
set angle rad
#=================== Parameters ====================
N = int(5e3) # If you integrate using Simpson's rule, N is even.
num = 360 # Output (num+1) images
numPNG = 0
lineWidth = 2.
pointSize = 1.5e-2
trange = 15. #[-trange:trange]
limitCenterX = sqrt(pi/2)/2
limitCenterY = sqrt(pi/2)/2
#=================== Functions ====================
# Integrands of Fresnel integrals
c(t) = cos(t**2)
s(t) = sin(t**2)
# Fresnel integral using composite trapezoidal rule
# fresnelC(t) = (h = t/N, h/2*(c(0)+2*(sum[i=1:N-1]c(h*i))+c(t)))
# fresnelS(t) = (h = t/N, h/2*(s(0)+2*(sum[i=1:N-1]s(h*i))+s(t)))
# Fresnel integral using composite Simpson's rule
fresnelC(t) = (h = t/N, h/3*(sum[i=1:N/2]c((2*i-2)*h)+4*c((2*i-1)*h)+c(2*i*h)))
fresnelS(t) = (h = t/N, h/3*(sum[i=1:N/2]s((2*i-2)*h)+4*s((2*i-1)*h)+s(2*i*h)))
# The osculating circle
centerX(t) = fresnelC(t) - sin(t**2)/(2*t)
centerY(t) = fresnelS(t) + cos(t**2)/(2*t)
radius(t) = 1./(2*abs(t))
# Distance between (x1,y1), (x2,y2)
dist(x1, y1, x2, y2) = sqrt((x2-x1)**2 + (y2-y1)**2)
#=================== Setting ====================
set term pngcairo truecolor enhanced dashed size 720, 720 font 'Times, 18'
folderName = 'png'
system sprintf('mkdir %s', folderName)
set size ratio -1
set nokey
set grid
set samples 5e3
range = 1.0
set xr[-range:range]
set yr[-range:range]
set xl '{/:Italic x}'
set yl '{/:Italic y}'
set parametric
#=================== Plot and Output ====================
do for [i=0:num:1]{
set output sprintf("%s/img_%04d.png", folderName, numPNG)
numPNG = numPNG + 1
ti = trange/num * i
ti_next = trange/num * (i+1)
set trange [-ti:ti]
set title sprintf("%.2f ≦ {/:Italic t} ≦ %.2f", -ti, ti)
# Since you calculate Fresnel integrals using Numerical integral,
# the following codes exmaine calculation accuracy.
if(i > 0){
nowDistance = dist(fresnelC(ti), fresnelS(ti), limitCenterX, limitCenterY)
nextDistance = dist(fresnelC(ti_next), fresnelS(ti_next), limitCenterX, limitCenterY)
if(nowDistance < nextDistance){
print 'Error! Poor accuracy!' ; exit # Recommend you to reset N
}
}
# Draw two osculating circles
if(i != 0){
# Shorten lines to draw within graph area.
if(centerY(ti) > range){
tan2 = atan2(fresnelS(ti)-centerY(ti), fresnelC(ti)-centerX(ti)) # Angle of line
cutY = centerY(ti) - range
cutX = cutY/tan(tan2)
} else {
cutY = 0
cutX = 0
}
# Radius of curvature
set arrow 1 nohead from centerX(ti)+cutX, centerY(ti)-cutY to fresnelC(ti), fresnelS(ti) lw lineWidth lc rgb 'red' # x>0, y>0
set arrow 2 nohead from centerX(-ti)-cutX, centerY(-ti)+cutY to fresnelC(-ti), fresnelS(-ti) lw lineWidth lc rgb 'red' # x<0, y<0
# Osculating circle
set object 1 circle at centerX(ti), centerY(ti) size radius(ti) fc rgb 'red' fill transparent solid 0.2 noborder
set object 2 circle at centerX(-ti), centerY(-ti) size radius(-ti) fc rgb 'red' fill transparent solid 0.2 noborder
# Center of curvature
set object 3 circle at centerX(ti), centerY(ti) size pointSize fc rgb 'red' fill solid
set object 4 circle at centerX(-ti), centerY(-ti) size pointSize fc rgb 'red' fill solid
# Point of tangency
set object 5 circle at fresnelC(ti), fresnelS(ti) size pointSize fc rgb 'royalblue' fill solid front
set object 6 circle at fresnelC(-ti), fresnelS(-ti) size pointSize fc rgb 'royalblue' fill solid front
}
# Draw two limit points
set object 7 circle at limitCenterX, limitCenterY size pointSize fc rgb 'black' fill solid front
set object 8 circle at -limitCenterX, -limitCenterY size pointSize fc rgb 'black' fill solid front
# Draw the curve
plot fresnelC(t), fresnelS(t) w l lc rgb 'royalblue' lw lineWidth
set out
}

Output (PNG file → GIF file)

Only curve Curve with limit points
Curve with osculating circles Curve with the points and the circles

Graph of Fresnel integrals C(t) and S(t)

Source code (PLT file)

reset
set angle rad
#=================== Parameters ====================
N = int(5e3) # If you integrate using Simpson's rule, N is even.
lineWidth = 1.5
trange = 15. #[-trange:trange]
limitCenterX = sqrt(pi)/2
limitCenterY = sqrt(pi)/2
#=================== Functions ====================
# Integrands of Fresnel integrals
c(t) = cos(t**2)
s(t) = sin(t**2)
# Fresnel integral using composite Simpson's rule
fresnelC(t) = (h = t/N, h/3*(sum[i=1:N/2]c((2*i-2)*h)+4*c((2*i-1)*h)+c(2*i*h)))
fresnelS(t) = (h = t/N, h/3*(sum[i=1:N/2]s((2*i-2)*h)+4*s((2*i-1)*h)+s(2*i*h)))
#=================== Setting ====================
# set term pngcairo transparent truecolor enhanced dashed size 300, 225 font 'Times, 12' # for YouTube
set term pngcairo truecolor enhanced dashed size 600, 450 font 'Times, 12'
set key font ', 14' right bottom spacing 1.3 # default=1
set grid
set samples 5e3
set xr[-5:5]
set yr[-1:1]
# set xl '{/:Italic t}' offset screen 0, 0.03 font ', 14'
set xl '{/:Italic t}' font ', 14'
unset yl
#=================== Plot ====================
set output "fresnelCS.png"
plot fresnelC(x) w l lc rgb '0x0086C8' lw lineWidth t '{/:Italic C}({/:Italic t})', \
fresnelS(x) w l lc rgb '0xFF5050' lw lineWidth t '{/:Italic S}({/:Italic t})'
set out

Output (PNG file)

Note : Numerical Integration

Composite trapezoidal rule [3]

\begin{align*} \int_a^b f(x)\,\diff x \approx \frac{h}{2}\left(f(x_0)+2\sum_{i=1}^{N-1}f(x_i)+f(x_N)\right) \end{align*}
where \begin{align*} x_i &= a+ih\ (i=0, 1, \cdots,\ N-1, N)\\ h &= \frac{b-a}{N} \end{align*}
This time, \begin{equation*} a=0, b=t\ \rightarrow\ h=\frac{t}{N}, x_i=ih \end{equation*}

Composite Simpson's rule [4]

\begin{align*} \int_a^b f(x)\,\diff x \approx \frac{h}{3}\sum_{i=1}^{N/2}\left[f(x_{2i-2})+4f(x_{2i-1})+f(x_{2i})\right] \end{align*}
where \begin{align*} x_i &= a+ih\ (i=0,\ 1,\ \cdots,\ N-1,\ N)\\ h &= \frac{b-a}{N} \end{align*}
This time, \begin{equation*} a=0, b=t\ \rightarrow\ h=\frac{t}{N}, x_i=ih \end{equation*}

More details

GitHub Repository

https://github.com/hiroloquy/euler-spiral.git

References

  1. ^ Euler spiral - Wikipedia
  2. ^ Fresnel integral - Wikipedia
  3. ^ Trapezoidal rule - Wikipedia
  4. ^ Simpson's rule - Wikipedia

Search This Blog

Translate

QooQ