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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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 Cube
{
public partial class Form1 : Form
{
public double FI = 0;
public Form1()
{
InitializeComponent();
}
static double[,] Multiplication(double[,] a, double[,] b)
{
if (a.GetLength(1) != b.GetLength(0)) throw new Exception("Матрицы нельзя перемножить");
double[,] r = 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++)
{
for (int k = 0; k < b.GetLength(0); k++)
{
r[i, j] += a[i, k] * b[k, j];
}
}
}
return r;
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
double n1, n2, n3;
n1 = n2 = n3 = 1 / Math.Sqrt(3);
double[,] x = new double[,] {
{0, 0, 100, 1},
{100,0,100,1},
{100,100,100,1},
{0,100,100,1},
{0,0,0,1},
{100,0,0,1},
{100,100,0,1},
{0,100,0,1}};
double[,] matriz = new double[,] {
{n1*n1+(1-n1*n1)*Math.Cos(FI),n1*n2*(1-Math.Cos(FI))+n3*Math.Sin(FI),n1*n3*(1-Math.Cos(FI))-n2*Math.Sin(FI),0},
{n1*n2*(1-Math.Cos(FI))-n3*Math.Sin(FI),n2*n2+(1-n2*n2)*Math.Cos(FI),n3*n2*(1-Math.Cos(FI))+n1*Math.Sin(FI),0},
{n1*n3*(1-Math.Cos(FI))+n2*Math.Sin(FI),n3*n2*(1-Math.Cos(FI))-n1*Math.Sin(FI),n3*n3+(1-n3*n3)*Math.Cos(FI),0},
{0,0,0,1}};
Graphics g = e.Graphics;
g.TranslateTransform(Width / 3, Height / 3);
Pen pen = new Pen(Color.Red);
x = Multiplication(x, matriz);
PointF[] pt = new PointF[] {
new PointF((float)x[0, 0], (float)x[0, 1]),
new PointF((float)x[1, 0], (float)x[1, 1]),
new PointF((float)x[2, 0], (float)x[2, 1]),
new PointF((float)x[3, 0], (float)x[3, 1]),
new PointF((float)x[4, 0], (float)x[4, 1]),
new PointF((float)x[5, 0], (float)x[5, 1]),
new PointF((float)x[6, 0], (float)x[6, 1]),
new PointF((float)x[7, 0], (float)x[7, 1])
};
g.DrawLine(pen, pt[0], pt[1]);
g.DrawLine(pen, pt[1], pt[2]);
g.DrawLine(pen, pt[2], pt[3]);
g.DrawLine(pen, pt[3], pt[0]);
g.DrawLine(pen, pt[6], pt[7]);
g.DrawLine(pen, pt[0], pt[4]);
g.DrawLine(pen, pt[1], pt[5]);
g.DrawLine(pen, pt[4], pt[5]);
g.DrawLine(pen, pt[4], pt[7]);
g.DrawLine(pen, pt[3], pt[7]);
g.DrawLine(pen, pt[2], pt[6]);
g.DrawLine(pen, pt[6], pt[2]);
g.DrawLine(pen, pt[5], pt[6]);
}
private void timer1_Tick(object sender, EventArgs e)
{
this.Invalidate();
this.DoubleBuffered = true;
FI += 0.01;
}
}
}