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 _2D
- {
- public partial class Form1 : Form
- {
- public const int n = 10, m = 4;
- public float[,] matrix = new float[n, m];
- public Form1()
- {
- InitializeComponent();
- float w = this.ClientSize.Width;
- float h = this.ClientSize.Height;
- matrix[0, 0] = (-8);
- matrix[1, 0] = 8;
- matrix[2, 0] = (-6);
- matrix[3, 0] = (-8);
- matrix[4, 0] = (-8);
- matrix[5, 0] = ;
- matrix[6, 0] = ;
- matrix[7, 0] = (-8);
- matrix[8, 0] = (-8);
- matrix[9, 0] = (-8);
- matrix[0, 1] = 8;
- matrix[1, 1] = (-8);
- matrix[2, 1] = (-4);
- matrix[3, 1] = 2;
- matrix[4, 1] = 8;
- matrix[0, 2] = 2;
- matrix[1, 2] = 2;
- matrix[2, 2] = 2;
- matrix[3, 2] = 2;
- matrix[4, 2] = 2;
- matrix[5, 2] = 2;
- matrix[6, 2] = 2;
- matrix[7, 2] = 2;
- matrix[8, 2] = 2;
- matrix[9, 2] = 2;
- matrix[0, 3] = 1;
- matrix[1, 3] = 1;
- matrix[2, 3] = 1;
- matrix[3, 3] = 1;
- matrix[4, 3] = 1;
- matrix[5, 3] = 1;
- matrix[6, 3] = 1;
- matrix[7, 3] = 1;
- matrix[8, 3] = 1;
- matrix[9, 3] = 1;
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- Refresh();
- }
- static float[,] Multiplication(float[,] a, float[,] b)
- {
- float[,] result = new float[a.GetLength(0), b.GetLength(1)];
- for (int i = 0; i < a.GetLength(0); ++i)
- {
- for (int j = 0; j < b.GetLength(1); ++j)
- {
- for (int k = 0; k < a.GetLength(1); ++k)
- {
- result[i, j] += a[i, k] * b[k, j];
- }
- }
- }
- return result;
- }
- public float MonitorX(float tmp)
- {
- float X_mon;
- X_mon = Width / 20 * (10 + tmp);
- return X_mon;
- }
- public float MonitorY(float tmp)
- {
- float Y_mon;
- Y_mon = Height / 20 * (10 - tmp);
- return Y_mon;
- }
- private void Button3_Click(object sender, EventArgs e)
- {
- Refresh();
- float w = this.ClientSize.Width;
- float h = this.ClientSize.Height;
- Graphics g = this.CreateGraphics();
- Pen pen = new Pen(Color.FromArgb(255, 255, 0, 0));
- Pen color = new Pen(Color.FromArgb(255, 255, 0, 255));
- g.DrawLine(pen, w / 2, 0, w /2 , h);
- g.DrawLine(pen, 0, h / 2, w, h / 2);
- for (int i = 0; i < n - 2; i++)
- {
- for (int j = 0; j < m - 2; j++)
- {
- if (i==2)
- g.DrawLine(color, MonitorX(matrix[i + 1, j]), MonitorY(matrix[i + 1, j + 1]), MonitorX(matrix[0, 0]), MonitorY(matrix[0, 1]));
- g.DrawLine(color, MonitorX(matrix[i, j]), MonitorY(matrix[i, j + 1]), MonitorX(matrix[i + 1, j]), MonitorY(matrix[i + 1, j + 1]));
- }
- }
- g.Dispose();
- }
- private void Rotation_Click(object sender, EventArgs e)
- {
- //Refresh();
- double tmp = 45 * Math.PI / 180;
- float [,] rotation = new float[3, 3];
- rotation[0, 0] = (float)Math.Sin(tmp);
- rotation[0, 1] = (float)Math.Cos(tmp);
- rotation[0, 2] = 0;
- rotation[1, 0] = (float)(Math.Sin(tmp)) * -1;
- rotation[1, 1] = (float)Math.Cos(tmp);
- rotation[1, 2] = 0;
- rotation[2, 0] = 0;
- rotation[2, 1] = 0;
- rotation[2, 2] = 1;
- //float[,] rotation = { { }, { }, { } }
- float[,] rotation_result = Multiplication(matrix, rotation);
- Graphics g = this.CreateGraphics();
- Pen color = new Pen(Color.FromArgb(255, 255, 0, 175));
- for (int i = 0; i < n - 2; i++)
- {
- for (int j = 0; j < m - 2; j++)
- {
- if (i == 2)
- g.DrawLine(color, MonitorX(rotation_result[i + 1, j]), MonitorY(rotation_result[i + 1, j + 1]), MonitorX(rotation_result[0, 0]), MonitorY(rotation_result[0, 1]));
- g.DrawLine(color, MonitorX(rotation_result[i, j]), MonitorY(rotation_result[i, j + 1]), MonitorX(rotation_result[i + 1, j]), MonitorY(rotation_result[i + 1, j + 1]));
- }
- }
- g.Dispose();
- }
- private void Scale_Click(object sender, EventArgs e)
- {
- float[,] scalle = new float[3, 3];
- scalle[0, 0] = (float)0.5;
- scalle[0, 1] = 0;
- scalle[0, 2] = 0;
- scalle[1, 0] = 0;
- scalle[1, 1] = (float)0.5;
- scalle[1, 2] = 0;
- scalle[2, 0] = 0;
- scalle[2, 1] = 0;
- scalle[2, 2] = 1;
- float[,] scalle_result = Multiplication(matrix, scalle);
- Graphics g = this.CreateGraphics();
- Pen color = new Pen(Color.FromArgb(255, 0, 0, 175));
- for (int i = 0; i < n - 2; i++)
- {
- for (int j = 0; j < m - 2; j++)
- {
- if (i == 2)
- g.DrawLine(color, MonitorX(scalle_result[i + 1, j]), MonitorY(scalle_result[i + 1, j + 1]), MonitorX(scalle_result[0, 0]), MonitorY(scalle_result[0, 1]));
- g.DrawLine(color, MonitorX(scalle_result[i, j]), MonitorY(scalle_result[i, j + 1]), MonitorX(scalle_result[i + 1, j]), MonitorY(scalle_result[i + 1, j + 1]));
- }
- }
- g.Dispose();
- }
- private void Reflect_Click(object sender, EventArgs e)
- {
- float[,] reflect = new float[3, 3];
- reflect[0, 0] = -1;
- reflect[0, 1] = 0;
- reflect[0, 2] = 0;
- reflect[1, 0] = 0;
- reflect[1, 1] = -1;
- reflect[1, 2] = 0;
- reflect[2, 0] = 0;
- reflect[2, 1] = 0;
- reflect[2, 2] = 1;
- float[,] reflect_result = Multiplication(matrix, reflect);
- Graphics g = this.CreateGraphics();
- Pen color = new Pen(Color.FromArgb(255, 255, 255, 255));
- for (int i = 0; i < n - 2; i++)
- {
- for (int j = 0; j < m - 2; j++)
- {
- if (i == 2)
- g.DrawLine(color, MonitorX(reflect_result[i + 1, j]), MonitorY(reflect_result[i + 1, j + 1]), MonitorX(reflect_result[0, 0]), MonitorY(reflect_result[0, 1]));
- g.DrawLine(color, MonitorX(reflect_result[i, j]), MonitorY(reflect_result[i, j + 1]), MonitorX(reflect_result[i + 1, j]), MonitorY(reflect_result[i + 1, j + 1]));
- }
- }
- g.Dispose();
- }
- private void Transposition_Click(object sender, EventArgs e)
- {
- float[,] trans = new float[3, 3];
- trans[0, 0] = 1;
- trans[0, 1] = 0;
- trans[0, 2] = 0;
- trans[1, 0] = 0;
- trans[1, 1] = 1;
- trans[1, 2] = 0;
- trans[2, 0] = 2;
- trans[2, 1] = 2;
- trans[2, 2] = 1;
- float[,] trans_result = Multiplication(matrix, trans);
- Graphics g = this.CreateGraphics();
- Pen color = new Pen(Color.FromArgb(255, 170, 255, 50));
- for (int i = 0; i < n - 2; i++)
- {
- for (int j = 0; j < m - 2; j++)
- {
- if (i == 2)
- g.DrawLine(color, MonitorX(trans_result[i + 1, j]), MonitorY(trans_result[i + 1, j + 1]), MonitorX(trans_result[0, 0]), MonitorY(trans_result[0, 1]));
- g.DrawLine(color, MonitorX(trans_result[i, j]), MonitorY(trans_result[i, j + 1]), MonitorX(trans_result[i + 1, j]), MonitorY(trans_result[i + 1, j + 1]));
- }
- }
- g.Dispose();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement