Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.66 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace _2D
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.  
  16.         public const int n = 10, m = 4;
  17.         public float[,] matrix = new float[n, m];
  18.  
  19.         public Form1()
  20.         {
  21.             InitializeComponent();
  22.  
  23.             float w = this.ClientSize.Width;
  24.             float h = this.ClientSize.Height;
  25.  
  26.             matrix[0, 0] = (-8);
  27.             matrix[1, 0] = 8;
  28.             matrix[2, 0] = (-6);
  29.             matrix[3, 0] = (-8);
  30.             matrix[4, 0] = (-8);
  31.             matrix[5, 0] = ;
  32.             matrix[6, 0] = ;
  33.             matrix[7, 0] = (-8);
  34.             matrix[8, 0] = (-8);
  35.             matrix[9, 0] = (-8);
  36.            
  37.             matrix[0, 1] = 8;
  38.             matrix[1, 1] = (-8);
  39.             matrix[2, 1] = (-4);
  40.             matrix[3, 1] = 2;
  41.             matrix[4, 1] = 8;
  42.  
  43.             matrix[0, 2] = 2;
  44.             matrix[1, 2] = 2;
  45.             matrix[2, 2] = 2;
  46.             matrix[3, 2] = 2;
  47.             matrix[4, 2] = 2;
  48.             matrix[5, 2] = 2;
  49.             matrix[6, 2] = 2;
  50.             matrix[7, 2] = 2;
  51.             matrix[8, 2] = 2;
  52.             matrix[9, 2] = 2;
  53.            
  54.             matrix[0, 3] = 1;
  55.             matrix[1, 3] = 1;
  56.             matrix[2, 3] = 1;
  57.             matrix[3, 3] = 1;
  58.             matrix[4, 3] = 1;
  59.             matrix[5, 3] = 1;
  60.             matrix[6, 3] = 1;
  61.             matrix[7, 3] = 1;
  62.             matrix[8, 3] = 1;
  63.             matrix[9, 3] = 1;
  64.  
  65.         }
  66.  
  67.         private void Form1_Load(object sender, EventArgs e)
  68.         {
  69.  
  70.             Refresh();
  71.  
  72.         }
  73.  
  74.         static float[,] Multiplication(float[,] a, float[,] b)
  75.         {
  76.             float[,] result = new float[a.GetLength(0), b.GetLength(1)];
  77.             for (int i = 0; i < a.GetLength(0); ++i)
  78.             {
  79.                 for (int j = 0; j < b.GetLength(1); ++j)
  80.                 {
  81.                     for (int k = 0; k < a.GetLength(1); ++k)
  82.                     {
  83.                         result[i, j] += a[i, k] * b[k, j];
  84.                     }
  85.                 }
  86.             }
  87.  
  88.             return result;
  89.         }
  90.  
  91.         public float MonitorX(float tmp)  
  92.         {
  93.             float X_mon;
  94.             X_mon = Width / 20 * (10 + tmp);
  95.             return X_mon;
  96.         }
  97.         public float MonitorY(float tmp)
  98.         {
  99.             float Y_mon;
  100.             Y_mon = Height / 20 * (10 - tmp);
  101.             return Y_mon;
  102.         }
  103.  
  104.         private void Button3_Click(object sender, EventArgs e)
  105.         {
  106.            
  107.             Refresh();
  108.  
  109.             float w = this.ClientSize.Width;
  110.             float h = this.ClientSize.Height;
  111.  
  112.             Graphics g = this.CreateGraphics();
  113.             Pen pen = new Pen(Color.FromArgb(255, 255, 0, 0));
  114.             Pen color = new Pen(Color.FromArgb(255, 255, 0, 255));
  115.             g.DrawLine(pen, w / 2, 0, w /2 , h);
  116.             g.DrawLine(pen, 0, h / 2, w, h / 2);
  117.  
  118.             for (int i = 0; i < n - 2; i++)
  119.             {
  120.                 for (int j = 0; j < m - 2; j++)
  121.                 {
  122.                     if (i==2)
  123.                         g.DrawLine(color, MonitorX(matrix[i + 1, j]), MonitorY(matrix[i + 1, j + 1]), MonitorX(matrix[0, 0]), MonitorY(matrix[0, 1]));
  124.                         g.DrawLine(color, MonitorX(matrix[i, j]), MonitorY(matrix[i, j + 1]), MonitorX(matrix[i + 1, j]), MonitorY(matrix[i + 1, j + 1]));
  125.                    
  126.                 }
  127.                
  128.             }
  129.             g.Dispose();
  130.  
  131.         }
  132.  
  133.         private void Rotation_Click(object sender, EventArgs e)
  134.         {
  135.  
  136.             //Refresh();
  137.             double tmp = 45 * Math.PI / 180;
  138.             float [,] rotation = new float[3, 3];
  139.             rotation[0, 0] = (float)Math.Sin(tmp);
  140.             rotation[0, 1] = (float)Math.Cos(tmp);
  141.             rotation[0, 2] = 0;
  142.             rotation[1, 0] = (float)(Math.Sin(tmp)) * -1;
  143.             rotation[1, 1] = (float)Math.Cos(tmp);
  144.             rotation[1, 2] = 0;
  145.             rotation[2, 0] = 0;
  146.             rotation[2, 1] = 0;
  147.             rotation[2, 2] = 1;
  148.  
  149.             //float[,] rotation = { { }, { }, { } }
  150.  
  151.             float[,] rotation_result = Multiplication(matrix, rotation);
  152.  
  153.  
  154.  
  155.             Graphics g = this.CreateGraphics();
  156.             Pen color = new Pen(Color.FromArgb(255, 255, 0, 175));
  157.             for (int i = 0; i < n - 2; i++)
  158.             {
  159.                 for (int j = 0; j < m - 2; j++)
  160.                 {
  161.                     if (i == 2)
  162.                         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]));
  163.                         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]));
  164.  
  165.                 }
  166.  
  167.             }
  168.             g.Dispose();
  169.  
  170.  
  171.         }
  172.  
  173.         private void Scale_Click(object sender, EventArgs e)
  174.         {  
  175.             float[,] scalle = new float[3, 3];
  176.             scalle[0, 0] = (float)0.5;
  177.             scalle[0, 1] = 0;
  178.             scalle[0, 2] = 0;
  179.             scalle[1, 0] = 0;
  180.             scalle[1, 1] = (float)0.5;
  181.             scalle[1, 2] = 0;
  182.             scalle[2, 0] = 0;
  183.             scalle[2, 1] = 0;
  184.             scalle[2, 2] = 1;
  185.             float[,] scalle_result = Multiplication(matrix, scalle);
  186.  
  187.  
  188.  
  189.             Graphics g = this.CreateGraphics();
  190.             Pen color = new Pen(Color.FromArgb(255, 0, 0, 175));
  191.             for (int i = 0; i < n - 2; i++)
  192.             {
  193.                 for (int j = 0; j < m - 2; j++)
  194.                 {
  195.                     if (i == 2)
  196.                         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]));
  197.                         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]));
  198.  
  199.                 }
  200.  
  201.             }
  202.             g.Dispose();
  203.  
  204.         }
  205.  
  206.         private void Reflect_Click(object sender, EventArgs e)
  207.         {
  208.  
  209.             float[,] reflect = new float[3, 3];
  210.             reflect[0, 0] = -1;
  211.             reflect[0, 1] = 0;
  212.             reflect[0, 2] = 0;
  213.             reflect[1, 0] = 0;
  214.             reflect[1, 1] = -1;
  215.             reflect[1, 2] = 0;
  216.             reflect[2, 0] = 0;
  217.             reflect[2, 1] = 0;
  218.             reflect[2, 2] = 1;
  219.             float[,] reflect_result = Multiplication(matrix, reflect);
  220.  
  221.  
  222.  
  223.             Graphics g = this.CreateGraphics();
  224.             Pen color = new Pen(Color.FromArgb(255, 255, 255, 255));
  225.             for (int i = 0; i < n - 2; i++)
  226.             {
  227.                 for (int j = 0; j < m - 2; j++)
  228.                 {
  229.                     if (i == 2)
  230.                         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]));
  231.                         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]));
  232.  
  233.                 }
  234.  
  235.             }
  236.             g.Dispose();
  237.  
  238.         }
  239.  
  240.         private void Transposition_Click(object sender, EventArgs e)
  241.         {
  242.  
  243.  
  244.             float[,] trans = new float[3, 3];
  245.             trans[0, 0] = 1;
  246.             trans[0, 1] = 0;
  247.             trans[0, 2] = 0;
  248.             trans[1, 0] = 0;
  249.             trans[1, 1] = 1;
  250.             trans[1, 2] = 0;
  251.             trans[2, 0] = 2;
  252.             trans[2, 1] = 2;
  253.             trans[2, 2] = 1;
  254.             float[,] trans_result = Multiplication(matrix, trans);
  255.  
  256.  
  257.  
  258.             Graphics g = this.CreateGraphics();
  259.             Pen color = new Pen(Color.FromArgb(255, 170, 255, 50));
  260.             for (int i = 0; i < n - 2; i++)
  261.             {
  262.                 for (int j = 0; j < m - 2; j++)
  263.                 {
  264.                     if (i == 2)
  265.                         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]));
  266.                         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]));
  267.  
  268.                 }
  269.  
  270.             }
  271.             g.Dispose();
  272.  
  273.         }
  274.     }
  275. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement