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
140
141
142
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
PointF[] B = new PointF[5];
int m = 0;
int k = 3;
int n=3;
int f = 20;
private void Form1_Load(object sender, EventArgs e)
{
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
for (int j = 0; j < m; j++)
{
if ((Math.Abs(e.X - B[j].X) < 5) && (Math.Abs(e.Y - B[j].Y) < 5))
{
f = j;
}
}
this.Invalidate();
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (f < 20)
{
B[f].X = e.X;
B[f].Y = e.Y;
}
//this.Invalidate();
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
f = 20;
this.Invalidate();
}
private void Form1_MouseClick(object sender, MouseEventArgs e)
{
if (m < n+1)
{
B[m].X = e.X;
B[m].Y = e.Y;
m++;
}
this.Invalidate();
}
public float Get_N(int i, int k, float t, int[] X)
{
float rez = 0;
if (1 == k)
{
if (t >= X[i] && t <= X[i + 1])
{
rez = 1;
}
else
{
rez = 0;
}
}
else
{
if ((X[i + k - 1] - X[i]) != 0)
{
rez += (t - X[i]) * Get_N(i, k - 1, t, X) / (X[i + k - 1] - X[i]);
}
if ((X[i + k] - X[i + 1]) != 0)
{
rez += (X[i + k] - t) * Get_N(i + 1, k - 1, t, X) / (X[i + k] - X[i + 1]);
}
}
return rez;
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
int[] X = new int[n + k + 1 ];
Graphics g = e.Graphics;
SolidBrush pen1 = new SolidBrush(Color.Black);
for (int j = 0; j < 5; j++)
{
if ((B[j].X != 0) && (B[j].Y != 0))
{
g.FillEllipse(pen1, B[j].X, B[j].Y, 8, 8);
}
}
if (m == n+1)
{
for (int i = 0; i < X.Length; i++)
{
X[i] = i;
}
if (X == null) return;
for (float t = X[0]; t <= X[X.Length-1]; t += 0.001f)
{
float Xt = 0;
float Yt = 0;
for (int i = 0; i < n + 1; i++)
{
Xt += B[i].X * Get_N(i, k, t, X);
Yt += B[i].Y * Get_N(i, k, t, X);
}
g.DrawEllipse(new Pen(Color.Blue), Xt, Yt, 1, 1);
}
}
}
}
}