forked from abacusmodeling/abacus-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmath_bspline.cpp
More file actions
58 lines (51 loc) · 1.27 KB
/
math_bspline.cpp
File metadata and controls
58 lines (51 loc) · 1.27 KB
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
54
55
56
#include "math_bspline.h"
#include <cstdlib>
#include <assert.h>
namespace ModuleBase
{
Bspline::Bspline()
{
bezier = nullptr;
norder = 0;
xi = 0;
Dx = 1.0;
}
Bspline::~Bspline()
{
if(bezier!=nullptr) delete[] bezier;
}
void Bspline::init(int norderin, double Dxin, double xiin)
{
this->xi = xiin;
this->Dx = Dxin;
this->norder = norderin;
assert(Dx > 0);
//norder must be a positive even number.
assert(norder > 0);
assert(norder % 2 == 0);
bezier = new double [this->norder+1];
for(int i = 0 ; i < norder+1 ; ++i)
{
bezier[i] = 0;
}
}
double Bspline::bezier_ele(int n)
{
return this->bezier[n];
}
void Bspline::getbspline(double x)
{
bezier[0] = 1.0;
for(int k = 1 ; k <= norder ; ++k)
{
//for n>=1
for(int n = k; n >= 1; --n )
{
this->bezier[n] = ((x + n*this->Dx - this->xi)*this->bezier[n] +
(this->xi + (k-n+1)*Dx - x)*this->bezier[n-1])/(k*this->Dx);
}
//for n = 0
this->bezier[0] = (x - this->xi)*this->bezier[0] / (k*this->Dx);
}
}
}