Ejemplo n.º 1
0
        /// <summary>
        /// Rotates the vector about the Z axis as though the tail of the vector were at the origin
        /// </summary>
        /// <param name="degrees">The angle in degrees to rotate counter-clockwise when looking at the origin from the positive axis.</param>
        /// <returns>A new Vector that has been rotated</returns>
        public virtual Vector RotateZ(double degrees)
        {
            IMatrixD m   = ToMatrix();
            IMatrixD res = m.Multiply(Matrix4.RotationZ(degrees));

            return(new Vector(res));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Matrix multiplication only works if the number of columns of the first matrix is the same as the number of rows of the second matrix.
        /// The first matrix is this object, so this will only work if inMatrix has the same number of rows as this matrix has columns.
        /// </summary>
        /// <param name="inMatrix">The IMatrix to multiply against this matrix.</param>
        /// <returns>Result of the multiplication.</returns>
        /// <exception cref="ArgumentException">Thrown if number of columns of the first matrix differs from the number of rows from the second matrix.</exception>
        public IMatrixD Multiply(IMatrixD inMatrix)
        {
            if (inMatrix.NumRows != NumColumns)
            {
                throw new ArgumentException("Matrix multiplication only works if the number of columns of the first matrix is the same as the number of rows of the second matrix");
            }

            int m = NumRows;
            int n = inMatrix.NumColumns;

            double[,] vals = new double[m, n];
            for (int row = 0; row < m; row++)
            {
                for (int col = 0; col < n; col++)
                {
                    vals[row, col] = 0;
                    for (int i = 0; i < NumColumns; i++)
                    {
                        vals[row, col] += _values[row, i] * inMatrix.Values[i, col];
                    }
                }
            }

            return(new MatrixD(vals));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Transforms a point that has 3 dimensions by multiplying it by the specified 3 x 3 matrix in the upper left,
        /// but treats the bottom row as supplying the translation coordinates.
        /// </summary>
        /// <param name="transformMatrix">Transformation matrix for transformation.</param>
        /// <returns>The resulting vector.</returns>
        public Vector TransformCoordinate(IMatrix4 transformMatrix)
        {
            IMatrixD m   = ToMatrix();
            IMatrixD res = m.Multiply(transformMatrix);

            // the output vector will have the coordinates arranged in columns rather than rows.
            double[,] results = res.Values;
            return(new Vector(results[0, 0], results[0, 1], results[0, 2]));
        }
Ejemplo n.º 4
0
        IMatrix IMatrix.Multiply(IMatrix inMatrix)
        {
            IMatrixD mat = inMatrix as IMatrixD;

            if (mat == null)
            {
                throw new ArgumentException("Invalid Matrix provided for inMatrix");
            }
            return(Multiply(mat));
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Matrix multiplication only works if the number of columns of the first matrix is the same
 /// as the number of rows of the second matrix.  The first matrix is this object, so this
 /// will only work if inMatrix has the same number of rows as this matrix has columns.
 /// </summary>
 /// <param name="inMatrix">The IMatrix to multiply against this matrix</param>
 /// <returns></returns>
 public IMatrixD Multiply(IMatrixD inMatrix)
 {
     if (inMatrix.NumRows != NumColumns) throw new ArgumentException("Matrix multiplication only works if the number of columns of the first matrix is the same as the number of rows of the second matrix");
     
     int m = NumRows;
     int n = inMatrix.NumColumns;
     double[,] vals = new double[m, n];
     for (int row = 0; row < m; row++)
     {
         for (int col = 0; col < n; col++)
         {
             vals[row, col] = 0;
             for(int I = 0; I < NumColumns; I++)
             {
                 vals[row, col] += _values[row, I] * inMatrix.Values[I, col];
             }
         }
     }
     return new MatrixD(vals);
     
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Creates a new vector based on the first three values on the first row of the
 /// matrix.  This is useful for working with the result of a transformation matrix.
 /// </summary>
 /// <param name="mat">An IMatrixD that should represent the vector</param>
 public Vector(IMatrixD mat)
 {
     X = mat.Values[0, 0];
     Y = mat.Values[0, 1];
     Z = mat.Values[0, 2];
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Vector"/> class based on the first three values on the first row of the
 /// matrix. This is useful for working with the result of a transformation matrix.
 /// </summary>
 /// <param name="mat">An IMatrixD that should represent the vector</param>
 public Vector(IMatrixD mat)
 {
     X = mat.Values[0, 0];
     Y = mat.Values[0, 1];
     Z = mat.Values[0, 2];
 }