示例#1
0
        private void B3_Click(object sender, EventArgs e)
        {
            Label l31 = FindControl(panel1, "l31") as Label;
            Label l32 = FindControl(panel1, "l32") as Label;
            Label l33 = FindControl(panel1, "l33") as Label;
            Label l34 = FindControl(panel1, "l34") as Label;
            Label l35 = FindControl(panel1, "l35") as Label;
            int   x1;
            int   y1;
            int   x2;
            int   y2;

            int.TryParse(l31.Text.Split(' ')[1], out x1);
            int.TryParse(l32.Text.Split(' ')[1], out y1);
            int.TryParse(l33.Text.Split(' ')[1], out x2);
            int.TryParse(l34.Text.Split(' ')[1], out y2);
            Figure f2 = new Figure();

            f2.Add(new CustomPoint(x1, y1));
            f2.Add(new CustomPoint(x2, y2));
            var res = Figure.Intersection(f, f2);

            l35.Text = "Result: " + (res.x).ToString("F0") + "; " + (res.y).ToString("F0");
            Graphics g = Graphics.FromImage(pictureBox1.Image);

            Point[] points = new Point[2];
            points[0] = new Point(ToPictureBoxX(x1), ToPictureBoxY(y1));
            points[1] = new Point(ToPictureBoxX(x2), ToPictureBoxY(y2));
            Pen pen = new Pen(Color.Blue);

            g.DrawPolygon(pen, points);
            pictureBox1.Invalidate();
        }
示例#2
0
 private void checkBox_cam_CheckedChanged(object sender, EventArgs e)
 {
     if (checkBox_cam.Checked)
     {
         is_cam = true;
         f_cam  = new Figure();
         var lns = f.GetLines();
         for (int i = 0; i < lns.Count; i++)
         {
             f_cam.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)));
         }
     }
     else
     {
         is_cam = false;
     }
 }
示例#3
0
        private Figure Tetrahedron()
        {
            Figure  figure = new Figure();
            double  coef   = 50 * Math.Sqrt(3);
            Point3d p1     = new Point3d(0, coef / 2, 0);
            Point3d p2     = new Point3d(-50, -coef / 2, 0);
            Point3d p3     = new Point3d(50, -coef / 2, 0);
            Point3d p4     = new Point3d(0, -coef / 2, -coef);

            // Должна быть именно такая последовательность описания, иначе отображается не совсем корректно
            figure.Add(new Line(p3, p4));
            figure.Add(new Line(p2, p4));
            figure.Add(new Line(p3, p1));
            figure.Add(new Line(p2, p3));
            figure.Add(new Line(p1, p4));
            figure.Add(new Line(p1, p2));

            return(figure);
        }
示例#4
0
        private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
        {
            if (CurrPanel == 0)
            {
                Graphics g   = Graphics.FromImage(pictureBox1.Image);
                Pen      pen = new Pen(Color.Red);
                if (Mode == 1)
                {
                    //f.Add(new CustomPoint(e.X, e.Y));
                    f.Add(new CustomPoint(ToDekartX(e.X), ToDekartY(e.Y)));
                    g.DrawRectangle(pen, e.X, e.Y, 1, 1);
                    pictureBox1.Invalidate();
                }
                else
                {
                    if (f.Points().Count < 2)
                    {
                        //f.Add(new CustomPoint(e.X, e.Y));
                        f.Add(new CustomPoint(ToDekartX(e.X), ToDekartY(e.Y)));
                        g.DrawRectangle(pen, e.X, e.Y, 1, 1);
                        pictureBox1.Invalidate();
                    }
                }
            }
            if (CurrPanel == 1)
            {
                if (comboBox2.SelectedIndex == 1)
                {
                    if (FindControl(panel1, "cb1") != null)
                    {
                        if (!(FindControl(panel1, "cb1") as CheckBox).Checked)
                        {
                            Label  l11 = FindControl(panel1, "l11") as Label;
                            Label  l12 = FindControl(panel1, "l12") as Label;
                            Button b1  = FindControl(panel1, "b1") as Button;
                            b1.Enabled = true;
                            if (e.Button == MouseButtons.Left)
                            {
                                l11.Text = "X: " + ToDekartX(e.X).ToString();
                                l12.Text = "Y: " + ToDekartY(e.Y).ToString();
                            }
                        }
                    }
                    else
                    {
                        Label  l11 = FindControl(panel1, "l11") as Label;
                        Label  l12 = FindControl(panel1, "l12") as Label;
                        Button b1  = FindControl(panel1, "b1") as Button;
                        b1.Enabled = true;

                        /*if (e.Button == MouseButtons.Left)
                         * {
                         *  l11.Text = "X: " + (ToValidPoint(e.X, e.Y).X - 500).ToString();
                         *  l12.Text = "Y: " + ToValidPoint(e.X, e.Y).Y.ToString();
                         * }*/
                    }
                }

                if (Mode == 0)
                {
                    if (comboBox2.SelectedIndex == 3)
                    {
                        Button b3  = FindControl(panel1, "b3") as Button;
                        Label  l31 = FindControl(panel1, "l31") as Label;
                        Label  l32 = FindControl(panel1, "l32") as Label;
                        Label  l33 = FindControl(panel1, "l33") as Label;
                        Label  l34 = FindControl(panel1, "l34") as Label;
                        if (e.Button == MouseButtons.Left)
                        {
                            l31.Text = "X1: " + ToDekartX(e.X).ToString();
                            l32.Text = "Y1: " + ToDekartY(e.Y).ToString();
                        }
                        if (e.Button == MouseButtons.Right)
                        {
                            l33.Text   = "X2: " + ToDekartX(e.X).ToString();
                            l34.Text   = "Y2: " + ToDekartY(e.Y).ToString();
                            b3.Enabled = true;
                        }
                    }
                }
            }
            if (CurrPanel == 2)
            {
                if (Mode == 1)
                {
                    if (comboBox3.SelectedIndex == 0)
                    {
                        Label  l21 = FindControl(panel2, "l21") as Label;
                        Label  l22 = FindControl(panel2, "l22") as Label;
                        Button b5  = FindControl(panel2, "b5") as Button;
                        if (e.Button == MouseButtons.Left)
                        {
                            l21.Text = "X: " + ToDekartX(e.X).ToString();
                            l22.Text = "Y: " + ToDekartY(e.Y).ToString();
                        }
                        b5.Enabled = true;
                    }
                }
                else
                {
                    if (comboBox3.SelectedIndex == 0)
                    {
                        Label  l11 = FindControl(panel2, "l11") as Label;
                        Label  l12 = FindControl(panel2, "l12") as Label;
                        Button b4  = FindControl(panel2, "b4") as Button;
                        {
                            l11.Text = "X: " + ToDekartX(e.X).ToString();
                            l12.Text = "Y: " + ToDekartY(e.Y).ToString();
                        }
                        b4.Enabled = true;
                    }
                }
            }
        }
示例#5
0
        private Figure Hexahedron()
        {
            Figure  figure = new Figure();
            Point3d p1     = new Point3d(100 / 2, -100 / 2, 100 / 2);
            Point3d p2     = new Point3d(100 / 2, -100 / 2, -100 / 2);
            Point3d p3     = new Point3d(-100 / 2, -100 / 2, -100 / 2);
            Point3d p4     = new Point3d(-100 / 2, -100 / 2, 100 / 2);

            Point3d p5 = new Point3d(100 / 2, 100 / 2, 100 / 2);
            Point3d p6 = new Point3d(100 / 2, 100 / 2, -100 / 2);
            Point3d p7 = new Point3d(-100 / 2, 100 / 2, -100 / 2);
            Point3d p8 = new Point3d(-100 / 2, 100 / 2, 100 / 2);

            // Должна быть именно такая последовательность описания, иначе отображается не совсем корректно
            figure.Add(new Line(p1, p2));
            figure.Add(new Line(p2, p3));
            figure.Add(new Line(p1, p5));
            figure.Add(new Line(p2, p6));

            figure.Add(new Line(p3, p4));
            figure.Add(new Line(p4, p1));
            figure.Add(new Line(p7, p8));

            figure.Add(new Line(p5, p6));
            figure.Add(new Line(p6, p7));
            figure.Add(new Line(p8, p5));
            figure.Add(new Line(p3, p7));
            figure.Add(new Line(p4, p8));

            return(figure);
        }
示例#6
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;
        }