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 WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public double[,] mult(double[,] a, double[,] b) { double[,] c = new double[8, 4]; for (int i = 0; i < 8; ++i) { for (int j = 0; j < 4; ++j) { for (int k = 0; k < 4; ++k) { c[i, j] += a[i, k] * b[k, j]; } } } return c; } double[,] cube = { {0.0, 0.0, 0.0, 1.0}, {100.0, 0.0, 0.0, 1.0}, {100.0, 0.0, 100.0, 1.0}, {0.0, 0.0, 100.0, 1.0}, {0.0, 100.0, 0.0, 1.0}, {100.0, 100.0, 0.0, 1.0}, {100.0, 100.0, 100.0, 1.0}, {0.0, 100.0, 100.0, 1.0} }; double[] pt = { 1.0, 1.0, 1.0 }; double n1, n2, n3; double alpha = 0.0; private void Form1_Paint(object sender, PaintEventArgs e) { double[,] rotate = new double[4, 4]; n1 = pt[0] / Math.Sqrt(pt[0] * pt[0] + pt[1] * pt[1] + pt[2] * pt[2]); n2 = pt[1] / Math.Sqrt(pt[0] * pt[0] + pt[1] * pt[1] + pt[2] * pt[2]); n3 = pt[2] / Math.Sqrt(pt[0] * pt[0] + pt[1] * pt[1] + pt[2] * pt[2]); rotate[0, 0] = n1 * n1 + (1.0 - n1 * n1) * Math.Cos(alpha); rotate[1, 0] = n1 * n2 * (1.0 - Math.Cos(alpha)) - n3 * Math.Sin(alpha); rotate[2, 0] = n1 * n3 * (1.0 - Math.Cos(alpha)) + n2 * Math.Sin(alpha); rotate[3, 0] = 0.0; rotate[0, 1] = n1 * n2 * (1.0 - Math.Cos(alpha)) + n3 * Math.Sin(alpha); rotate[1, 1] = n2 * n2 + (1.0 - n2 * n2) * Math.Cos(alpha); rotate[2, 1] = n2 * n3 * (1.0 - Math.Cos(alpha)) - n1 * Math.Sin(alpha); rotate[3, 1] = 0.0; rotate[0, 2] = n1 * n3 * (1.0 - Math.Cos(alpha)) - n2 * Math.Sin(alpha); rotate[1, 2] = n2 * n3 * (1.0 - Math.Cos(alpha)) + n1 * Math.Sin(alpha); rotate[2, 2] = n3 * n3 + (1.0 - n3 * n3) * Math.Cos(alpha); rotate[3, 2] = 0.0; rotate[0, 3] = 0.0; rotate[1, 3] = 0.0; rotate[2, 3] = 0.0; rotate[3, 3] = 1.0; double[,] output = mult(cube, rotate); Graphics g = e.Graphics; g.TranslateTransform(this.ClientRectangle.Width / 2, this.ClientRectangle.Height / 2); g.DrawLine(new Pen(Color.Black), new PointF((float)output[0, 0], (float)output[0, 1]), new PointF((float)output[1, 0], (float)output[1, 1])); g.DrawLine(new Pen(Color.Black), new PointF((float)output[1, 0], (float)output[1, 1]), new PointF((float)output[2, 0], (float)output[2, 1])); g.DrawLine(new Pen(Color.Black), new PointF((float)output[2, 0], (float)output[2, 1]), new PointF((float)output[3, 0], (float)output[3, 1])); g.DrawLine(new Pen(Color.Black), new PointF((float)output[3, 0], (float)output[3, 1]), new PointF((float)output[0, 0], (float)output[0, 1])); g.DrawLine(new Pen(Color.Black), new PointF((float)output[4, 0], (float)output[4, 1]), new PointF((float)output[5, 0], (float)output[5, 1])); g.DrawLine(new Pen(Color.Black), new PointF((float)output[5, 0], (float)output[5, 1]), new PointF((float)output[6, 0], (float)output[6, 1])); g.DrawLine(new Pen(Color.Black), new PointF((float)output[6, 0], (float)output[6, 1]), new PointF((float)output[7, 0], (float)output[7, 1])); g.DrawLine(new Pen(Color.Black), new PointF((float)output[7, 0], (float)output[7, 1]), new PointF((float)output[4, 0], (float)output[4, 1])); g.DrawLine(new Pen(Color.Black), new PointF((float)output[0, 0], (float)output[0, 1]), new PointF((float)output[4, 0], (float)output[4, 1])); g.DrawLine(new Pen(Color.Black), new PointF((float)output[1, 0], (float)output[1, 1]), new PointF((float)output[5, 0], (float)output[5, 1])); g.DrawLine(new Pen(Color.Black), new PointF((float)output[2, 0], (float)output[2, 1]), new PointF((float)output[6, 0], (float)output[6, 1])); g.DrawLine(new Pen(Color.Black), new PointF((float)output[3, 0], (float)output[3, 1]), new PointF((float)output[7, 0], (float)output[7, 1])); } private void timer1_Tick(object sender, EventArgs e) { this.Invalidate(); this.DoubleBuffered = true; alpha += 0.01; } private void Form1_Load(object sender, EventArgs e) { } } }