Beispiel #1
0
        public static Tetraeder Isometric(Tetraeder Tetr)
        {
            Tetraeder temp = new Tetraeder(Tetr);

            temp = AngleY(temp, (float)120 * 180 / (float)Math.PI);
            temp = AngleX(temp, (float)135 * 180 / (float)Math.PI);
            return(temp);
        }
Beispiel #2
0
        private void panel1_Paint(object sender, PaintEventArgs e)
        {
            Graphics graphics = panel1.CreateGraphics();
            Pen      pen      = new Pen(Color.Black, 2);
            Point3D  mover    = new Point3D(panel1.Width / 2, panel1.Height / 2, 0);

            graphics.Clear(Color.White);

            #region OXYZ
            pen.Color = Color.DarkOrange;
            graphics.DrawLine(pen, (PointF)MatrixManager.Isometric(new Point3D(1000, 0, 0), mover), (PointF)MatrixManager.Isometric(new Point3D(0, 0, 0), mover));
            graphics.DrawLine(pen, (PointF)MatrixManager.Isometric(new Point3D(-1000, 0, 0), mover), (PointF)MatrixManager.Isometric(new Point3D(0, 0, 0), mover));

            pen.Color = Color.Brown;
            graphics.DrawLine(pen, (PointF)MatrixManager.Isometric(new Point3D(0, 1000, 0), mover), (PointF)MatrixManager.Isometric(new Point3D(0, 0, 0), mover));
            graphics.DrawLine(pen, (PointF)MatrixManager.Isometric(new Point3D(0, -1000, 0), mover), (PointF)MatrixManager.Isometric(new Point3D(0, 0, 0), mover));

            pen.Color = Color.DeepPink;
            graphics.DrawLine(pen, (PointF)MatrixManager.Isometric(new Point3D(0, 0, 1000), mover), (PointF)MatrixManager.Isometric(new Point3D(0, 0, 0), mover));
            graphics.DrawLine(pen, (PointF)MatrixManager.Isometric(new Point3D(0, 0, -1000), mover), (PointF)MatrixManager.Isometric(new Point3D(0, 0, 0), mover));
            #endregion

            #region Line
            pen.DashStyle = DashStyle.Dot;
            pen.Color     = Color.Black;
            //////////////
            if (!A.Equals(B))
            {
                Point3D tempA = new Point3D(A);
                Point3D tempB = new Point3D(B);


                while (Math.Abs(tempA.X) < 1000 && Math.Abs(tempA.Y) < 1000 && Math.Abs(tempA.Z) < 1000)
                {
                    tempA = MatrixManager.MoveOnVector(tempA, B.X - A.X, B.Y - A.Y, B.Z - A.Z);
                }

                while (Math.Abs(tempB.X) < 1000 && Math.Abs(tempB.Y) < 1000 && Math.Abs(tempB.Z) < 1000)
                {
                    tempB = MatrixManager.MoveOnVector(tempB, -(B.X - A.X), -(B.Y - A.Y), -(B.Z - A.Z));
                }

                graphics.DrawLine(pen, (PointF)MatrixManager.Isometric(tempA, mover), (PointF)MatrixManager.Isometric(tempB, mover));
            }
            /////////////
            pen.DashStyle = DashStyle.Solid;
            #endregion

            if (isCube)
            {
                Cube.Draw(cube, graphics, pen, mover);
            }
            else
            {
                Tetraeder.Draw(tet, graphics, pen, mover);
            }
        }
Beispiel #3
0
 public Tetraeder(Tetraeder t)
 {
     arrP = new Point3D[4];
     for (int i = 0; i < this.arrP.Length; i++)
     {
         this.arrP[i] = t.arrP[i];
     }
     this.Size = t.Size;
 }
Beispiel #4
0
        public static Tetraeder MoveOnVector(Tetraeder Tetr, float a, float b, float c)
        {
            Tetraeder temp = new Tetraeder(Tetr);

            for (int i = 0; i < Tetr.arrP.Length; i++)
            {
                temp.arrP[i] = MatrixManager.MoveOnVector(temp.arrP[i], a, b, c);
            }
            return(temp);
        }
Beispiel #5
0
        public static Tetraeder AngleZ(Tetraeder Tetr, float angle)
        {
            Tetraeder temp = new Tetraeder(Tetr);

            for (int i = 0; i < Tetr.arrP.Length; i++)
            {
                temp.arrP[i] = MatrixManager.OnAngleZ(temp.arrP[i], angle);
            }
            return(temp);
        }
Beispiel #6
0
        private void button1_Click(object sender, EventArgs e)
        {
            A = (Point3D)textBox3.Text;
            B = (Point3D)textBox4.Text;

            if (isCube)
            {
                cube = new Cube((Point3D)textBox1.Text, Convert.ToDouble(textBox2.Text));
            }
            else
            {
                tet = new Tetraeder((Point3D)textBox1.Text, Convert.ToDouble(textBox2.Text));
            }

            panel1_Paint(sender, new PaintEventArgs(CreateGraphics(), panel1.ClientRectangle));
        }
Beispiel #7
0
        public Form1()
        {
            InitializeComponent();

            A    = new Point3D(0, 0, 0);
            B    = new Point3D(100, 100, 100);
            cube = new Cube(new Point3D(100, 100, 100), 100);
            tet  = new Tetraeder(new Point3D(100, 100, 100), 100);

            comboBox1.Items.AddRange(new[] { "Cube", "Tetraeder" });
            comboBox1.SelectedIndex = 0;

            textBox1.Text = cube.ArrF[0].ToString();
            textBox2.Text = cube.Size.ToString();

            //textBox1.Text = tet.arrP[0].ToString();
            //textBox2.Text = cube.Size.ToString();

            textBox3.Text = A.ToString();
            textBox4.Text = B.ToString();
            textBox5.Text = trackBar1.Value.ToString();
        }
Beispiel #8
0
        public static void Draw(Tetraeder Tetr, Graphics g, Pen pen, Point3D vector = null)
        {
            Tetraeder temp = new Tetraeder(Tetr);

            temp = Isometric(temp);
            if (vector != null)
            {
                temp = Tetraeder.MoveOnVector(temp, vector.X, vector.Y, vector.Z);
            }

            pen.Color = Color.Red;
            g.DrawLine(pen, (PointF)temp.arrP[0], (PointF)temp.arrP[1]);
            g.DrawLine(pen, (PointF)temp.arrP[1], (PointF)temp.arrP[3]);
            g.DrawLine(pen, (PointF)temp.arrP[0], (PointF)temp.arrP[3]);

            pen.Color = Color.Blue;
            g.DrawLine(pen, (PointF)temp.arrP[0], (PointF)temp.arrP[2]);
            g.DrawLine(pen, (PointF)temp.arrP[1], (PointF)temp.arrP[2]);

            pen.Color = Color.Green;
            g.DrawLine(pen, (PointF)temp.arrP[2], (PointF)temp.arrP[3]);
        }
Beispiel #9
0
        private void Rotate(object sender, EventArgs e, int value)
        {
            Point3D   tempA    = new Point3D(A);
            Point3D   tempB    = new Point3D(B);
            Point3D   toStart  = MatrixManager.PointsToStart(A, B);
            Cube      tempCube = new Cube(cube);
            Tetraeder tempTet  = new Tetraeder(tet);

            if (!toStart.Equals(new Point3D(0, 0, 0)))
            {
                tempA = MatrixManager.MoveOnVector(tempA, toStart.X, toStart.Y, toStart.Z);
                tempB = MatrixManager.MoveOnVector(tempB, toStart.X, toStart.Y, toStart.Z);

                if (isCube)
                {
                    tempCube = Cube.MoveOnVector(tempCube, toStart.X, toStart.Y, toStart.Z);
                }
                else
                {
                    tempTet = Tetraeder.MoveOnVector(tempTet, toStart.X, toStart.Y, toStart.Z);
                }
            }
            else
            {
                tempA = toStart;
            }

            //At this moment tempA is on 0,0,0
            //B can be anywere
            //XY->angle to Z
            //XZ->angle to Y
            //YZ->angle to X

            if (tempB.X == 0 && tempB.Z == 0)
            {
                //Line is OY
                if (isCube)
                {
                    tempCube = Cube.AngleY(tempCube, value);
                }
                else
                {
                    tempTet = Tetraeder.AngleY(tempTet, value);
                }
            }
            else if (tempB.Y == 0 && tempB.Z == 0)
            {
                //Line is OX
                if (isCube)
                {
                    tempCube = Cube.AngleX(tempCube, value);
                }
                else
                {
                    tempTet = Tetraeder.AngleX(tempTet, value);
                }
            }
            else if (tempB.X == 0 && tempB.Y == 0)
            {
                //Line is OZ
                if (isCube)
                {
                    tempCube = Cube.AngleZ(tempCube, value);
                }
                else
                {
                    tempTet = Tetraeder.AngleZ(tempTet, value);
                }
            }
            else if (tempB.X != 0 && tempB.Y != 0 && tempB.Z != 0)
            {
                float angleX = (float)Math.Atan2(tempB.Y, tempB.Z) * 180 / (float)Math.PI;

                tempB = MatrixManager.OnAngleX(tempB, angleX);

                float angleY = (float)Math.Atan2(tempB.Z, tempB.X) * 180 / (float)Math.PI;

                if (isCube)
                {
                    tempCube = Cube.AngleX(tempCube, angleX);
                    tempCube = Cube.AngleY(tempCube, angleY);

                    tempCube = Cube.AngleX(tempCube, value);

                    tempCube = Cube.AngleY(tempCube, -angleY);
                    tempCube = Cube.AngleX(tempCube, -angleX);
                }
                else
                {
                    tempTet = Tetraeder.AngleX(tempTet, angleX);
                    tempTet = Tetraeder.AngleY(tempTet, angleY);

                    tempTet = Tetraeder.AngleX(tempTet, value);

                    tempTet = Tetraeder.AngleY(tempTet, -angleY);
                    tempTet = Tetraeder.AngleX(tempTet, -angleX);
                }
            }
            else if (tempB.X == 0)
            {
                float angleX = (float)Math.Atan2(tempB.Y, tempB.Z) * 180 / (float)Math.PI;
                if (isCube)
                {
                    tempCube = Cube.AngleX(tempCube, angleX);

                    tempCube = Cube.AngleZ(tempCube, value);

                    tempCube = Cube.AngleX(tempCube, -angleX);
                }
                else
                {
                    tempTet = Tetraeder.AngleX(tempTet, angleX);

                    tempTet = Tetraeder.AngleZ(tempTet, value);

                    tempTet = Tetraeder.AngleX(tempTet, -angleX);
                }
            }
            else if (tempB.Y == 0)
            {
                float angleY = (float)Math.Atan2(tempB.Z, tempB.X) * 180 / (float)Math.PI;

                if (isCube)
                {
                    tempCube = Cube.AngleY(tempCube, angleY);

                    tempCube = Cube.AngleZ(tempCube, value);

                    tempCube = Cube.AngleY(tempCube, -angleY);
                }
                else
                {
                    tempTet = Tetraeder.AngleY(tempTet, angleY);

                    tempTet = Tetraeder.AngleZ(tempTet, value);

                    tempTet = Tetraeder.AngleY(tempTet, -angleY);
                }
            }
            else if (tempB.Z == 0)
            {
                float angleZ = (float)Math.Atan2(tempB.Y, tempB.X) * 180 / (float)Math.PI;
                if (isCube)
                {
                    tempCube = Cube.AngleZ(tempCube, angleZ);

                    tempCube = Cube.AngleY(tempCube, value);

                    tempCube = Cube.AngleZ(tempCube, -angleZ);
                }
                else
                {
                    tempTet = Tetraeder.AngleZ(tempTet, angleZ);

                    tempTet = Tetraeder.AngleY(tempTet, value);

                    tempTet = Tetraeder.AngleZ(tempTet, -angleZ);
                }
            }

            if (isCube)
            {
                cube = Cube.MoveOnVector(tempCube, -toStart.X, -toStart.Y, -toStart.Z);
            }
            else
            {
                tet = Tetraeder.MoveOnVector(tempTet, -toStart.X, -toStart.Y, -toStart.Z);
            }
            panel1_Paint(sender, new PaintEventArgs(CreateGraphics(), panel1.DisplayRectangle));
        }