calcBasisFunctions function

List<double> calcBasisFunctions(
  1. int span,
  2. num u,
  3. int p,
  4. List<double> U,
)

Implementation

List<double> calcBasisFunctions(int span, num u, int p, List<double> U ) {
	final List<double> N = List.filled(p+1, 0);
	final left = List.filled(p+1, 0.0);
	final right = List.filled(p+1, 0.0);
	N[0] = 1.0;

	for (int j = 1; j <= p; ++ j ) {
		left[ j ] = u - U[ span + 1 - j ];
		right[ j ] = U[ span + j ] - u;

		double saved = 0.0;

		for (int r = 0; r < j; ++ r ) {
			final rv = right[ r + 1 ];
			final lv = left[ j - r ];
			final temp = N[ r ] / ( rv + lv );
			N[r] = saved + rv * temp;
			saved = lv * temp;
		}

		N[j] = saved;
	}

	return N;
}