B-Spline for any number of control points

3.2k views Asked by At

I am currently working on a soft body system using numeric spring physics and I have finally got that working. My issue is that everything is currently in straight lines.

I am aiming to replicate something similar to the game "The floor is Jelly" and everything work except the smooth corners and deformation which currently are straight and angular.

I have tried using Cubic Bezier equations but that just means every 3 nodes I have a new curve. Is there an equation for Bezier splines that take in n number of control points that will work with loop of vec2's (so node[0] is the first and last control point).

Sorry I don't any code to show for this but i'm completely stumped and googling is bringing up nothing.

2

There are 2 answers

1
fang On BEST ANSWER

Simply google "B-spline library" will give you many references. Having said this, B-spline is not your only choice. You can use cubic Hermite spline (which is defined by a series of points and derivatives) (see link for details) as well.

On the other hand, you can also continue using straight lines in your system and create a curve interpolating the straight line vertices just for display purpose. To create an interpolating curve thru a series of data points, Catmull-Rom spline is a good choice for easy implementation. This approach is likely to have a better performance than really using a B-spline curve in your system.

0
Foivos On

I would use B-splines for this problem since they can represent smooth curves with minimal number of control points. In addition finding the approximate smooth surface for a given data set is a simple linear algebra problem.

I have written a simple B-spline C++ library (includes Bezier curves as well) that I am using for scientific computations, here: https://github.com/feevos/bsplines

it can accept arbitrary number of control points / multiplicities and give you back a basis. However, creating the B-spline curve that fits your data is something you have to do.

A great implementation of B-splines (but no Bezier curves) exists also in GNU GSL ( https://www.gnu.org/software/gsl/manual/html_node/Basis-Splines.html). Again here you have to implement the control points to be 2/3D for the given basis, and fix the boundary conditions to fit your data.

More information on open/closed curves and B-splines here: https://www.cs.mtu.edu/~shene/COURSES/cs3621/NOTES/index.html