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.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
double[,] matrix = new double[8, 4] { { 0, 100, 0, 1 }, { 0, 0, 0, 1 }, { 100, 0, 0, 1 }, { 100, 100, 0, 1 }, { 0, 100, 100, 1 }, { 0, 0, 100, 1 }, { 100, 0, 100, 1 }, { 100, 100, 100, 1 } };
double yg = 0;
private void Form1_Load(object sender, EventArgs e)
{
matrix = move(matrix, 60, new double[] { 1, 1, 1 });
cube(matrix);
}
void cube(double[,] mat)
{
Bitmap a = new Bitmap(500, 500);//поверхность
Graphics g = Graphics.FromImage(a);// в ней находится функция, которая рисует
g.TranslateTransform(250, 250);//переставляем начало координат
g.Clear(Color.Brown);
PointF p0 = new PointF((float)mat[0, 0], (float)mat[0, 1]);
PointF p1 = new PointF((float)mat[1, 0], (float)mat[1, 1]);
PointF p2 = new PointF((float)mat[2, 0], (float)mat[2, 1]);
PointF p3 = new PointF((float)mat[3, 0], (float)mat[3, 1]);
PointF p4 = new PointF((float)mat[4, 0], (float)mat[4, 1]);
PointF p5 = new PointF((float)mat[5, 0], (float)mat[5, 1]);
PointF p6 = new PointF((float)mat[6, 0], (float)mat[6, 1]);
PointF p7 = new PointF((float)mat[7, 0], (float)mat[7, 1]);
Pen k = new Pen(Color.LightCoral);
g.DrawPolygon(k, new PointF[] { p0, p1, p2, p3 });//выбираем квардраты
g.DrawPolygon(k, new PointF[] { p4, p5, p6, p7 });
g.DrawPolygon(k, new PointF[] { p0, p4, p5, p1 });
g.DrawPolygon(k, new PointF[] { p3, p7, p6, p2 });
g.DrawPolygon(k, new PointF[] { p1, p5, p6, p2 });
g.DrawPolygon(k, new PointF[] { p0, p4, p7, p3 });
pictureBox1.Image = a;//выставляем набор точек с рисунком
}
double[,] mult(double[,] mat1, double[,] mat2)
{
double[,] matrix = new double[mat1.GetLength(0), mat2.GetLength(1)];
for (int i = 0; i <= mat1.GetLength(0) - 1; i++)
{
for (int j = 0; j <= mat2.GetLength(1) - 1; j++)
{
double a = 0;
for (int k = 0; k <= mat2.GetLength(0) - 1; k++)
{
a = mat1[i, k] * mat2[k, j] + a;
}
matrix[i, j] = a;
}
}
return matrix;
}
double[,] move(double[,] k, double b, double[] vector)//b-угол
{
double Lenght = Math.Sqrt(vector[0] * vector[0] + vector[1] * vector[1] + vector[2] * vector[2]);//длина вектора
double x = vector[0] / Lenght;//нормированные векторы
double y = vector[1] / Lenght;
double z = vector[2] / Lenght;
double cos = Math.Cos(b);
double sin = Math.Sin(b);
double[,] Matrix1 = new double[4, 4]
{
{(cos+(1-cos)*x*x),((1-cos)*x*y-(sin)*z),((1-cos)*x*z+sin*y),0},
{((1-cos)*y*x+sin*z),(cos+(1-cos)*y*y),((1-cos)*y*z-sin*x),0},
{((1-cos)*z*x-sin*y),((1-cos)*z*y+sin*x),(cos+(1-cos)*z*z),0},
{0,0,0,1}
};
return mult(k, Matrix1);
}
private void timer1_Tick(object sender, EventArgs e)
{
yg += 10;//то же самое, что и yg=yg+10
yg /= 360;
matrix = move(matrix, yg, new double[] { 1, 1, 1 });
cube(matrix);
}
}
}