# How to calculate interpolating splines in 3D space?

I'm trying to model a smooth path between several control points in three dimensions, the problem is that there doesn't appear to be an explanation on how to use splines to achieve this. Are splines a subset of other types of curves such as Bezier curve or the Hermite curve?

I have successfully found cubic splines in 2 dimensions, but I'm not sure how to extend it into 3 dimensions and why there is no explanation about this.

Is there a better and more documented type of curve I could use to achieve this? My goal is to move an object along the smooth curve going through the control points. Please help.

• This article focuses on explaining the thought processes and concepts behind 2D splines, but can be extended to 3 dimensions Commented Apr 20, 2023 at 23:36

First, let's understand parametric splines.

Let's assume we already know how to find $$y$$ as a (spline) function of $$x$$. And suppose we have a sequence of 2D points $$P_i = (x_i,y_i)$$. First, we assign a parameter value $$t_i$$ to each point $$P_i$$. The usual way to do this is to use chord-lengths -- you choose the $$t_i$$ values such that $$t_i - t_{i-1} = \|P_i - P_{i-1}\|$$. Then you compute $$x$$ as a function of $$t$$. The calculation is the one you already know, but it's just $$x=f(t)$$ instead of $$y=f(x)$$. Now do the same thing with $$y$$ and $$t$$. So, now you have both $$x$$ and $$y$$ as functions of $$t$$. In other words, you have a 2D point $$(x,y)$$ as function of $$t$$, which means you have a 2D parametric curve.

Now, the extension to 3D is straightforward. We just make $$z$$ a function of $$t$$, also. So, now we have $$(x,y,z)$$ as a function of $$t$$, so we have a parametric space curve.

To do 3D spline interpolation using Matlab functions, see here.

A better reference is this web site.

Bezier curves are also easy to extend to 3D. As you probably know, the equation of a cubic Bezier curve is $$\mathbf{C}(t) = (1-t)^3\mathbf{P}_0 + 3t(1-t)^2\mathbf{P}_1 + 3t^2(1-t)\mathbf{P}_2 + t^3\mathbf{P}_3$$ In this equation it doesn't matter whether the control points $$\mathbf{P}_0$$, $$\mathbf{P}_1$$, $$\mathbf{P}_2$$, $$\mathbf{P}_3$$ are 2D or 3D.

• I found cubic splines in 2D by finding y in terms of x and not t, which is why I'm now confused. I can't find any decent explanation to find splines in terms of a parameter t. Commented Nov 24, 2013 at 18:58
• The math is identical. See the additions to my answer. Commented Nov 25, 2013 at 14:17
• @Saras take a look at this very good pdf, except for an error in computed value of the b coefficient in the 14.1 paragraph, where "𝒃 = −𝟐. 𝟔7" and not "−2 ∙ (2 2⁄3)": people.cs.clemson.edu/~dhouse/courses/405/notes/splines.pdf Commented Nov 11, 2018 at 16:42

This seems relevant: https://en.wikipedia.org/wiki/Bicubic_interpolation

There is a MATLAB toolkit with this functionality (spline toolkit).

• But isn't that used for images and surfaces? I only need a path. Commented Nov 23, 2013 at 9:01
• Ah, I see what you mean now. You want to parameterize your spline as in @bubba's solution. Commented Nov 25, 2013 at 18:59