MathB.in
New
Demo
Tutorial
About
We approximate the interval $[0,\pi /2]$ with a cubic Bézier curve. We need four control points, $P_0$, $P_1$, $P_2$ and $P_3$. As we're approximating the interval $[0,\pi /2]$ and want the boundary points to be accurate, we know $P_0$ and $P_3$: \begin{align*} P_0 &= \begin{pmatrix} 0 \\sin(0)\end{pmatrix} = \begin{pmatrix} 0 \\0\end{pmatrix}\\ P_3 &= \begin{pmatrix} 0 \\sin(\pi/2)\end{pmatrix} = \begin{pmatrix}\pi/2\\1\end{pmatrix}. \end{align*} We want the tangents to be accurate in the endpoints. The slope in the start point $P_0$ is the slope of the vector $$P_1 - P_0 = P_1 - \begin{pmatrix}0\\0\end{pmatrix}=P_1=\begin{pmatrix}x_1\\y_1\end{pmatrix}.$$ The slope in the end point $P_3$ is the slope of the vector $$P_3 - P_2 = \begin{pmatrix}\pi/2\\1\end{pmatrix} - \begin{pmatrix}x_2\\y_2\end{pmatrix}.$$ We know that the slope at $x=0$ (i.e. in $P_1$) is $1$, therefore \begin{align*} y_1/x_1 = 1 \Rightarrow y_1 = x_1\\ \Rightarrow P_1 = \begin{pmatrix}x_1\\x_1\end{pmatrix}. \end{align*} The slope at $x=\pi/2$ (i.e. in point $P_2$) is 0, therefore \begin{align*} {{y_2 - 1}\over{x_2 - \pi/2}} = 0 \Rightarrow y_2 = 1\\ \Rightarrow P_2 = \begin{pmatrix}x_2\\1\end{pmatrix}. \end{align*} To find $x_1$ and $x_2$, we require the curvature of the approximating Bézier curve to be accurate in the boundary points. The curvature of a graph of function $f$ is $$ k(x) = \frac{f''(x)}{(1+f'(x)^2)^{3/2}}.$$ For the $sin$ function, it's therefore $$ k(x) = \frac{-sin(x)}{(1+cos(x)^2)^{3/2}}.$$ We want to match the curvature at $x=0$ and $x=\pi/2$: \begin{align*} k(0) &= \frac{0}{(1+1^2)^{3/2}} = 0,\\ k(\pi/2) &= \frac{-1}{(1+0^2)^{3/2}} = -1.\\ \end{align*} The curvature of a parametric curve $p$ with $$p(t)=\begin{pmatrix}x(t)\\y(t)\end{pmatrix}$$ is $$k(t) = \frac{x'(t)y''(t)-y'(t)x''(t)}{(x'(t)^2+y'(t)^2)^{3/2}}.$$ We therefore need the first and second derivative of the Bézier curve $p$: \begin{align*} p(t) &= (1-t)^3 P_0 + 3t(1-t)^2 P_1 + 3t^2(1-t) P_2 + t^3 P_3\\ &= (1-t)^3 \begin{pmatrix}0\\0\end{pmatrix} + 3t(1-t)^2 \begin{pmatrix}x_1\\x_1\end{pmatrix} + 3t^2(1-t) \begin{pmatrix}x_2\\1\end{pmatrix} + t^3 \begin{pmatrix}\pi/2\\1\end{pmatrix}\\ & = 3(t-2t^2+t^3) \begin{pmatrix}x_1\\x_1\end{pmatrix} + 3(t^2-t^3) \begin{pmatrix}x_2\\1\end{pmatrix} + t^3 \begin{pmatrix}\pi/2\\1\end{pmatrix}\\ p'(t) & = 3(1-4t+3t^2 ) \begin{pmatrix}x_1\\x_1\end{pmatrix} + 3(2t-3t^2) \begin{pmatrix}x_2\\1\end{pmatrix} + 3t^2 \begin{pmatrix}\pi/2\\1\end{pmatrix}\\ p''(t) &= 3( -4 +6t ) \begin{pmatrix}x_1\\x_1\end{pmatrix} + 3(2 -6t ) \begin{pmatrix}x_2\\1\end{pmatrix} + 6t \begin{pmatrix}\pi/2\\1\end{pmatrix}\\ \end{align*} We only need the derivatives at $t=0$ and $t=1$ as we want to match the curvature in these points: \begin{align*} p'(0) & = 3\begin{pmatrix}x_1\\x_1\end{pmatrix}\\ p''(0)& = -12\begin{pmatrix}x_1\\x_1\end{pmatrix} + 6\begin{pmatrix}x_2\\1\end{pmatrix}=\begin{pmatrix}-12x_1+6x_2\\-12x_1+6\end{pmatrix}\\ p'(1) & = -3\begin{pmatrix}x_2\\1\end{pmatrix}+3\begin{pmatrix}\pi/2\\1\end{pmatrix}=\begin{pmatrix}3/2\pi -3x_2\\0\end{pmatrix}\\ p''(1)& = 6\begin{pmatrix}x_1\\x_1\end{pmatrix}-12\begin{pmatrix}x_2\\1\end{pmatrix}+6\begin{pmatrix}\pi/2\\1\end{pmatrix}=\begin{pmatrix}6x_1-12x_2+3\pi\\6x_1-6\end{pmatrix} \end{align*} The curvature of the Bézier curve at $t=0$ is therefore: \begin{align*} &k(0) = \frac{x'(0)y''(0)-y'(0)x''(0)}{(x'(0)^2+y'(0)^2)^{3/2}}\\ & \stackrel{x'(0)=y'(0)}{=} \frac{x'(0)(y''(0)-x''(0))}{(2x'(0)^2)^{3/2}}\stackrel{!}{=}0\\ &\Rightarrow y''(0) = x''(0)\\ &\Rightarrow -12x_1+6 = -12x_1+6x_2\\ &\Rightarrow x_2 = 1 \end{align*} We can determine $x_1$ using the curvature at $t=1$: \begin{align*} k(1)=&\frac{x'(1)y''(1)-y'(1)x''(1)}{(x'(1)^2+y'(1)^2)^{3/2}}\\ \stackrel{y'(1)=0}{=}&\frac{x'(1)y''(1)}{x'(1)^3}\\ =&\frac{y''(1)}{x'(1)^2}\stackrel{!}{=}-1\\ \Rightarrow y''(1)=&-x'(1)^2\\ \Rightarrow 6x_1 -6=& -(3/2\pi-3x_2)^2\\ \stackrel{x_2=1}{\Rightarrow}x_1 =& \frac{6-(3/2\pi-3)^2}{6} \approx 0.51128733 \end{align*} The control points are therefore \begin{align*} P_0 &= \begin{pmatrix} 0 \\0\end{pmatrix}\\ P_1 &= \frac{6-(3/2\pi-3)^2}{6}\begin{pmatrix} 1 \\1\end{pmatrix}\\ P_2 &= \begin{pmatrix} 1 \\1\end{pmatrix}\\ P_3 &= \begin{pmatrix}\pi/2\\1\end{pmatrix} \end{align*} These control points can be transformed to piece together a spline interpolation of the sine curve.
ERROR: JavaScript must be enabled to render input!
Wed, 19 Dec 2012 07:51 GMT