Exemplo n.º 1
0
        /// <summary>
        /// Поворот фигуры
        /// </summary>
        /// <param name="Angle">Угол</param>
        /// <param name="Axis">Ось, относительно которой осуществляется поворот</param>
        public void Rotation(double Angle, char Axis)
        {
            //TODO
            Angle = Angle * Math.PI / 180;
            if (Axis == 'x')
            {
                //По формуле меняем координаты 4х точек (Атрибутов этого же класса)
                double NewLeftTop3Dx = LeftTop3D.X * 1;
                double NewLeftTop3Dy = LeftTop3D.Y * Math.Cos(Angle) - LeftTop3D.Z * Math.Sin(Angle);
                double NewLeftTop3Dz = LeftTop3D.Y * Math.Sin(Angle) + LeftTop3D.Z * Math.Cos(Angle);
                this.LeftTop3D = new Tochka3D(NewLeftTop3Dx, NewLeftTop3Dy, NewLeftTop3Dz);

                double NewLeftBot3Dx = LeftBot3D.X * 1;
                double NewLeftBot3Dy = LeftBot3D.Y * Math.Cos(Angle) - LeftBot3D.Z * Math.Sin(Angle);
                double NewLeftBot3Dz = LeftBot3D.Y * Math.Sin(Angle) + LeftBot3D.Z * Math.Cos(Angle);
                this.LeftBot3D = new Tochka3D(NewLeftBot3Dx, NewLeftBot3Dy, NewLeftBot3Dz);

                double NewRightTop3Dx = RightTop3D.X * 1;
                double NewRightTop3Dy = RightTop3D.Y * Math.Cos(Angle) - RightTop3D.Z * Math.Sin(Angle);
                double NewRightTop3Dz = RightTop3D.Y * Math.Sin(Angle) + RightTop3D.Z * Math.Cos(Angle);
                this.RightTop3D = new Tochka3D(NewRightTop3Dx, NewRightTop3Dy, NewRightTop3Dz);

                double NewRightBot3Dx = RightBot3D.X * 1;
                double NewRightBot3Dy = RightBot3D.Y * Math.Cos(Angle) - RightBot3D.Z * Math.Sin(Angle);
                double NewRightBot3Dz = RightBot3D.Y * Math.Sin(Angle) + RightBot3D.Z * Math.Cos(Angle);
                this.RightBot3D = new Tochka3D(NewRightBot3Dx, NewRightBot3Dy, NewRightBot3Dz);
                //Вызываем метод MakeFigure, который нарисует фигуру по новым точкам
            }
            else
            {
                if (Axis == 'y')
                {
                    //По формуле меняем координаты 4х точек (Атрибутов этого же класса)
                    double NewLeftTop3Dx = LeftTop3D.X * Math.Cos(Angle) - LeftTop3D.Z * Math.Sin(Angle);
                    double NewLeftTop3Dy = LeftTop3D.Y * 1;
                    double NewLeftTop3Dz = LeftTop3D.X * Math.Sin(Angle) + LeftTop3D.Z * Math.Cos(Angle);
                    this.LeftTop3D = new Tochka3D(NewLeftTop3Dx, NewLeftTop3Dy, NewLeftTop3Dz);

                    double NewLeftBot3Dx = LeftBot3D.X * Math.Cos(Angle) - LeftBot3D.Z * Math.Sin(Angle);
                    double NewLeftBot3Dy = LeftBot3D.Y * 1;
                    double NewLeftBot3Dz = LeftBot3D.X * Math.Sin(Angle) + LeftBot3D.Z * Math.Cos(Angle);
                    this.LeftBot3D = new Tochka3D(NewLeftBot3Dx, NewLeftBot3Dy, NewLeftBot3Dz);

                    double NewRightTop3Dx = RightTop3D.X * Math.Cos(Angle) - RightTop3D.Z * Math.Sin(Angle);
                    double NewRightTop3Dy = RightTop3D.Y * 1;
                    double NewRightTop3Dz = RightTop3D.X * Math.Sin(Angle) + RightTop3D.Z * Math.Cos(Angle);
                    this.RightTop3D = new Tochka3D(NewRightTop3Dx, NewRightTop3Dy, NewRightTop3Dz);

                    double NewRightBot3Dx = RightBot3D.X * Math.Cos(Angle) - RightBot3D.Z * Math.Sin(Angle);
                    double NewRightBot3Dy = RightBot3D.Y * 1;
                    double NewRightBot3Dz = RightBot3D.X * Math.Sin(Angle) + RightBot3D.Z * Math.Cos(Angle);
                    this.RightBot3D = new Tochka3D(NewRightBot3Dx, NewRightBot3Dy, NewRightBot3Dz);


                    //Вызываем метод MakeFigure, который нарисует фигуру по новым точкам
                }
            }
        }
Exemplo n.º 2
0
        public Figure(Tochka3D point1, Tochka3D point2, Tochka3D point3, Tochka3D point4)
        {
            List <Tochka3D> points = new List <Tochka3D> {
                point1, point2, point3, point4
            };

            //TODO
            //Сортировка по х
            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    if (points[j].To2D.X > points[j + 1].To2D.X)
                    {
                        points.Reverse(j, j + 1);
                        //Swap(points[j], points[j + 1]);
                    }
                }
            }

            //Заполнение переменных
            if (points[0].To2D.Y < points[1].To2D.Y)
            {
                this.LeftBot3D = points[0];
                this.LeftTop3D = points[1];

                if (points[2].To2D.Y < points[3].To2D.Y)
                {
                    this.RightBot3D = points[2];
                    this.RightTop3D = points[3];
                }

                else
                {
                    this.RightBot3D = points[3];
                    this.RightTop3D = points[2];
                }
            }
            else
            {
                this.LeftBot3D = points[1];
                this.LeftTop3D = points[0];

                if (points[2].To2D.Y < points[3].To2D.Y)
                {
                    this.RightBot3D = points[2];
                    this.RightTop3D = points[3];
                }

                else
                {
                    this.RightBot3D = points[3];
                    this.RightTop3D = points[2];
                }
            }
        }