Пример #1
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);
        }
Пример #2
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);
                }
            }
        }
Пример #3
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);
        }