using System using System Collections Generic using System ComponentMo

  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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace nynyny
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private bool isEqualNull(double num)
{
return Math.Abs(num) <= 1e-8;
}
public int[] knots = { };
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];
}
public int[] getKnots(int n, int k)
{
int size = n + k;
int[] knots = new int[size];
int temp = 0;
for (int i = 0; i < size; ++i)
{
if (i >= k && size - i >= k)
{
++temp;
}
knots[i] = temp;
}
return knots;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
Graphics g = pictureBox1.CreateGraphics();
int k = 2;
const int n = 3;
double t = 0;
int[,] mea = new int[n, 2] { { 0, 100 }, { 100, -100 }, { 200, 100 } };
knots = getKnots(n, k);
for (int i = 1; i < knots.Length; i++)
{
double t_min = knots[i - 1];
double t_max = knots[i];
double sum_x = 0;
double sum_y = 0;
while (t_min < t_max)
{
t_min += 0.01;
double Nik = getNik(t_min, i, k);
sum_x += mea[i, 0] * Nik;
sum_y += mea[i, 1] * Nik;
}
g.DrawEllipse(new Pen(new SolidBrush(Color.Blue), 2), new RectangleF(new PointF((float)(sum_x), (float)(mea[i, 1] * sum_y)), new Size(2, 2)));
}
}
}
}