#include #include #include #include //#include "util/box.h" #include "util/vec3f.h" #include "bspline.h" //B-Splines for use in field modeling shape functions //For a nice reference, see //Finite Element Methods with B-Splines, Klaus Hollig /* Define a univariate n-degree b spline. Here the grid size is one, we scale below.s n=1 gives linear hat function, n=2 quadratic, */ float bspline_base(const float xx, const int n) { const float x = abs(xx); //symmetric about origin if (n==1) { if (x<1) return 1-x; else return 0; } else if (n==2) { if (x<.5) return 1+x-(x+.5)*(x+.5); else if (x<1.5) return 1-x+.5*(x-.5)*(x-.5); else return 0.; } else { assert(0); //bspline degree not implemented return 0; } } /* Define corresponding derivative */ float d_bspline_base(const float x, const int n) { if (n==1){ if (0<=x<=1) return -1; else if (-1<=x<0) return 1; else return 0; } else if (n==2){ if (-.5<=x<=.5) return -2*x; else if (.5