Ejemplo n.º 1
0
        private void createHexahedron_Click(object sender, EventArgs e)
        {
            int edgeLength = 100;

            Polyhedron hexahedrone = Polyhedrons.getHexahedron();

            currentPolyhedron = AffineTransform.getMoved(hexahedrone, 0, 0, -edgeLength / 2);
            foreach (var control in groupBox2.Controls)
            {
                (control as RadioButton).Checked = false;
            }
            drawFigure();
        }
Ejemplo n.º 2
0
        // применяет к многограннику матричное преобразование
        static public Polyhedron ChangePolyhedronByMatrix(Polyhedron polyhedron, Matrix matrix)
        {
            List <Point3D> newPoints = polyhedron.Vertices.Select(point => (Matrix.getMatrixFromPoint(point) * matrix).ToPoint()).ToList();
            Polyhedron     res       = new Polyhedron(newPoints);

            foreach (var edge in polyhedron.Edges)
            {
                int p1Index = polyhedron.Vertices.FindIndex(point => point == edge.From);
                int p2Index = polyhedron.Vertices.FindIndex(point => point == edge.To);
                res.AddEdge(newPoints[p1Index], newPoints[p2Index]);
            }
            return(res);
        }
Ejemplo n.º 3
0
        private void createTetrahedron_Click(object sender, EventArgs e)
        {
            double x = 200, y = 150, z = 0;
            int    r  = 150;
            double bz = z - r * Math.Sqrt(6) / 3.0;

            Polyhedron tetrahedron = Polyhedrons.getTetrahedron();

            currentPolyhedron = AffineTransform.getMoved(tetrahedron, 0, 0, (int)-bz / 2);
            foreach (var control in groupBox2.Controls)
            {
                (control as RadioButton).Checked = false;
            }
            drawFigure();
        }
Ejemplo n.º 4
0
        public void Tetrahedron(Polyhedron cube = null)
        {
            if (cube == null)
            {
                cube = new Polyhedron();
                cube.Hexahedron();
            }
            Polygon f0 = new Polygon(
                new List <Point3D>
            {
                new Point3D(cube.Polygons[0].Points[0]),
                new Point3D(cube.Polygons[1].Points[1]),
                new Point3D(cube.Polygons[1].Points[3])
            }
                );

            Polygon f1 = new Polygon(
                new List <Point3D>
            {
                new Point3D(cube.Polygons[1].Points[3]),
                new Point3D(cube.Polygons[1].Points[1]),
                new Point3D(cube.Polygons[0].Points[2])
            }
                );

            Polygon f2 = new Polygon(
                new List <Point3D>
            {
                new Point3D(cube.Polygons[0].Points[2]),
                new Point3D(cube.Polygons[1].Points[1]),
                new Point3D(cube.Polygons[0].Points[0])
            }
                );

            Polygon f3 = new Polygon(
                new List <Point3D>
            {
                new Point3D(cube.Polygons[0].Points[2]),
                new Point3D(cube.Polygons[0].Points[0]),
                new Point3D(cube.Polygons[1].Points[3])
            }
                );

            Polygons = new List <Polygon> {
                f0, f1, f2, f3
            };
            UpdateCenter();
        }
Ejemplo n.º 5
0
        public static Polyhedron getRotationFigure(List <Point3D> startPoints, Line3D axis, int count)
        {
            float angle = 360f / count;

            int rings = startPoints.Count;

            List <Point3D> points = new List <Point3D>();

            for (int i = 0; i < count; ++i)
            {
                for (int j = 0; j < rings; ++j)
                {
                    points.Add(AffineTransform.getRotatedAroundLine(startPoints[j], axis, i * angle));
                }
            }

            Polyhedron rf = new Polyhedron(points);


            rf.AddEdges(points[0], new List <Point3D> {
                points[(count - 1) * rings]
            });

            for (int j = 1; j < rings; ++j)
            {
                rf.AddEdges(points[j], new List <Point3D> {
                    points[j - 1], points[(count - 1) * rings + j]
                });
            }

            for (int i = 1; i < count; ++i)
            {
                rf.AddEdges(points[i * rings], new List <Point3D> {
                    points[(i - 1) * rings]
                });

                for (int j = 1; j < rings; ++j)
                {
                    rf.AddEdges(points[i * rings + j], new List <Point3D> {
                        points[i * rings + j - 1], points[(i - 1) * rings + j]
                    });
                }
            }

            return(rf);
        }
Ejemplo n.º 6
0
        // получить сдвинутый многогранник относительно начала координат
        static public Polyhedron getMoved(Polyhedron polyhedron, int dx, int dy, int dz)
        {
            Matrix moveMatrix = new Matrix(
                new double[4] {
                1, 0, 0, 0
            },
                new double[4] {
                0, 1, 0, 0
            },
                new double[4] {
                0, 0, 1, 0
            },
                new double[4] {
                dx, dy, dz, 1
            }
                );

            return(TransformHelper.ChangePolyhedronByMatrix(polyhedron, moveMatrix));
        }
Ejemplo n.º 7
0
        // получить масштабированный многогранник относительно начала координат
        static public Polyhedron getScaled(Polyhedron polyhedron, double dx, double dy, double dz)
        {
            Matrix scaleMatrix = new Matrix(
                new double[4] {
                dx, 0, 0, 0
            },
                new double[4] {
                0, dy, 0, 0
            },
                new double[4] {
                0, 0, dz, 0
            },
                new double[4] {
                0, 0, 0, 1
            }
                );

            return(TransformHelper.ChangePolyhedronByMatrix(polyhedron, scaleMatrix));
        }
Ejemplo n.º 8
0
        private void loadButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.CheckFileExists  = true;
            dialog.CheckPathExists  = true;
            dialog.Filter           = "Текстовый файл|*.txt";
            dialog.DefaultExt       = "txt";
            dialog.InitialDirectory = Directory.GetCurrentDirectory().Replace("bin\\Debug", "");
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                string     fname      = dialog.FileName;
                Polyhedron polyhedron = new Polyhedron();
                try //обратотка возможных ошибок
                {
                    foreach (var line in File.ReadAllLines(fname))
                    {
                        if (line.Split(' ').Length == 3) //это точка
                        {
                            var coords = line.Split(' ').Select(s => double.Parse(s)).ToArray();
                            polyhedron.AddVertex(coords[0], coords[1], coords[2]);
                        }
                        else //это ребро
                        {
                            var vertexNumbers = line.Split(' ').Select(s => int.Parse(s)).ToArray();
                            polyhedron.AddEdge(polyhedron.Vertices[vertexNumbers[0]], polyhedron.Vertices[vertexNumbers[1]]);
                        }
                    }
                    currentPolyhedron = polyhedron;
                    drawFigure();
                    MessageBox.Show("Файл загружен!", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch
                {
                    MessageBox.Show("Ошибка чтения файла!", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 9
0
        public static Polyhedron getTetrahedron()
        {
            double         x = 200, y = 150, z = 0;
            int            r      = 150;
            double         bz     = z - r * Math.Sqrt(6) / 3.0;
            List <Point3D> points = new List <Point3D>
            {
                new Point3D(x, y, z),
                new Point3D(x - r * Math.Sqrt(3) / 6.0, y - r / 2.0, bz),
                new Point3D(x - r * Math.Sqrt(3) / 6.0, y + r / 2.0, bz),
                new Point3D(x + r * Math.Sqrt(3) / 3.0, y, bz),
            };
            Polyhedron tetrahedron = new Polyhedron(points);

            tetrahedron.AddEdges(points[0], new List <Point3D> {
                points[1], points[2], points[3]
            });
            tetrahedron.AddEdges(points[1], new List <Point3D> {
                points[2], points[3]
            });
            tetrahedron.AddEdge(points[2], points[3]);

            return(tetrahedron);
        }
Ejemplo n.º 10
0
        public List <Line> Display(Polyhedron polyhedron, int proc)
        {
            Matrix dM = new Matrix(4, 4);

            switch (proc)
            {
            case 0:
                dM = isometric_projection;
                break;

            case 1:
                dM = orthographic_projection_X;
                break;

            case 2:
                dM = orthographic_projection_Y;
                break;

            case 3:
                dM = orthographic_projection_Z;
                break;

            case 4:
                dM = perspective_projection;
                break;

            default:
                break;
            }
            List <Line>   edges      = new List <Line>();
            List <PointD> vertices2D = new List <PointD>();

            foreach (var p in polyhedron.Vertices)
            {
                //var temp = Matrix.getMatrixFromPoint(p) * dM;
                var temp = Matrix.kostylify(Matrix.getMatrixFromPoint(p)) * dM;

                var temp2d = new PointD(temp[0, 0] / temp[0, 3], temp[0, 1] / temp[0, 3]);
                if (dM == orthographic_projection_X)
                {
                    temp2d = new PointD(temp[0, 1] / temp[0, 3], temp[0, 2] / temp[0, 3]);
                }
                else if (dM == orthographic_projection_Y)
                {
                    temp2d = new PointD(temp[0, 0] / temp[0, 3], temp[0, 2] / temp[0, 3]);
                }
                vertices2D.Add(temp2d);
                foreach (var t in polyhedron.AdjacencyMatrix[p])
                {
                    //var t1 = Matrix.getMatrixFromPoint(t) * dM;

                    var t1 = Matrix.kostylify(Matrix.getMatrixFromPoint(t)) * dM;

                    if (dM == isometric_projection || dM == perspective_projection || dM == orthographic_projection_Z)
                    {
                        vertices2D.Add(new PointD(t1[0, 0] / t1[0, 3], t1[0, 1] / t1[0, 3]));
                    }
                    else if (dM == orthographic_projection_X)
                    {
                        vertices2D.Add(new PointD(t1[0, 1] / t1[0, 3], t1[0, 2] / t1[0, 3]));
                    }
                    else
                    {
                        vertices2D.Add(new PointD(t1[0, 0] / t1[0, 3], t1[0, 2] / t1[0, 3]));
                    }
                    edges.Add(new Line(temp2d, vertices2D.Last()));
                }
            }

            return(edges);
        }
Ejemplo n.º 11
0
        public void Dodecahedron()
        {
            Polygons = new List <Polygon>();
            Polyhedron ik = new Polyhedron();

            ik.Icosahedron();

            List <Point3D> pts = new List <Point3D>();

            foreach (Polygon f in ik.Polygons)
            {
                pts.Add(f.Center);
            }

            Polygons.Add(new Polygon(new List <Point3D>
            {
                new Point3D(pts[0]),
                new Point3D(pts[1]),
                new Point3D(pts[2]),
                new Point3D(pts[3]),
                new Point3D(pts[4])
            }));

            Polygons.Add(new Polygon(new List <Point3D>
            {
                new Point3D(pts[5]),
                new Point3D(pts[6]),
                new Point3D(pts[7]),
                new Point3D(pts[8]),
                new Point3D(pts[9])
            }));

            for (int i = 0; i < 5; ++i)
            {
                Polygons.Add(new Polygon(new List <Point3D>
                {
                    new Point3D(pts[i]),
                    new Point3D(pts[(i + 1) % 5]),
                    new Point3D(pts[(i == 4) ? 10 : 2 * i + 12]),
                    new Point3D(pts[(i == 4) ? 11 : 2 * i + 13]),
                    new Point3D(pts[2 * i + 10])
                }));
            }

            Polygons.Add(new Polygon(new List <Point3D>
            {
                new Point3D(pts[5]),
                new Point3D(pts[6]),
                new Point3D(pts[13]),
                new Point3D(pts[10]),
                new Point3D(pts[11])
            }));
            Polygons.Add(new Polygon(new List <Point3D>
            {
                new Point3D(pts[6]),
                new Point3D(pts[7]),
                new Point3D(pts[15]),
                new Point3D(pts[12]),
                new Point3D(pts[13])
            }));
            Polygons.Add(new Polygon(new List <Point3D>
            {
                new Point3D(pts[7]),
                new Point3D(pts[8]),
                new Point3D(pts[17]),
                new Point3D(pts[14]),
                new Point3D(pts[15])
            }));
            Polygons.Add(new Polygon(new List <Point3D>
            {
                new Point3D(pts[8]),
                new Point3D(pts[9]),
                new Point3D(pts[19]),
                new Point3D(pts[16]),
                new Point3D(pts[17])
            }));
            Polygons.Add(new Polygon(new List <Point3D>
            {
                new Point3D(pts[9]),
                new Point3D(pts[5]),
                new Point3D(pts[11]),
                new Point3D(pts[18]),
                new Point3D(pts[19])
            }));

            UpdateCenter();
        }
Ejemplo n.º 12
0
        public void Octahedron(Polyhedron cube = null)
        {
            if (cube == null)
            {
                cube = new Polyhedron();
                cube.Hexahedron();
            }

            Polygon f0 = new Polygon(
                new List <Point3D>
            {
                new Point3D(cube.Polygons[2].Center),
                new Point3D(cube.Polygons[1].Center),
                new Point3D(cube.Polygons[4].Center)
            }
                );

            Polygon f1 = new Polygon(
                new List <Point3D>
            {
                new Point3D(cube.Polygons[2].Center),
                new Point3D(cube.Polygons[1].Center),
                new Point3D(cube.Polygons[5].Center)
            }
                );

            Polygon f2 = new Polygon(
                new List <Point3D>
            {
                new Point3D(cube.Polygons[2].Center),
                new Point3D(cube.Polygons[5].Center),
                new Point3D(cube.Polygons[0].Center)
            }
                );

            Polygon f3 = new Polygon(
                new List <Point3D>
            {
                new Point3D(cube.Polygons[2].Center),
                new Point3D(cube.Polygons[0].Center),
                new Point3D(cube.Polygons[4].Center)
            }
                );

            Polygon f4 = new Polygon(
                new List <Point3D>
            {
                new Point3D(cube.Polygons[3].Center),
                new Point3D(cube.Polygons[1].Center),
                new Point3D(cube.Polygons[4].Center)
            }
                );

            Polygon f5 = new Polygon(
                new List <Point3D>
            {
                new Point3D(cube.Polygons[3].Center),
                new Point3D(cube.Polygons[1].Center),
                new Point3D(cube.Polygons[5].Center)
            }
                );

            Polygon f6 = new Polygon(
                new List <Point3D>
            {
                new Point3D(cube.Polygons[3].Center),
                new Point3D(cube.Polygons[5].Center),
                new Point3D(cube.Polygons[0].Center)
            }
                );

            Polygon f7 = new Polygon(
                new List <Point3D>
            {
                new Point3D(cube.Polygons[3].Center),
                new Point3D(cube.Polygons[0].Center),
                new Point3D(cube.Polygons[4].Center)
            }
                );

            Polygons = new List <Polygon> {
                f0, f1, f2, f3, f4, f5, f6, f7
            };
            UpdateCenter();
        }
Ejemplo n.º 13
0
        //private void drawRotationButton_Click(object sender, EventArgs e)
        //{
        //    List<Point3D> points = new List<Point3D>();
        //    var lines = textBox1.Text.Split('\n');

        //    foreach (var p in lines)
        //    {
        //        var arr = ((string)p).Split(',');
        //        points.Add(new Point3D(float.Parse(arr[0]), float.Parse(arr[1]), float.Parse(arr[2])));
        //    }

        //    Axis axis = 0;
        //    switch (comboBox6.SelectedItem.ToString())
        //    {
        //        case "OX":
        //            axis = 0;
        //            break;
        //        case "OY":
        //            axis = Axis.AXIS_Y;
        //            break;
        //        case "OZ":
        //            axis = Axis.AXIS_Z;
        //            break;
        //        default:
        //            axis = 0;
        //            break;
        //    }

        //    RotationFigure rotateFigure = new RotationFigure(points, axis, (int)numericUpDown10.Value);

        //    figure = rotateFigure;

        //    Draw();
        //}

        private void clearButton_Click(object sender, EventArgs e)
        {
            g.Clear(Color.White);
            figures.Clear();
            Polyhedron figure = null;
        }
Ejemplo n.º 14
0
        public Graphic(int x0, int x1, int y0, int y1, int count, int func)
        {
            X0            = x0;
            X1            = x1;
            Y0            = y0;
            Y1            = y1;
            CountOfSplits = count;

            float dx = (Math.Abs(x0) + Math.Abs(x1)) / (float)count;
            float dy = (Math.Abs(y0) + Math.Abs(y1)) / (float)count;

            List <Point3D> points = new List <Point3D>();

            switch (func)
            {
            case 0:
                F = (x, y) => x + y;
                break;

            case 1:
                F = (x, y) => (float)(x * x + y * y);
                break;

            case 2:
                F = (x, y) => (float)Math.Sin(x) * 3f + (float)Math.Cos(y) * 3f;
                break;

            case 3:
                F = (x, y) => (float)Math.Sin(x) * 5f;
                break;

            default:
                F = (x, y) => x + y;
                break;
            }

            for (float x = x0; x < x1; x += dx)
            {
                for (float y = y0; y < y1; y += dy)
                {
                    var z = F(x, y);
                    points.Add(new Point3D(x, y, (float)z));
                }
            }

            graphic = new Polyhedron(points);

            for (int j = 1; j < count; ++j)
            {
                graphic.AddEdges(points[j], new List <Point3D> {
                    points[j - 1]
                });
            }

            for (int i = 1; i < count; ++i)
            {
                graphic.AddEdges(points[i * count], new List <Point3D> {
                    points[(i - 1) * count]
                });

                for (int j = 1; j < count; ++j)
                {
                    graphic.AddEdges(points[i * count + j], new List <Point3D> {
                        points[i * count + j - 1], points[(i - 1) * count + j]
                    });
                }
            }
        }
Ejemplo n.º 15
0
 private void drawRotationButton_Click(object sender, EventArgs e)
 {
     int.TryParse(countTextBox.Text, out turnSubs);
     currentPolyhedron = RotationFigure.getRotationFigure(points, new Line3D(new Point3D(0, 0, 0), axisLine), turnSubs);
     drawFigure();
 }
Ejemplo n.º 16
0
        private void transformationRadioButton_Click(object sender, EventArgs e)
        {
            if (currentPolyhedron == null)
            {
                MessageBox.Show("Задайте фигуру", "Ошибка", MessageBoxButtons.OK);
            }
            else
            {
                if (moveRadioButton.Checked)
                {
                    var dialogFirst = new CoordinateBox("Введите смещение по координатам:");
                    if (dialogFirst.ShowDialog() == DialogResult.OK)
                    {
                        currentPolyhedron = AffineTransform.getMoved(
                            currentPolyhedron,
                            dialogFirst.X,
                            dialogFirst.Y,
                            dialogFirst.Z
                            );
                    }
                }
                else if (turnRadioButton.Checked)
                {
                    var dialogX = new InputBox("Введите поворот по оси X \n(градусы)");
                    var dialogY = new InputBox("Введите поворот по оси Y \n(градусы)");
                    var dialogZ = new InputBox("Введите поворот по оси Z \n(градусы)");
                    if (dialogX.ShowDialog() == DialogResult.OK && dialogY.ShowDialog() == DialogResult.OK && dialogZ.ShowDialog() == DialogResult.OK)
                    {
                        currentPolyhedron = AffineTransform.getRotated(
                            currentPolyhedron,
                            int.Parse(dialogX.ResultText),
                            int.Parse(dialogY.ResultText),
                            int.Parse(dialogZ.ResultText)
                            );
                    }
                }
                else if (scaleRadioButton.Checked)
                {
                    var dialogX = new InputBox("Введите увеличение по X");
                    var dialogY = new InputBox("Введите увеличение по Y");
                    var dialogZ = new InputBox("Введите увеличение по Z");
                    if (dialogX.ShowDialog() == DialogResult.OK && dialogY.ShowDialog() == DialogResult.OK && dialogZ.ShowDialog() == DialogResult.OK)
                    {
                        currentPolyhedron = AffineTransform.getScaled(
                            currentPolyhedron,
                            double.Parse(dialogX.ResultText.Replace('.', ',')),
                            double.Parse(dialogY.ResultText.Replace('.', ',')),
                            double.Parse(dialogZ.ResultText.Replace('.', ','))
                            );
                    }
                }
                else if (scaleAroundCenterRadioButton.Checked)
                {
                    var dialogScale = new InputBox("Введите целое значение для  \nмасштабирования в процентах");
                    if (dialogScale.ShowDialog() == DialogResult.OK)
                    {
                        int scale;
                        if (int.TryParse(dialogScale.ResultText, out scale))
                        {
                            ScaleFromCenter(scale);
                        }
                        else
                        {
                            MessageBox.Show("Было введено неверное значение. \nПожалуйста, попробуйте еще раз.", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
                else if (reflectionRadioButton.Checked)
                {
                    var dialog = new InputBox("Введите плоскость, относительно \nкоторой будет происходить \nотражение. Например, xy или yz");
                    if (dialog.ShowDialog() == DialogResult.OK)
                    {
                        var surface = dialog.ResultText.ToLower();
                        if (surface.Length == 2 && (surface.Contains("x") || surface.Contains("y") || surface.Contains("z")))
                        {
                            if (surface == "xy" || surface == "yx")
                            {
                                surface = "xy";
                            }
                            else if (surface == "xz" || surface == "zx")
                            {
                                surface = "xz";
                            }
                            else if (surface == "yz" || surface == "zy")
                            {
                                surface = "yz";
                            }
                            else
                            {
                                MessageBox.Show("Было введено неверное значение. \nПожалуйста, попробуйте еще раз.", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                        }

                        ReflectionFromSurface(surface);
                    }
                }
                else if (rotateAroundLineRadioButton.Checked)
                {
                    var    dialog = new InputBox("Введите название координатной \nоси, параллельно которой \nбудет проходит ось вращения. \nНапример, Oy.");
                    string surface;
                    if (dialog.ShowDialog() == DialogResult.OK)
                    {
                        surface = dialog.ResultText.ToLower();
                        if (surface.Length == 2 && (surface.Contains("x") || surface.Contains("y") || surface.Contains("z")))
                        {
                            if (surface == "ox" || surface == "xo")
                            {
                                surface = "x";
                            }
                            else if (surface == "oy" || surface == "yo")
                            {
                                surface = "y";
                            }
                            else if (surface == "oz" || surface == "zo")
                            {
                                surface = "z";
                            }
                            else
                            {
                                MessageBox.Show("Было введено неверное значение. \nПожалуйста, попробуйте еще раз.", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                        }

                        dialog = new InputBox("Введите целое значение угла \nповорота в градусах");
                        if (dialog.ShowDialog() == DialogResult.OK)
                        {
                            int angle;
                            if (int.TryParse(dialog.ResultText, out angle))
                            {
                                RotateWithLine(surface, angle);
                            }
                            else
                            {
                                MessageBox.Show("Было введено неверное значение. \nПожалуйста, попробуйте еще раз.", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                        }
                    }
                }
                else if (turnAroundLineRadioButton.Checked)
                {
                    var dialogFirst = new CoordinateBox("Введите координаты первой точки прямой:");
                    if (dialogFirst.ShowDialog() == DialogResult.OK)
                    {
                        var first        = new Point3D(dialogFirst.X, dialogFirst.Y, dialogFirst.Z);
                        var dialogSecond = new CoordinateBox("Введите координаты второй точки прямой:");
                        if (dialogSecond.ShowDialog() == DialogResult.OK)
                        {
                            var second      = new Point3D(dialogSecond.X, dialogSecond.Y, dialogSecond.Z);
                            var dialogAngle = new InputBox("Введите целое значение угла поворота в градусах:");
                            if (dialogAngle.ShowDialog() == DialogResult.OK)
                            {
                                int angle;
                                if (int.TryParse(dialogAngle.ResultText, out angle))
                                {
                                    RotateAroundLine(new Line3D(first, second), angle);
                                }
                                else
                                {
                                    MessageBox.Show("Было введено неверное значение. \n Пожалуйста, попробуйте еще раз.", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                }
                            }
                        }
                    }
                }
                drawFigure();
            }
        }
Ejemplo n.º 17
0
        static public Polyhedron getRotated(Polyhedron polyhedron, int ax, int ay, int az)
        {
            double dx = polyhedron.Center.X, dy = polyhedron.Center.Y, dz = polyhedron.Center.Z;
            Matrix moveMatrix = new Matrix(
                new double[4] {
                1, 0, 0, 0
            },
                new double[4] {
                0, 1, 0, 0
            },
                new double[4] {
                0, 0, 1, 0
            },
                new double[4] {
                -dx, -dy, -dz, 1
            }
                );
            Matrix moveMatrix2 = new Matrix(
                new double[4] {
                1, 0, 0, 0
            },
                new double[4] {
                0, 1, 0, 0
            },
                new double[4] {
                0, 0, 1, 0
            },
                new double[4] {
                dx, dy, dz, 1
            }
                );
            double cos = Math.Cos(ax * Math.PI / 180), sin = Math.Sin(ax * Math.PI / 180);
            Matrix rotateAMatrix = new Matrix(
                new double[4] {
                1, 0, 0, 0
            },
                new double[4] {
                0, cos, -sin, 0
            },
                new double[4] {
                0, sin, cos, 0
            },
                new double[4] {
                0, 0, 0, 1
            }
                );

            cos = Math.Cos(ay * Math.PI / 180); sin = Math.Sin(ay * Math.PI / 180);
            Matrix rotateBMatrix = new Matrix(
                new double[4] {
                cos, 0, sin, 0
            },
                new double[4] {
                0, 1, 0, 0
            },
                new double[4] {
                -sin, 0, cos, 0
            },
                new double[4] {
                0, 0, 0, 1
            }
                );

            cos = Math.Cos(az * Math.PI / 180); sin = Math.Sin(az * Math.PI / 180);
            Matrix rotateCMatrix = new Matrix(
                new double[4] {
                cos, -sin, 0, 0
            },
                new double[4] {
                sin, cos, 0, 0
            },
                new double[4] {
                0, 0, 1, 0
            },
                new double[4] {
                0, 0, 0, 1
            }
                );

            return(TransformHelper.ChangePolyhedronByMatrix(polyhedron, moveMatrix * rotateAMatrix * rotateBMatrix * rotateCMatrix * moveMatrix2));
        }
Ejemplo n.º 18
0
 public Polyhedron(Polyhedron polyhedron)
 {
     Polygons = polyhedron.Polygons.Select(face => new Polygon(face)).ToList();
     Center   = new Point3D(polyhedron.Center);
 }
Ejemplo n.º 19
0
        public static Polyhedron getDodehedron()
        {
            double r = 100 * (3 + Math.Sqrt(5)) / 4; // радиус полувписанной окружности
            double x = 100 * (1 + Math.Sqrt(5)) / 4; // половина стороны пятиугольника в сечении

            List <Point3D> points = new List <Point3D>
            {
                new Point3D(0, -50, -r),
                new Point3D(0, 50, -r),
                new Point3D(x, x, -x),
                new Point3D(r, 0, -50),
                new Point3D(x, -x, -x),
                new Point3D(50, -r, 0),
                new Point3D(-50, -r, 0),
                new Point3D(-x, -x, -x),
                new Point3D(-r, 0, -50),
                new Point3D(-x, x, -x),
                new Point3D(-50, r, 0),
                new Point3D(50, r, 0),
                new Point3D(-x, -x, x),
                new Point3D(0, -50, r),
                new Point3D(x, -x, x),
                new Point3D(0, 50, r),
                new Point3D(-x, x, x),
                new Point3D(x, x, x),
                new Point3D(-r, 0, 50),
                new Point3D(r, 0, 50)
            };

            Polyhedron dodehedron = new Polyhedron(points);

            dodehedron.AddEdges(points[0], new List <Point3D> {
                points[1], points[4], points[7]
            });
            dodehedron.AddEdges(points[1], new List <Point3D> {
                points[2], points[9]
            });
            dodehedron.AddEdges(points[2], new List <Point3D> {
                points[3], points[11]
            });
            dodehedron.AddEdges(points[3], new List <Point3D> {
                points[4], points[19]
            });
            dodehedron.AddEdges(points[4], new List <Point3D> {
                points[5]
            });
            dodehedron.AddEdges(points[5], new List <Point3D> {
                points[6], points[14]
            });
            dodehedron.AddEdges(points[6], new List <Point3D> {
                points[7], points[12]
            });
            dodehedron.AddEdges(points[7], new List <Point3D> {
                points[8]
            });
            dodehedron.AddEdges(points[8], new List <Point3D> {
                points[9], points[18]
            });
            dodehedron.AddEdges(points[9], new List <Point3D> {
                points[10]
            });
            dodehedron.AddEdges(points[10], new List <Point3D> {
                points[11], points[16]
            });
            dodehedron.AddEdges(points[11], new List <Point3D> {
                points[17]
            });
            dodehedron.AddEdges(points[12], new List <Point3D> {
                points[13], points[18]
            });
            dodehedron.AddEdges(points[13], new List <Point3D> {
                points[14], points[15]
            });
            dodehedron.AddEdges(points[14], new List <Point3D> {
                points[19]
            });
            dodehedron.AddEdges(points[15], new List <Point3D> {
                points[16], points[17]
            });
            dodehedron.AddEdges(points[16], new List <Point3D> {
                points[18]
            });
            dodehedron.AddEdges(points[17], new List <Point3D> {
                points[19]
            });

            return(dodehedron);
        }
Ejemplo n.º 20
0
        void cameraTransform()
        {
            List <float> m = null;

            if (figure == null)
            {
                MessageBox.Show("Сначала создайте фигуру", "Нет фигуры", MessageBoxButtons.OK);
            }
            else
            {
                int dx = (int)numericUpDown18.Value,
                    dy = (int)numericUpDown17.Value,
                    dz = (int)numericUpDown16.Value;
                //figure.Translate(-dx, -dy, -dz);

                double angleOX = Math.PI * (-((int)numericUpDown15.Value)) / 180,
                       angleOY = Math.PI * (-((int)numericUpDown14.Value)) / 180,
                       angleOZ = Math.PI * (-((int)numericUpDown13.Value)) / 180;

                List <float> translation = new List <float> {
                    1, 0, 0, 0,
                    0, 1, 0, 0,
                    0, 0, 1, 0,
                    -dx, -dy, -dz, 1
                };

                float sin = (float)Math.Sin(angleOX);
                float cos = (float)Math.Cos(angleOX);

                List <float> rotX = new List <float> {
                    1, 0, 0, 0,
                    0, cos, sin, 0,
                    0, -sin, cos, 0,
                    0, 0, 0, 1
                };

                sin = (float)Math.Sin(angleOY);
                cos = (float)Math.Cos(angleOY);

                List <float> rotY = new List <float> {
                    cos, 0, -sin, 0,
                    0, 1, 0, 0,
                    sin, 0, cos, 0,
                    0, 0, 0, 1
                };



                List <float> help1 = mul_matrix2(rotY, 4, 4, rotX, 4, 4);
                m = mul_matrix2(translation, 4, 4, help1, 4, 4);

                //camera.translate(dx, dy, dz);
                ////figure.Rotate(-angleOX, Axis.AXIS_X);
                //camera.rotate((int)numericUpDown15.Value,
                //    (int)numericUpDown14.Value,
                //    (int)numericUpDown13.Value);
            }

            g.Clear(Color.White);

            Polyhedron figureForCam = figure;

            figureForCam.isFake = true;
            figureForCam.Show(g, projection, m);

            //if (renderMode != 0)
            //    show_z_buff();

            //Draw();
        }