示例#1
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex == 0)
            {
                f = Tetrahedron();
            }
            else if (comboBox1.SelectedIndex == 1)
            {
                f = Hexahedron();
            }
            else if (comboBox1.SelectedIndex == 2)
            {
                f = Figure.Generate(((double x, double y) => { return(x * x - y * y); }), -20, -20, 0, 0, 10, 10);
            }
            else if (comboBox1.SelectedIndex == 3)
            {
                f = Figure.Generate(((double x, double y) => { return(x - y); }), -30, -30, 0, 0, 10, 10);
            }
            else if (comboBox1.SelectedIndex == 4)
            {
                Figure  figure = new Figure();
                Point3d p1     = new Point3d(-50, -50, 0);
                Point3d p4     = new Point3d(50, -50, 0);
                figure.Add(new Line(p1, p4));
                f = figure;
                int count;
                int.TryParse(textBox1.Text, out count);
                int axis = 0;
                if (radioButton5.Checked)
                {
                    axis = 1;
                }
                else if (radioButton6.Checked)
                {
                    axis = 2;
                }
                Figure fig = new Figure();
                var    lns = f.GetLines();
                for (int i = 0; i < lns.Count; i++)
                {
                    fig.Add(new Line(new Point3d(f.lines[i].start.x, f.lines[i].start.y, f.lines[i].start.z), new Point3d(f.lines[i].end.x, f.lines[i].end.y, f.lines[i].end.z)));
                }
                f = new Figure();
                for (int i = 0; i < count; i++)
                {
                    double angle = 360 / count;
                    angle = angle * Math.PI / 180;
                    if (axis == 0)
                    {
                        fig.RotateX(angle);
                    }
                    if (axis == 1)
                    {
                        fig.RotateY(angle);
                    }
                    if (axis == 2)
                    {
                        fig.RotateZ(angle);
                    }
                    var lines = fig.GetLines();
                    for (int j = 0; j < lines.Count; j++)
                    {
                        f.Add(new Line(new Point3d(fig.lines[j].start.x, fig.lines[j].start.y, fig.lines[j].start.z), new Point3d(fig.lines[j].end.x, fig.lines[j].end.y, fig.lines[j].end.z)));
                    }
                }
            }
            else if (comboBox1.SelectedIndex == 5)
            {
                Figure figure = new Figure();
                double px     = -5;
                double py     = Math.Cos(-5);
                for (double x = -5; x < 7; x += 0.1)
                {
                    double cx = x;
                    double cy = Math.Cos(cx);
                    figure.Add(new Line(new Point3d(20 * px, 20 * py - 50, 0), new Point3d(20 * cx, 20 * cy - 50, 0)));
                    px = cx;
                    py = cy;
                }
                f = figure;
                int count;
                int.TryParse(textBox1.Text, out count);
                int axis = 0;
                if (radioButton5.Checked)
                {
                    axis = 1;
                }
                else if (radioButton6.Checked)
                {
                    axis = 2;
                }
                Figure fig = new Figure();
                var    lns = f.GetLines();
                for (int i = 0; i < lns.Count; i++)
                {
                    fig.Add(new Line(new Point3d(f.lines[i].start.x, f.lines[i].start.y, f.lines[i].start.z), new Point3d(f.lines[i].end.x, f.lines[i].end.y, f.lines[i].end.z)));
                }
                f = new Figure();
                for (int i = 0; i < count; i++)
                {
                    double angle = 360 / count;
                    angle = angle * Math.PI / 180;
                    if (axis == 0)
                    {
                        fig.RotateX(angle);
                    }
                    if (axis == 1)
                    {
                        fig.RotateY(angle);
                    }
                    if (axis == 2)
                    {
                        fig.RotateZ(angle);
                    }
                    var lines = fig.GetLines();
                    for (int j = 0; j < lines.Count; j++)
                    {
                        f.Add(new Line(new Point3d(fig.lines[j].start.x, fig.lines[j].start.y, fig.lines[j].start.z), new Point3d(fig.lines[j].end.x, fig.lines[j].end.y, fig.lines[j].end.z)));
                    }
                }
            }

            else if (comboBox1.SelectedIndex == 6)
            {
                Figure  figure = new Figure();
                Point3d p1     = new Point3d(0, 50, 0);
                Point3d p2     = new Point3d(0, -50, 0);
                Point3d p3     = new Point3d(50, 0, 0);
                figure.Add(new Line(p1, p3));
                figure.Add(new Line(p2, p3));
                f = figure;
                int count;
                int.TryParse(textBox1.Text, out count);
                int axis = 0;
                if (radioButton5.Checked)
                {
                    axis = 1;
                }
                else if (radioButton6.Checked)
                {
                    axis = 2;
                }
                Figure fig = new Figure();
                var    lns = f.GetLines();
                for (int i = 0; i < lns.Count; i++)
                {
                    fig.Add(new Line(new Point3d(f.lines[i].start.x, f.lines[i].start.y, f.lines[i].start.z), new Point3d(f.lines[i].end.x, f.lines[i].end.y, f.lines[i].end.z)));
                }
                f = new Figure();
                for (int i = 0; i < count; i++)
                {
                    double angle = 360 / count;
                    angle = angle * Math.PI / 180;
                    if (axis == 0)
                    {
                        fig.RotateX(angle);
                    }
                    if (axis == 1)
                    {
                        fig.RotateY(angle);
                    }
                    if (axis == 2)
                    {
                        fig.RotateZ(angle);
                    }
                    var lines = fig.GetLines();
                    for (int j = 0; j < lines.Count; j++)
                    {
                        f.Add(new Line(new Point3d(fig.lines[j].start.x, fig.lines[j].start.y, fig.lines[j].start.z), new Point3d(fig.lines[j].end.x, fig.lines[j].end.y, fig.lines[j].end.z)));
                    }
                }
            }
            DrawFigure();
            is_selected = true;
        }
示例#2
0
        //лень переписывать, поэтому просто продублирую и заменю переменную
        void DrawFigure2()
        {
            ClearScreen();
            Pen pen = new Pen(Color.DarkRed);

            if (clipping == 2)
            {
                foreach (var edge in f_cam.GetLines())
                {
                    g.DrawLine(pen, ToPBPoint(edge.start), ToPBPoint(edge.end));
                }
            }
            else if (clipping == 1)
            {
                var f2 = f_cam.toVersion2();

                foreach (var fac in f2.Faces())
                {
                    var ugol = Point3d.Ugol(fac.Normal(), new Point3d(0, 0, 200));
                    if (Math.Abs(ugol) > (3.14 / 2))
                    {
                        continue;
                    }

                    Point3d start = fac.Points()[0];
                    for (int i = 0; i < (fac.Points().Count - 1); i++)
                    {
                        var edge = fac.Points()[i];
                        g.DrawLine(pen, ToPBPoint(edge), ToPBPoint(fac.Points()[i + 1]));
                    }
                    g.DrawLine(pen, ToPBPoint(start), ToPBPoint(fac.Points()[fac.Points().Count - 1]));
                }
            }
            else if (clipping == 3)
            {
                //Z-Buffer
                var f2 = f_cam.toVersion2();
                //Конвертированная фигура
                var tmp = new Figure2();
                for (int j = 0; j < f2.Faces().Count; j++)
                {
                    List <Point3d> points = new List <Point3d>();
                    for (int i = 0; i < f2.Faces()[j].Points().Count; i++)
                    {
                        var     ff = ToPBPoint((f2.Faces()[j]).Points()[i]);
                        Point3d t  = new Point3d(ff.X, ff.Y);
                        points.Add(t);
                    }
                    Face f = new Face(points);
                    tmp.Add(f);
                }
                Color fc = Color.Green;
                for (int x = 0; x < pictureBox1.Width; x++)
                {
                    for (int y = 0; y < pictureBox1.Height; y++)
                    {
                        int    pos   = -1;
                        double depth = -1;

                        for (int i = 0; i < tmp.Faces().Count; i++)
                        {
                            if (tmp.Faces()[i].Inside(x, y))
                            {
                                double t = f2.Faces()[i].DepthValue(1, 1);
                                if (t != Face.MaxValue())
                                {
                                    if (pos == -1)
                                    {
                                        depth = t;
                                        pos   = i;
                                    }
                                    else
                                    {
                                        if (depth > t)
                                        {
                                            depth = t;
                                            pos   = i;
                                        }
                                    }
                                }
                            }
                        }
                        if (pos != -1)
                        {
                            //Console.WriteLine (depth);
                            depth = Math.Abs((Face.MaxValue() - depth) / Face.MaxValue());
                            if (depth > 1)
                            {
                                depth = 1;
                            }
                            pen.Color = Color.FromArgb((int)(fc.R * depth), (int)(fc.G * depth), (int)(fc.B * depth));
                            g.DrawEllipse(pen, x, y, 1, 1);
                        }
                    }
                }
            }
            pictureBox1.Invalidate();
        }