コード例 #1
0
        //----------------------------------------------------------------------------------------------
        //vector и auxiliaryVector задают плоскость, в которой
        //vector будет повернут на угол angle
        public static RealVector RotateVectorInPlane(
            RealVector vector, RealVector auxiliaryVector, double angle
            )
        {
            RealVector crossProductOne = SpaceManager.GetVectorsCrossProduct(vector, auxiliaryVector);
            RealVector crossProductTwo = SpaceManager.GetVectorsCrossProduct(vector, crossProductOne);
            RealVector newVector       =
                Math.Cos(angle) * vector + Math.Sin(angle) * crossProductTwo;

            return(newVector);
        }
コード例 #2
0
        //----------------------------------------------------------------------------------------------
        //Матрица поворота от вектора до заданного вектора
        public static RealMatrix GetRotationMatrixToTargetVector(
            RealVector vector, RealVector targetVector
            )
        {
            RealVector crossProduct           = SpaceManager.GetVectorsCrossProduct(vector, targetVector);
            RealVector normalizedCrossProduct = (1 / crossProduct.Length) * crossProduct;
            double     angle = SpaceManager.GetAngleBetweenVectors(vector, targetVector);

            double x = normalizedCrossProduct[0];
            double y = normalizedCrossProduct[1];
            double z = normalizedCrossProduct[2];

            double[ , ] arrayA = new double[, ] {
                { 0, -z, y },
                { z, 0, -x },
                { -y, x, 0 }
            };
            RealMatrix matrixA        = new RealMatrix(arrayA);
            RealMatrix rotationMatrix =
                RealMatrix.IdentityMatrix(3) + matrixA * Math.Sin(angle) +
                (matrixA * matrixA) * (1 - Math.Cos(angle));

            return(rotationMatrix);
        }