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
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 bezier
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.TranslateTransform(ClientRectangle.Width / 2, ClientRectangle.Height / 2);
PointF[] points = new PointF[4] {new PointF(4, 230), new PointF(110, 20), new PointF(209, 128), new PointF(360, 17)};
PointF[] p = new PointF[20];
int j = 0;
for (float i = 0; i <= 1; i += 0.001f)
{
float tempX = (float)Math.Pow((1 - i), 3) * points[0].X + 3 * i * (1 - i) * (1 - i) * points[1].X + 3 * i * i * (1 - i) * points[2].X + i * i * i * points[3].X;
float tempY = (float)Math.Pow((1 - i), 3) * points[0].Y + 3 * i * (1 - i) * (1 - i) * points[1].Y + 3 * i * i * (1 - i) * points[2].Y + i * i * i * points[3].Y;
g.DrawEllipse(new Pen(Color.Black, 2), tempX, tempY, 1, 1);
}
for (int i = 0; i < 4; ++i)
g.DrawEllipse(new Pen(Color.Red, 5), points[i].X, points[i].Y, 5, 5);
g.DrawPolygon(new Pen(Color.Blue), points);
}
}
}