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))); } } } }