Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 Krzywe_B
- {
- public partial class Form1 : Form
- {
- private System.Drawing.Graphics g;
- private System.Drawing.Pen pen1 = new System.Drawing.Pen(Color.Blue, 2);
- private System.Drawing.Pen pen2 = new System.Drawing.Pen(Color.Red, 2);
- PointF P1 = new PointF();
- PointF P2 = new PointF();
- PointF P3 = new PointF();
- PointF P4 = new PointF();
- PointF P5 = new PointF();
- PointF P6 = new PointF();
- PointF P7 = new PointF();
- PointF[] Points = new PointF[7];
- public Form1()
- {
- InitializeComponent();
- g = pictureBox1.CreateGraphics();
- P1.X = 0;
- P1.Y = 0;
- P2.X = 300;
- P2.Y = 0;
- P3.X = 150;
- P3.Y = 40;
- P4.X = 300;
- P4.Y = 300;
- Points[0] = P1;
- Points[1] = P2;
- Points[2] = P3;
- Points[3] = P4;
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- private void pictureBox1_Click(object sender, EventArgs e)
- {
- }
- private void button1_Click(object sender, EventArgs e)
- {
- double startx = Points[0].X;
- double starty = Points[0].Y;
- double x, y;
- g.DrawBezier(pen2, P1.X, P1.Y, P2.X, P2.Y, P3.X, P3.Y, P4.X, P4.Y);
- for (double t = 0; t < 1; t = t + 0.001)
- {
- x = Math.Pow((1 - t), 3) * Points[0].X + 3 * t * (Math.Pow((1 - t), 2)) * Points[1].X + 3 * t * t * (1 - t) * Points[2].X + t * t * t * Points[3].X;
- y = Math.Pow((1 - t), 3) * Points[0].Y + 3 * t * (Math.Pow((1 - t), 2)) * Points[1].Y + 3 * t * t * (1 - t) * Points[2].Y + t * t * t * Points[3].Y;
- g.DrawLine(pen1, (int)startx, (int)starty, (int)x, (int)y);
- startx = x;
- starty = y;
- }
- for(int i =0; i < Points.Length; i++)
- {
- g.DrawEllipse(pen2, new RectangleF(Points[i].X, Points[i].Y, 3, 3));
- }
- }
- private void button2_Click(object sender, EventArgs e)
- {
- pictureBox1.Refresh();
- P1.X = 0;
- P1.Y = 0;
- P2.X = 200;
- P2.Y = 3;
- P3.X = 10;
- P3.Y = 200;
- P4.X = 300;
- P4.Y = 300;
- double start = P1.X;
- double next = P2.Y;
- double x, y;
- PointF R1 = new PointF();
- PointF R2 = new PointF();
- R1.X = P2.X - P1.X;
- R1.Y = P2.Y - P1.Y;
- R2.X = P4.X - P3.X;
- R2.Y = P4.Y - P3.Y;
- for (double t = 0; t < 1; t = t + 0.001)
- {
- x = (2 * t * t * t - 3 * t * t + 1) * P1.X + (-2 * t * t * t + 3 * t * t) * P4.X + (t * t * t - 2 * t * t + t) * R1.X + (t * t * t - t * t) * R2.X;
- y = (2 * t * t * t - 3 * t * t + 1) * P1.Y + (-2 * t * t * t + 3 * t * t) * P4.Y + (t * t * t - 2 * t * t + t) * R1.Y + (t * t * t - t * t) * R2.Y;
- g.DrawLine(pen1, (int)start, (int)next, (int)x, (int)y);
- start = x;
- next = y;
- }
- }
- private void button3_Click(object sender, EventArgs e)
- {
- PointF P1 = new PointF();
- PointF P2 = new PointF();
- P1.X = 20;
- P1.Y = 30;
- P2.X = 10;
- double Tx = P1.X;
- double Ty = P1.Y;
- double x = 100;
- double y = 120;
- double r = 50;
- double alfa = 0;
- double dalfa = (2 * Math.PI) / 100;
- pictureBox1.Refresh();
- for (int i = 0; i < 1000; i++)
- {
- g.DrawLine(pen1,
- (int)(r * Math.Cos(alfa + dalfa * i) + (x)),
- (int)(r * Math.Sin(alfa + dalfa * i) + (y)),
- (int)(r * Math.Cos(alfa + dalfa * (i + 1)) + (x)),
- (int)(r * Math.Sin(alfa + dalfa * (i + 1)) + (y))
- );
- g.DrawLine(pen2,
- P2.X * (int)(r * Math.Cos(alfa + dalfa * i) + (x - Tx)),
- P2.X * (int)(r * Math.Sin(alfa + dalfa * i) + (y - Ty)),
- P2.X * (int)(r * Math.Cos(alfa + dalfa * (i + 1)) + (x - Tx)),
- P2.X * (int)(r * Math.Sin(alfa + dalfa * (i + 1)) + (y - Ty))
- );
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement