File: basisSplines.h

package info (click to toggle)
groops 0%2Bgit20240830%2Bds-1
  • links: PTS, VCS
  • area: non-free
  • in suites: trixie
  • size: 11,052 kB
  • sloc: cpp: 134,939; fortran: 1,569; makefile: 20
file content (53 lines) | stat: -rw-r--r-- 1,135 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/***********************************************/
/**
* @file basisSplines.h
*
* @brief Basis Splines.
*
* @author Beate Klinger
* @date 2015-05-30
*
*/
/***********************************************/

#ifndef __GROOPS_BASISSPLINES__
#define __GROOPS_BASISSPLINES__

#include "base/importStd.h"
#include "matrix.h"

/***** CLASS ***********************************/

/** @brief Basis Splines.
* @ingroup base */
namespace BasisSplines
{
  /** @brief Basis Splines.
  * @param t in [0,1).
  * @param degree spline degree.
  * @return vector(degree+1) with splines coefficients. */
  inline Vector compute(Double t, UInt degree);
}

/***********************************************/
/***** INLINES *********************************/
/***********************************************/

inline Vector BasisSplines::compute(Double t, UInt degree)
{
  Vector b(degree+1);
  b(0) = 1.;
  for(UInt n=1; n<=degree; n++)
  {
    b(n) = t/n * b(n-1);
    for(UInt i=n; i-->1;)
      b(i) = (t+n-i)/n * b(i-1) - (t-i-1)/n * b(i);
    b(0) *= (1-t)/n;
  }

  return b;
}

/***********************************************/

#endif /* __GROOPS__ */