예제 #1
0
        public void TransformToOrthogonalProjection_Vector_Point()
        {
            //arrange
            var transformationMatrix = new Matrix3D(2, 3, 5, 1, 1, 18, 3, 0, 2);
            var v = new Vector3D(2, 3, 5);
            var expected = new Point(38, 95);

            //action
            var actual = transformationMatrix.TransformToOrthogonalProjection(v);

            //assert
            Assert.AreEqual(expected, actual);
        }
예제 #2
0
        public void MultiplyVectorMatrix_VectorAndMatrix_Vector()
        {
            //arrange
            var m = new Matrix3D(2, 1, 3, 3, 3, 2, 4, 1, 2);
            var v = new Vector3D(1, 2, 3);
            var expected = new Vector3D(13, 15, 12);

            //action
            var actual = Matrix3D.Multiply(m, v);

            //assert
            Assert.AreEqual(expected, actual);
        }
예제 #3
0
        public void MultiplyMatrixScalar_MatrixAndScalar_Matrix()
        {
            //arrange
            var m = new Matrix3D(2, 3, 1, 5, 4, -2, -3, 10, 11);
            const double scalar = 2;
            var expected = new Matrix3D(4, 6, 2, 10, 8, -4, -6, 20, 22);

            //action
            var actual = Matrix3D.Multiply(m, scalar);

            //assert
            Assert.AreEqual(expected, actual);
        }
예제 #4
0
        public void MultiplyMatrixMatrix_TwoMatrices_Matrix()
        {
            //arrange
            var m1 = new Matrix3D(1, 2, 3, 4, 5, 6, 7, 8, 9);
            var m2 = new Matrix3D(9, 8, 7, 6, 5, 4, 3, 2, 1);
            var expected = new Matrix3D(30, 24, 18, 84, 69, 54, 138, 114, 90);

            //action
            var actual = Matrix3D.Multiply(m1, m2);

            //assert
            Assert.AreEqual(expected, actual);
        }
예제 #5
0
        /// <summary>
        /// Returns rotation matrix by axis Z.
        /// </summary>
        /// <param name="angle">Angle of rotation by axis Z.</param>
        /// <returns>rotation matrix.</returns>
        public static Matrix3D RotationMatrixZ(double angle)
        {
            Matrix3D m = new Matrix3D();

            m.M11 = Math.Cos(angle);
            m.M12 = -Math.Sin(angle);
            m.M21 = Math.Sin(angle);
            m.M22 = Math.Cos(angle);
            m.M33 = 1;

            return m;
        }
예제 #6
0
        /// <summary>
        /// Returns rotation matrix by axis Y.
        /// </summary>
        /// <param name="angle">Angle of rotation by axis Y.</param>
        /// <returns>rotation matrix.</returns>
        public static Matrix3D RotationMatrixY(double angle)
        {
            Matrix3D m = new Matrix3D();

            m.M11 = Math.Cos(angle);
            m.M13 = Math.Sin(angle);
            m.M22 = 1;
            m.M31 = -Math.Sin(angle);
            m.M33 = Math.Cos(angle);

            return m;
        }
예제 #7
0
        /// <summary>
        /// Multiplies the specified matrices.
        /// </summary>
        /// <param name="m1">The matrix to multiply.</param>
        /// <param name="m2">The matrix by which the first matrix is multiplied.</param>
        /// <returns>the result of multiplication.</returns>
        public static Matrix3D Multiply(Matrix3D m1, Matrix3D m2)
        {
            Matrix3D result = new Matrix3D();

            result.M11 = m1.M11 * m2.M11 + m1.M12 * m2.M21 + m1.M13 * m2.M31;
            result.M12 = m1.M11 * m2.M12 + m1.M12 * m2.M22 + m1.M13 * m2.M32;
            result.M13 = m1.M11 * m2.M13 + m1.M12 * m2.M23 + m1.M13 * m2.M33;

            result.M21 = m1.M21 * m2.M11 + m1.M22 * m2.M21 + m1.M23 * m2.M31;
            result.M22 = m1.M21 * m2.M12 + m1.M22 * m2.M22 + m1.M23 * m2.M32;
            result.M23 = m1.M21 * m2.M13 + m1.M22 * m2.M23 + m1.M23 * m2.M33;

            result.M31 = m1.M31 * m2.M11 + m1.M32 * m2.M21 + m1.M33 * m2.M31;
            result.M32 = m1.M31 * m2.M12 + m1.M32 * m2.M22 + m1.M33 * m2.M32;
            result.M33 = m1.M31 * m2.M13 + m1.M32 * m2.M23 + m1.M33 * m2.M33;

            return result;
        }
예제 #8
0
        /// <summary>
        /// Multiplies matrix by vector.
        /// </summary>
        /// <param name="m">The matrix to multiply.</param>
        /// <param name="v">The vector to multiply.</param>
        /// <returns>the result of multiplication.</returns>
        public static Vector3D Multiply(Matrix3D m, Vector3D v)
        {
            Vector3D result = new Vector3D();

            result.X = m.M11 * v.X + m.M12 * v.Y + m.M13 * v.Z;
            result.Y = m.M21 * v.X + m.M22 * v.Y + m.M23 * v.Z;
            result.Z = m.M31 * v.X + m.M32 * v.Y + m.M33 * v.Z;

            return result;
        }
예제 #9
0
        /// <summary>
        /// Multiplies matrix by scalar.
        /// </summary>
        /// <param name="m">The matrix to multiply.</param>
        /// <param name="scalar">The scalar value to multiply.</param>
        /// <returns>the result of multiplication.</returns>
        public static Matrix3D Multiply(Matrix3D m, double scalar)
        {
            Matrix3D result = new Matrix3D();
            result.M11 = m.M11 * scalar;
            result.M12 = m.M12 * scalar;
            result.M13 = m.M13 * scalar;

            result.M21 = m.M21 * scalar;
            result.M22 = m.M22 * scalar;
            result.M23 = m.M23 * scalar;

            result.M31 = m.M31 * scalar;
            result.M32 = m.M32 * scalar;
            result.M33 = m.M33 * scalar;

            return result;
        }