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 two_point_perspective { public partial class Form1 : Form { Pen pen = new Pen(Color.FromArgb(255, 0, 0, 0), 3); Pen pen1 = new Pen(Color.FromArgb(255, 47, 79, 79)); public Form1() { InitializeComponent(); } public double[,] mult(double[,] a, double[,] b) { double[,] c = new double[a.GetLength(0), b.GetLength(1)]; for (int i = 0; i < a.GetLength(0); ++i) { for (int j = 0; j < b.GetLength(1); ++j) { c[i, j] = 0; for (int k = 0; k < a.GetLength(1); ++k) { c[i, j] = c[i, j] + a[i, k] * b[k, j]; } } } return c; } public double[,] check(double[,] a) { for (int i = 0; i < a.GetLength(0); i++) { if (a[i, a.GetLength(1)-1] != 1) { for (int j = 0; j < a.GetLength(1); j++) { a[i, j] = a[i, j] / a[i, a.GetLength(1) - 1]; } } } return a; } private void Form1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; double[,] cube = new double[8, 4] { { 0, 0, 0, 1 }, { 100, 0, 0, 1 }, { 100, 0, 100, 1 }, { 0, 0, 100, 1 }, { 0, 100, 0, 1 }, { 100, 100, 0, 1 }, { 100, 100, 100, 1 }, { 0, 100, 100, 1 } }; double[,] result = new double[8, 4]; double[,] t = new double[4, 4] { { 0.707, 0, 0, 0.002828 }, { 0, 1, 0, 0 }, { 0.707, 0, 0, -0.002828 }, { 0, -30, 0, 1 } }; double[,] tochki_shoda = new double[3, 4]; double[,] ishodnie_tochki = new double[3, 4] { { 1, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 1, 0 } }; //умножение куба на матрицу преобразований result = mult(cube, t); //проверка координат последнего столбца на равенство 1 - однородность result = check(result); //точки схода. tochki_shoda = mult(ishodnie_tochki, t); //проверка тчек схода tochki_shoda = check(tochki_shoda); g.TranslateTransform(this.ClientRectangle.Width / 2, this.ClientRectangle.Height / 2); g.DrawLine(pen, new PointF((float)result[0, 0], (float)result[0, 1]), new PointF((float)result[1, 0], (float)result[1, 1]));//ab g.DrawLine(pen, new PointF((float)result[1, 0], (float)result[1, 1]), new PointF((float)result[2, 0], (float)result[2, 1]));//bc g.DrawLine(pen, new PointF((float)result[2, 0], (float)result[2, 1]), new PointF((float)result[3, 0], (float)result[3, 1]));//cd g.DrawLine(pen, new PointF((float)result[3, 0], (float)result[3, 1]), new PointF((float)result[0, 0], (float)result[0, 1]));//da g.DrawLine(pen, new PointF((float)result[0, 0], (float)result[0, 1]), new PointF((float)result[4, 0], (float)result[4, 1]));//ah g.DrawLine(pen, new PointF((float)result[1, 0], (float)result[1, 1]), new PointF((float)result[5, 0], (float)result[5, 1]));//bg g.DrawLine(pen, new PointF((float)result[2, 0], (float)result[2, 1]), new PointF((float)result[6, 0], (float)result[6, 1]));//cf g.DrawLine(pen, new PointF((float)result[3, 0], (float)result[3, 1]), new PointF((float)result[7, 0], (float)result[7, 1]));//de g.DrawLine(pen, new PointF((float)result[7, 0], (float)result[7, 1]), new PointF((float)result[4, 0], (float)result[4, 1]));//eh g.DrawLine(pen, new PointF((float)result[4, 0], (float)result[4, 1]), new PointF((float)result[5, 0], (float)result[5, 1]));//hg g.DrawLine(pen, new PointF((float)result[5, 0], (float)result[5, 1]), new PointF((float)result[6, 0], (float)result[6, 1]));//gf g.DrawLine(pen, new PointF((float)result[6, 0], (float)result[6, 1]), new PointF((float)result[7, 0], (float)result[7, 1]));//fe g.DrawLine(pen1, new PointF((float)result[0, 0], (float)result[0, 1]), new PointF((float)tochki_shoda[0, 0], (float)tochki_shoda[0, 1]));//a - x g.DrawLine(pen1, new PointF((float)result[0, 0], (float)result[0, 1]), new PointF((float)tochki_shoda[2, 0], (float)tochki_shoda[2, 1]));// a -z g.DrawLine(pen1, new PointF((float)result[1, 0], (float)result[1, 1]), new PointF((float)tochki_shoda[0, 0], (float)tochki_shoda[0, 1]));// b -x g.DrawLine(pen1, new PointF((float)result[1, 0], (float)result[1, 1]), new PointF((float)tochki_shoda[2, 0], (float)tochki_shoda[2, 1]));// b -z g.DrawLine(pen1, new PointF((float)result[2, 0], (float)result[2, 1]), new PointF((float)tochki_shoda[0, 0], (float)tochki_shoda[0, 1]));//c - x g.DrawLine(pen1, new PointF((float)result[2, 0], (float)result[2, 1]), new PointF((float)tochki_shoda[2, 0], (float)tochki_shoda[2, 1]));// c -z g.DrawLine(pen1, new PointF((float)result[3, 0], (float)result[3, 1]), new PointF((float)tochki_shoda[0, 0], (float)tochki_shoda[0, 1]));//d - x g.DrawLine(pen1, new PointF((float)result[3, 0], (float)result[3, 1]), new PointF((float)tochki_shoda[2, 0], (float)tochki_shoda[2, 1]));// d -z g.DrawLine(pen1, new PointF((float)result[4, 0], (float)result[4, 1]), new PointF((float)tochki_shoda[0, 0], (float)tochki_shoda[0, 1]));//h - x g.DrawLine(pen1, new PointF((float)result[4, 0], (float)result[4, 1]), new PointF((float)tochki_shoda[2, 0], (float)tochki_shoda[2, 1]));// h -z g.DrawLine(pen1, new PointF((float)result[5, 0], (float)result[5, 1]), new PointF((float)tochki_shoda[0, 0], (float)tochki_shoda[0, 1]));//g - x g.DrawLine(pen1, new PointF((float)result[5, 0], (float)result[5, 1]), new PointF((float)tochki_shoda[2, 0], (float)tochki_shoda[2, 1]));// g -z g.DrawLine(pen1, new PointF((float)result[6, 0], (float)result[6, 1]), new PointF((float)tochki_shoda[0, 0], (float)tochki_shoda[0, 1]));//f - x g.DrawLine(pen1, new PointF((float)result[6, 0], (float)result[6, 1]), new PointF((float)tochki_shoda[2, 0], (float)tochki_shoda[2, 1]));// f -z g.DrawLine(pen1, new PointF((float)result[7, 0], (float)result[7, 1]), new PointF((float)tochki_shoda[0, 0], (float)tochki_shoda[0, 1]));//e - x g.DrawLine(pen1, new PointF((float)result[7, 0], (float)result[7, 1]), new PointF((float)tochki_shoda[2, 0], (float)tochki_shoda[2, 1]));// e -z } } }