Example #1
0
        private void Button_exec_Click(object sender, EventArgs e)
        {
            if (figure == null)
            {
                MessageBox.Show("Сначала создайте фигуру", "Нет фигуры", MessageBoxButtons.OK);
            }
            else
            {
                double         old_x = figure.Center.X, old_y = figure.Center.Y, old_z = figure.Center.Z;
                Transformation transformation = Transformation.Translate(-old_x, -old_y, -old_z);
                transformation *= Transformation.Translate(Double.Parse(trans_x.Text), Double.Parse(trans_y.Text), Double.Parse(trans_z.Text));
                transformation *= Transformation.Scale(Double.Parse(scaling_x.Text), Double.Parse(scaling_y.Text), Double.Parse(scaling_z.Text));
                double rotX = Double.Parse(angle_x.Text) / 180 * Math.PI;
                double rotY = Double.Parse(angle_y.Text) / 180 * Math.PI;
                double rotZ = Double.Parse(angle_z.Text) / 180 * Math.PI;
                switch (line_mode)
                {
                case Axis.OTHER:
                    Edge rot_line = new Edge(
                        new Point3d(
                            int.Parse(rot_line_x1.Text),
                            int.Parse(rot_line_y1.Text),
                            int.Parse(rot_line_z1.Text)),
                        new Point3d(
                            int.Parse(rot_line_x2.Text),
                            int.Parse(rot_line_y2.Text),
                            int.Parse(rot_line_z2.Text))
                        );
                    double Ax = (rot_line.P1.X + rot_line.P2.X) / 2,
                           Ay = (rot_line.P1.Y + rot_line.P2.Y) / 2,
                           Az = (rot_line.P1.Z + rot_line.P2.Z) / 2;

                    transformation *= Transformation.Translate(-Ax, -Ay, Az)
                                      * Transformation.RotateX(rotX)
                                      * Transformation.RotateY(rotY)
                                      * Transformation.RotateZ(rotZ)
                                      * Transformation.Translate(Ax, Ay, Az);
                    break;

                default:
                    transformation *= Transformation.RotateX(rotX)
                                      * Transformation.RotateY(rotY)
                                      * Transformation.RotateZ(rotZ);
                    break;
                }
                transformation *= Transformation.Translate(old_x, old_y, old_z);
                figure.Apply(transformation);
                camera.fiqureApply(transformation);
                clearScenes();
                figure.show(g, pr, new_fig);
                camera.show(camera_g, old_fig);
            }
        }
Example #2
0
        private void Button3_Click(object sender, EventArgs e)
        {
            Form2 form2 = new Form2();

            form2.ShowDialog();

            var   f             = form2.f;
            float x0            = form2.X0;
            float x1            = form2.X1;
            float y0            = form2.Y0;
            float y1            = form2.Y1;
            int   cnt_of_breaks = form2.Cnt_of_breaks;

            form2.Dispose();

            ReverseFloatComparer fcmp = new ReverseFloatComparer();

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

            List <Face>    faces = new List <Face>();
            List <Point3d> pts0  = new List <Point3d>();
            List <Point3d> pts1  = new List <Point3d>();

            for (float x = x0; x < x1; x += dx)
            {
                for (float y = y0; y < y1; y += dy)
                {
                    float z = f(x, y);
                    pts1.Add(new Point3d(x, y, z));
                }
                if (pts0.Count != 0)
                {
                    for (int i = 1; i < pts0.Count; ++i)
                    {
                        faces.Add(new Face(new List <Point3d>()
                        {
                            new Point3d(pts0[i - 1]), new Point3d(pts1[i - 1]),
                            new Point3d(pts1[i]), new Point3d(pts0[i])
                        }));
                    }
                }
                pts0.Clear();
                pts0 = pts1;
                pts1 = new List <Point3d>();
            }

            g.Clear(Color.White);
            figure = new Polyhedron(faces);
            figure.Apply(Transformation.Scale(5, 5, 5));
            figure.show(g, pr, new_fig);
        }