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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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];
}
private double getNikRecursion(double t, int i, int k)
{
if (k == 1) {
if (isEqualNull(Math.Abs(knots[i] - t)) || (knots[i] < t && t < knots[i + 1])) {
return 1;
} else {
return 0;
}
}
double numerator1 = (t - knots[i]) * getNikRecursion(t, i, k - 1),
znam1 = knots[i + k - 1] - knots[i];
double numerator2 = (knots[i + k] - t) * getNikRecursion(t, i + 1, k - 1),
znam2 = knots[i + k] - knots[i + 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;
return curN;
}
public double[] getKnots(int n, int k)
{
int size = n + k;
double[] knots = new double[size];
int temp = 0;
for (int i = 0; i < size; ++i) {
if (i >= k && size - i >= k) {
++temp;
}
knots[i] = temp;
}
return knots;
}