Exemplo n.º 1
0
        /// <summary>
        /// rotates the matrix by an angle ussing the following formula
        /// [ Cos(Theta), Sin(Theta),   0,]
        /// [-Sin(Theta), Cos(Theta),   0,]
        /// [     0     ,     0     ,   1)]
        /// </summary>
        /// <param name="angle"></param>
        /// <returns></returns>
        public static Matrix3 Rotation(float angle, Form1.Axis axis)
        {
            float radAngle = (float)(angle * (Math.PI / 180.0));
            float cosTheta = (float)Math.Cos(radAngle);
            float sinTheta = (float)Math.Sin(radAngle);

            Vector3 row1;
            Vector3 row2;
            Vector3 row3;

            switch (axis)
            {
            case Form1.Axis.X:
                row1 = new Vector3(cosTheta, -sinTheta, 0);
                row2 = new Vector3(sinTheta, cosTheta, 0);
                row3 = new Vector3(0, 0, 1);
                break;

            case Form1.Axis.Y:
                row1 = new Vector3(cosTheta, 0, sinTheta);
                row2 = new Vector3(0, 1, 0);
                row3 = new Vector3(-sinTheta, 0, cosTheta);
                break;

            case Form1.Axis.Z:
                row1 = new Vector3(1, 0, 0);
                row2 = new Vector3(0, cosTheta, -sinTheta);
                row3 = new Vector3(0, sinTheta, cosTheta);
                break;

            default:
                row1 = new Vector3();
                row2 = new Vector3();
                row3 = new Vector3();
                break;
            }
            return(new Matrix3(row1, row2, row3));
        }
Exemplo n.º 2
0
        private void setView()
        {
            float angle_beta_rad = (float)(_angle_view_beta * Math.PI / 180);
            float angle_alfa_rad = (float)(_angle_view_alfa * Math.PI / 180);

            _viewY = (float)(_l * Math.Sin(angle_beta_rad));
            float viewX2plusviewZ2 = (float)(_l * Math.Cos(angle_beta_rad));
            _viewX = (float)(viewX2plusviewZ2 * Math.Sin(angle_alfa_rad));
            _viewZ = (float)(viewX2plusviewZ2 * Math.Cos(angle_alfa_rad));

            double angle_x = Math.Acos(Math.Abs(_viewX) / _l) * 180 / Math.PI;
            double angle_y = Math.Acos(Math.Abs(_viewY) / _l) * 180 / Math.PI;
            double angle_z = Math.Acos(Math.Abs(_viewZ) / _l) * 180 / Math.PI;

            if (angle_x <= angle_y && angle_x <= angle_z)
            {
                nearestAxis = Form1.Axis.X;
            }
            else if (angle_y <= angle_x && angle_y <= angle_z)
            {
                nearestAxis = Form1.Axis.Y;
            }
            else if (angle_z <= angle_x && angle_z <= angle_y)
            {
                nearestAxis = Form1.Axis.Z;
            }
        }