1

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.

  • [Eigen](https://eigen.tuxfamily.org/dox/unsupported/group__Splines__Module.html) has a splines library. I used it once and it was OK despite being officially unsupported. But I don't think it supports closed curves. – Potatoswatter Jan 31 '17 at 04:53
  • might be worth giving http://pomax.github.io/bezierinfo/#bsplines a read because implementing b-splines isn't actually all *that* much work. Also https://github.com/thibauts/b-spline/blob/master/index.js is a highly readable JS implementation that is (almost) trivially adopted to a wide number of other languages, including C++ – Mike 'Pomax' Kamermans Feb 01 '17 at 23:26

2 Answers2

0

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.

fang
  • 3,473
  • 1
  • 13
  • 19
0

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

Foivos
  • 545
  • 4
  • 13