I want to figure out how to calculate a cubic spline using 3d points. The wiki page shows a good example for 2d points but I just cannot find any resources that would let me do it with a 3d point aka P(x,y,z). I don't understand how to add a z into the equations given and I'm not great at math so I need a clear explanation of how to do this. Any help is appreciated.
Interpolating splines with 3d points
3.4k Views Asked by Bumbble Comm https://math.techqa.club/user/bumbble-comm/detail AtThere are 2 best solutions below
On
The trick is that instead of using $t$ as a parameter along one axis, you use it as a free parameter, with $t = 0$ at the beginning of the curve, and $t = 1$ at the end of the curve, with $0 \le t \le 1$ specifying the points on the curve.
All cubic curves of a single parameter are of form $$\begin{cases} x(t) = X_0 + X_1 t + X_2 t^2 + X_3 t^3 \\ y(t) = Y_0 + Y_1 t + Y_2 t^2 + Y_3 t^3 \\ z(t) = Z_0 + Z_1 t + Z_2 t^2 + Z_3 t^3 \end{cases} \tag{1}\label{1}$$ The tangent of the curve is $$\begin{cases} \frac{d x(t)}{d t} = dx(t) = X_1 + 2 X_2 t + 3 X_3 t^2 \\ \frac{d y(t)}{d t} = dy(t) = Y_1 + 2 Y_2 t + 3 Y_3 t^2 \\ \frac{d z(t)}{d t} = dz(t) = Z_1 + 2 Z_2 t + 3 Z_3 t^2 \end{cases} \tag{2}\label{2}$$
Let's say you need a cubic interpolating curve $\vec{p}(t)$, with $$\begin{cases} \vec{p}(0) = \vec{p}_0 = ( x_0 , y_0 , z_0 ) \\ \vec{p}(1) = \vec{p}_1 = ( x_1 , y_1 , z_1 ) \\ \left.\frac{d \vec{p}(t)}{d t}\right\rvert_{t=0} = \vec{d}_0 = ( dx_0 , dy_0 , dz_0 ) \\ \left.\frac{d \vec{p}(t)}{d t}\right\rvert_{t=1} = \vec{d}_1 = ( dx_1 , dy_1 , dz_1 ) \end{cases} \tag{3}\label{3}$$ i.e. the curve starts from $\vec{p}_0$ tangent to $\vec{d}_0$, and ends at $\vec{p}_1$ tangent to $\vec{d}_1$.
If we combine $\eqref{1}$, $\eqref{2}$, and $\eqref{3}$, and solve for the curve coefficients $X_0$, $X_1$, ..., $Z_2$, $Z_3$, we get $$\begin{cases} X_0 = x_0 \\ X_1 = dx_0 \\ X_2 = 3 ( x_1 - x_0 ) - ( dx_1 + 2 dx_0 ) \\ X_3 = 2 ( x_0 - x_1 ) + dx_1 + dx_0 \\ Y_0 = y_0 \\ Y_1 = dy_0 \\ Y_2 = 3 ( y_1 - y_0 ) - ( dy_1 + 2 dy_0 ) \\ Y_3 = 2 ( y_0 - y_1 ) + dy_1 + dy_0 \\ Z_0 = z_0 \\ Z_1 = dz_0 \\ Z_2 = 3 ( z_1 - z_0 ) - ( dz_1 + 2 dz_0 ) \\ Z_3 = 2 ( z_0 - z_1 ) + dz_1 + dz_0 \end{cases} \tag{4}\label{4}$$
Computer graphics, and file formats like SVG and PostScript and PDF, use cubic Bézier curves rather than the form specified in equation $\eqref{1}$ above. (Bézier curves trivially extend to any number of dimensions, although the two-dimensional ones are most common.)
Cubic Bézier curves are defined as $$\vec{p}(t) = (1 - t)^3 \vec{c}_0 + 3 t (1 - t)^2 \vec{c}_1 + 3 t^2 (1 - t) \vec{c}_2 + t^3 \vec{c}_3 \tag{5}\label{5}$$ By defining $\vec{p}(t) = \left ( x(t) , y(t) , z(t) \right )$ and $$\begin{cases} \vec{c}_0 = ( x_0 , y_0 , z_0 ) \\ \vec{c}_1 = \left ( x_0 + \frac{dx_0}{3} , y_0 + \frac{dy_0}{3} , z_0 + \frac{dz_0}{3} \right ) \\ \vec{c}_2 = \left ( x_1 - \frac{dx_1}{3} , y_1 - \frac{dy_1}{3} , z_1 - \frac{dz_1}{3} \right ) \\ \vec{c}_3 = ( x_1 , y_1 , z_1 ) \end{cases}$$ we have a Bézier curve that fulfills the requirements in $\eqref{3}$, and is exactly the same as the curve specified by $\eqref{1}$ and $\eqref{4}$.
First we should define what is a 3-dimensional spline. Spline functions are immanantly connected with a plane. Maybe you should try Bezier curves, which are independent on dimension?