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
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 WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
double[,] Cube = 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 corn = 0;
void Point(double[,] m)
{
Bitmap feel = new Bitmap(1000, 1000);
Graphics G = Graphics.FromImage(feel);
G.TranslateTransform(200, 150);
G.Clear(Color.Aqua);
PointF p0 = new PointF((float)m[0, 0], (float)m[0, 1]);
PointF p1 = new PointF((float)m[1, 0], (float)m[1, 1]);
PointF p2 = new PointF((float)m[2, 0], (float)m[2, 1]);
PointF p3 = new PointF((float)m[3, 0], (float)m[3, 1]);
PointF p4 = new PointF((float)m[4, 0], (float)m[4, 1]);
PointF p5 = new PointF((float)m[5, 0], (float)m[5, 1]);
PointF p6 = new PointF((float)m[6, 0], (float)m[6, 1]);
PointF p7 = new PointF((float)m[7, 0], (float)m[7, 1]);
Pen pen = new Pen(Color.Maroon);
G.DrawPolygon(pen, new PointF[] { p0, p3, p7, p4 });
G.DrawPolygon(pen, new PointF[] { p1, p2, p6, p5 });
G.DrawPolygon(pen, new PointF[] { p0, p3, p2, p1 });
G.DrawPolygon(pen, new PointF[] { p4, p7, p6, p5 });
G.DrawPolygon(pen, new PointF[] { p0, p1, p5, p4 });
G.DrawPolygon(pen, new PointF[] { p3, p2, p6, p7 });
pictureBox1.Image = feel;
}
double[,] NMatrix(double[,] m1, double[,] m2)
{
double[,] NewM = new double[m1.GetLength(0), m2.GetLength(1)];
for (int i = 0; i < m1.GetLength(0); i++)
{
for (int j = 0; j < m2.GetLength(1); j++)
{
for (int k = 0; k < m1.GetLength(1); k++)
{
NewM[i, j] = NewM[i, j] + m1[i, k] * m2[k, j];
}
}
}
return NewM;
}
double[,] move(double[,] m, double corner, double[] a)
{
double vect = Math.Sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]);
double x = a[0] / vect;
double y = a[1] / vect;
double z = a[2] / vect;
double[,] M = new double[4, 4]{
{Math.Cos(corner) + (1 - Math.Cos(corner))*x*x, (1 - Math.Cos(corner))*x*y - z*Math.Sin(corner), (1 - Math.Cos(corner))*x*z + Math.Sin(corner)*y, 0},
{(1 - Math.Cos(corner))*y*x + z*Math.Sin(corner), Math.Cos(corner) + (1 - Math.Sin(corner))*y*y, (1 - Math.Cos(corner))*y*z - x*Math.Sin(corner), 0},
{(1 - Math.Cos(corner))*z*x - y*Math.Sin(corner), (1 - Math.Cos(corner))*z*y + x*Math.Sin(corner), Math.Cos(corner) + (1 - Math.Cos(corner))*z*z, 0},
{0, 0, 0, 1}};
return NMatrix(m, M);
}
private void Form1_Load(object sender, EventArgs e)
{
Cube = move(Cube, 60, new double[] { 1, 1, 1 });
Point(Cube);
}
private void timer1_Tick(object sender, EventArgs e)
{
corn += 10;
corn /= 360;
Cube = move(Cube, corn, new double[] { 1, 1, 1 });
Point(Cube);
}
}
}