private double getNik double int int double Niks new double for int kk

 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
private double getNik(double t, int i, int k)
{
double[,] Niks = new double[k, i + k];
for (int kk = 1; kk <= k; ++kk)
{
for (int ii = i; ii < k + i - kk + 1; ++ii)
{
double NikPrev1, NikPrev2;
if (kk == 1) {
if (isEqualNull(Math.Abs(knots[ii] - t)) || (knots[ii] < t && t < knots[ii + 1])) {
NikPrev1 = 1;
} else {
NikPrev1 = 0;
}
Niks[kk - 1, ii] = NikPrev1;
continue;
} else {
NikPrev1 = Niks[kk - 2, ii];
NikPrev2 = Niks[kk - 2, ii + 1];
}
double numerator1 = (t - knots[ii]) * NikPrev1,
znam1 = knots[ii + kk - 1] - knots[ii];
double numerator2 = (knots[ii + kk] - t) * NikPrev2,
znam2 = knots[ii + kk] - knots[ii + 1];
double proportion1, proportion2;
if (isEqualNull(numerator1) || isEqualNull(znam1)) {
proportion1 = 0;
} else {
proportion1 = numerator1 / znam1;
}
if (isEqualNull(numerator2) || isEqualNull(znam2)) {
proportion2 = 0;
} else {
proportion2 = numerator2 / znam2;
}
double curN = proportion1 + proportion2;
Niks[kk - 1, ii] = curN;
}
}
return Niks[k - 1, i];
}