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
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace lab1
{
public partial class Form1 : Form
{
int[] points = new int[] {0,1,1,2,2,3,3,0,4,4,6,6,3,2,2,7,7,6,6,7,7,5,5,1,1,0,0,4,4,5 };
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
double x = 1;
double y = 1;
double z = 1;
double len = Math.Sqrt(x * x + y * y + z * z);
x /= len;
y /= len;
z /= len;
double[,] rotationMatrix = new double[4, 4];
double cos = Math.Cos(0.8);
double sin = Math.Sin(0.8);
rotationMatrix[0, 0] = cos + (1 - cos) * x * x;
rotationMatrix[0, 1] = (1 - cos) * x * y - sin * z;
rotationMatrix[0, 2] = (1 - cos) * x * z + sin * y;
rotationMatrix[0, 3] = 0;
rotationMatrix[1, 0] = (1 - cos) * y * x + sin * z;
rotationMatrix[1, 1] = cos + (1 - cos) * y * y;
rotationMatrix[1, 2] = (1 - cos) * y * z - sin * x;
rotationMatrix[1, 3] = 0;
rotationMatrix[2, 0] = (1 - cos) * z * x - sin * y;
rotationMatrix[2, 1] = (1 - cos) * z * y + sin * x;
rotationMatrix[2, 2] = cos + (1 - cos) * z * z;
rotationMatrix[2, 3] = 0;
rotationMatrix[3, 0] = 0;
rotationMatrix[3, 1] = 0;
rotationMatrix[3, 2] = 0;
rotationMatrix[3, 3] = 1;
double[,] cube = new double[8, 4];
cube[0, 0] = 0;
cube[0, 1] = 0;
cube[0, 2] = 0;
cube[0, 3] = 1;
cube[1, 0] = 100;
cube[1, 1] = 0;
cube[1, 2] = 0;
cube[1, 3] = 1;
cube[2, 0] = 100;
cube[2, 1] = 100;
cube[2, 2] = 0;
cube[2, 3] = 1;
cube[3, 0] = 0;
cube[3, 1] = 100;
cube[3, 2] = 0;
cube[3, 3] = 1;
cube[4, 0] = 0;
cube[4, 1] = 0;
cube[4, 2] = 100;
cube[4, 3] = 1;
cube[5, 0] = 100;
cube[5, 1] = 0;
cube[5, 2] = 100;
cube[5, 3] = 1;
cube[6, 0] = 100;
cube[6, 1] = 100;
cube[6, 2] = 100;
cube[6, 3] = 1;
cube[7, 0] = 0;
cube[7, 1] = 100;
cube[7, 2] = 100;
cube[7, 3] = 1;
double[,] resultCube = new double[8, 4];
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 4; j++)
{
resultCube[i, j] = cube[i, j] * rotationMatrix[j, 0] +
cube[i, j] * rotationMatrix[j, 1] +
cube[i, j] * rotationMatrix[j, 2] +
cube[i, j] * rotationMatrix[j, 3];
}
}
Graphics test = e.Graphics;
Pen pen = new Pen(Color.Black);
for (int i = 0; i < 4; i = i + 1)
{
test.DrawLine(pen, new PointF((float)resultCube[points[i], 0]/(float)resultCube[points[i],3], (float)resultCube[points[i], 1]/(float)resultCube[points[i],3]),
new PointF((float)resultCube[points[i + 1], 0] / (float)resultCube[points[i + 1], 3], (float)resultCube[points[i + 1], 1] / (float)resultCube[points[i+1], 3]));
}
}
}
}