/// <summary> /// Transforms a given vector by a matrix. /// </summary> /// <param name="matrix">A <see cref="Matrix3F"/> instance.</param> /// <param name="vector">A <see cref="Vector3F"/> instance.</param> /// <returns>A new <see cref="Vector3F"/> instance containing the result.</returns> public static Vector3F Transform(Matrix3F matrix, Vector3F vector) { return(new Vector3F( (matrix.M11 * vector.X) + (matrix.M12 * vector.Y) + (matrix.M13 * vector.Z), (matrix.M21 * vector.X) + (matrix.M22 * vector.Y) + (matrix.M23 * vector.Z), (matrix.M31 * vector.X) + (matrix.M32 * vector.Y) + (matrix.M33 * vector.Z))); }
/// <summary> /// Converts the specified string to its <see cref="Matrix3F"/> equivalent. /// A return value indicates whether the conversion succeeded or failed. /// </summary> /// <param name="value">A string representation of a <see cref="Matrix3F"/>.</param> /// <param name="result"> /// When this method returns, if the conversion succeeded, /// contains a <see cref="Matrix3F"/> representing the vector specified by <paramref name="value"/>. /// </param> /// <returns><see langword="true"/> if value was converted successfully; otherwise, <see langword="false"/>.</returns> /// <remarks> /// The string should be in the following form: "3x3..matrix elements..>".<br/> /// Exmaple : "3x3[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]" /// </remarks> public static bool TryParse(string value, out Matrix3F result) { Regex r = new Regex(regularExp, RegexOptions.Singleline); Match m = r.Match(value); if (m.Success) { result = new Matrix3F( float.Parse(m.Result("${m11}")), float.Parse(m.Result("${m12}")), float.Parse(m.Result("${m13}")), float.Parse(m.Result("${m21}")), float.Parse(m.Result("${m22}")), float.Parse(m.Result("${m23}")), float.Parse(m.Result("${m31}")), float.Parse(m.Result("${m32}")), float.Parse(m.Result("${m33}")) ); return(true); } result = Matrix3F.Zero; return(false); }
/// <summary> /// Transposes a matrix. /// </summary> /// <param name="m">A <see cref="Matrix3F"/> instance.</param> /// <returns>A new <see cref="Matrix3F"/> instance containing the transposed matrix.</returns> public static Matrix3F Transpose(Matrix3F m) { Matrix3F t = new Matrix3F(m); t.Transpose(); return(t); }
/// <summary> /// Adds a matrix and a scalar. /// </summary> /// <param name="matrix">A <see cref="Matrix3F"/> instance.</param> /// <param name="scalar">A single-precision floating-point number.</param> /// <returns>A new <see cref="Matrix3F"/> instance containing the sum.</returns> public static Matrix3F Add(Matrix3F matrix, float scalar) { return(new Matrix3F( matrix.M11 + scalar, matrix.M12 + scalar, matrix.M13 + scalar, matrix.M21 + scalar, matrix.M22 + scalar, matrix.M23 + scalar, matrix.M31 + scalar, matrix.M32 + scalar, matrix.M33 + scalar )); }
/// <summary> /// Subtracts a scalar from a matrix. /// </summary> /// <param name="a">A <see cref="Matrix3F"/> instance.</param> /// <param name="s">A scalar.</param> /// <returns>A new <see cref="Matrix3F"/> instance containing the difference.</returns> public static Matrix3F Subtract(Matrix3F a, float s) { return(new Matrix3F( a.M11 - s, a.M12 - s, a.M13 - s, a.M21 - s, a.M22 - s, a.M23 - s, a.M31 - s, a.M32 - s, a.M33 - s )); }
/// <summary> /// Adds a matrix and a scalar. /// </summary> /// <param name="a">A <see cref="Matrix3F"/> instance.</param> /// <param name="s">A scalar.</param> /// <returns>A new <see cref="Matrix3F"/> instance containing the sum.</returns> public static Matrix3F Add(Matrix3F a, float s) { return(new Matrix3F( a.M11 + s, a.M12 + s, a.M13 + s, a.M21 + s, a.M22 + s, a.M23 + s, a.M31 + s, a.M32 + s, a.M33 + s )); }
/// <summary> /// Subtracts a matrix from a matrix. /// </summary> /// <param name="a">A <see cref="Matrix3F"/> instance to subtract from.</param> /// <param name="b">A <see cref="Matrix3F"/> instance to subtract.</param> /// <returns>A new <see cref="Matrix3F"/> instance containing the difference.</returns> /// <remarks>result[x][y] = a[x][y] - b[x][y]</remarks> public static Matrix3F Subtract(Matrix3F a, Matrix3F b) { return(new Matrix3F( a.M11 - b.M11, a.M12 - b.M12, a.M13 - b.M13, a.M21 - b.M21, a.M22 - b.M22, a.M23 - b.M23, a.M31 - b.M31, a.M32 - b.M32, a.M33 - b.M33 )); }
/// <summary> /// Adds two matrices. /// </summary> /// <param name="left">A <see cref="Matrix3F"/> instance.</param> /// <param name="right">A <see cref="Matrix3F"/> instance.</param> /// <returns>A new <see cref="Matrix3F"/> instance containing the sum.</returns> public static Matrix3F Add(Matrix3F left, Matrix3F right) { return(new Matrix3F( left.M11 + right.M11, left.M12 + right.M12, left.M13 + right.M13, left.M21 + right.M21, left.M22 + right.M22, left.M23 + right.M23, left.M31 + right.M31, left.M32 + right.M32, left.M33 + right.M33 )); }
/// <summary> /// Adds two matrices. /// </summary> /// <param name="a">A <see cref="Matrix3F"/> instance.</param> /// <param name="b">A <see cref="Matrix3F"/> instance.</param> /// <returns>A new <see cref="Matrix3F"/> instance containing the sum.</returns> public static Matrix3F Add(Matrix3F a, Matrix3F b) { return(new Matrix3F( a.M11 + b.M11, a.M12 + b.M12, a.M13 + b.M13, a.M21 + b.M21, a.M22 + b.M22, a.M23 + b.M23, a.M31 + b.M31, a.M32 + b.M32, a.M33 + b.M33 )); }
/// <summary> /// Subtracts a matrix from a matrix. /// </summary> /// <param name="left">A <see cref="Matrix3F"/> instance to subtract from.</param> /// <param name="right">A <see cref="Matrix3F"/> instance to subtract.</param> /// <returns>A new <see cref="Matrix3F"/> instance containing the difference.</returns> /// <remarks>result[x][y] = left[x][y] - right[x][y]</remarks> public static Matrix3F Subtract(Matrix3F left, Matrix3F right) { return(new Matrix3F( left.M11 - right.M11, left.M12 - right.M12, left.M13 - right.M13, left.M21 - right.M21, left.M22 - right.M22, left.M23 - right.M23, left.M31 - right.M31, left.M32 - right.M32, left.M33 - right.M33 )); }
/// <summary> /// Subtracts a scalar from a matrix. /// </summary> /// <param name="matrix">A <see cref="Matrix3F"/> instance.</param> /// <param name="scalar">A single-precision floating-point number.</param> /// <returns>A new <see cref="Matrix3F"/> instance containing the difference.</returns> public static Matrix3F Subtract(Matrix3F matrix, float scalar) { return(new Matrix3F( matrix.M11 - scalar, matrix.M12 - scalar, matrix.M13 - scalar, matrix.M21 - scalar, matrix.M22 - scalar, matrix.M23 - scalar, matrix.M31 - scalar, matrix.M32 - scalar, matrix.M33 - scalar )); }
/// <summary> /// Returns a value indicating whether this instance is equal to /// the specified object. /// </summary> /// <param name="obj">An object to compare to this instance.</param> /// <returns><see langword="true"/> if <paramref name="obj"/> is a <see cref="Matrix3F"/> and has the same values as this instance; otherwise, <see langword="false"/>.</returns> public override bool Equals(object obj) { if (obj is Matrix3F) { Matrix3F m = (Matrix3F)obj; return ((_m11 == m.M11) && (_m12 == m.M12) && (_m13 == m.M13) && (_m21 == m.M21) && (_m22 == m.M22) && (_m23 == m.M23) && (_m31 == m.M31) && (_m32 == m.M32) && (_m33 == m.M33)); } return(false); }
/// <summary> /// Subtracts a matrix from a matrix and put the result in a third matrix. /// </summary> /// <param name="a">A <see cref="Matrix3F"/> instance to subtract from.</param> /// <param name="b">A <see cref="Matrix3F"/> instance to subtract.</param> /// <param name="result">A <see cref="Matrix3F"/> instance to hold the result.</param> /// <remarks>result[x][y] = a[x][y] - b[x][y]</remarks> public static void Subtract(Matrix3F a, Matrix3F b, ref Matrix3F result) { result.M11 = a.M11 - b.M11; result.M12 = a.M12 - b.M12; result.M13 = a.M13 - b.M13; result.M21 = a.M21 - b.M21; result.M22 = a.M22 - b.M22; result.M23 = a.M23 - b.M23; result.M31 = a.M31 - b.M31; result.M32 = a.M32 - b.M32; result.M33 = a.M33 - b.M33; }
/// <summary> /// Adds a matrix and a scalar and put the result in a third matrix. /// </summary> /// <param name="a">A <see cref="Matrix3F"/> instance.</param> /// <param name="s">A scalar.</param> /// <param name="result">A <see cref="Matrix3F"/> instance to hold the result.</param> public static void Add(Matrix3F a, float s, ref Matrix3F result) { result.M11 = a.M11 + s; result.M12 = a.M12 + s; result.M13 = a.M13 + s; result.M21 = a.M21 + s; result.M22 = a.M22 + s; result.M23 = a.M23 + s; result.M31 = a.M31 + s; result.M32 = a.M32 + s; result.M33 = a.M33 + s; }
/// <summary> /// Adds two matrices and put the result in a third matrix. /// </summary> /// <param name="a">A <see cref="Matrix3F"/> instance.</param> /// <param name="b">A <see cref="Matrix3F"/> instance.</param> /// <param name="result">A <see cref="Matrix3F"/> instance to hold the result.</param> public static void Add(Matrix3F a, Matrix3F b, ref Matrix3F result) { result.M11 = a.M11 + b.M11; result.M12 = a.M12 + b.M12; result.M13 = a.M13 + b.M13; result.M21 = a.M21 + b.M21; result.M22 = a.M22 + b.M22; result.M23 = a.M23 + b.M23; result.M31 = a.M31 + b.M31; result.M32 = a.M32 + b.M32; result.M33 = a.M33 + b.M33; }
/// <summary> /// Multiplies two matrices and put the result in a third matrix. /// </summary> /// <param name="left">A <see cref="Matrix3F"/> instance.</param> /// <param name="right">A <see cref="Matrix3F"/> instance.</param> /// <param name="result">A <see cref="Matrix3F"/> instance to hold the result.</param> public static void Multiply(Matrix3F left, Matrix3F right, ref Matrix3F result) { result.M11 = left.M11 * right.M11 + left.M12 * right.M21 + left.M13 * right.M31; result.M12 = left.M11 * right.M12 + left.M12 * right.M22 + left.M13 * right.M32; result.M13 = left.M11 * right.M13 + left.M12 * right.M23 + left.M13 * right.M33; result.M21 = left.M21 * right.M11 + left.M22 * right.M21 + left.M23 * right.M31; result.M22 = left.M21 * right.M12 + left.M22 * right.M22 + left.M23 * right.M32; result.M23 = left.M21 * right.M13 + left.M22 * right.M23 + left.M23 * right.M33; result.M31 = left.M31 * right.M11 + left.M32 * right.M21 + left.M33 * right.M31; result.M32 = left.M31 * right.M12 + left.M32 * right.M22 + left.M33 * right.M32; result.M33 = left.M31 * right.M13 + left.M32 * right.M23 + left.M33 * right.M33; }
/// <summary> /// Subtracts a scalar from a matrix and put the result in a third matrix. /// </summary> /// <param name="matrix">A <see cref="Matrix3F"/> instance.</param> /// <param name="scalar">A single-precision floating-point number.</param> /// <param name="result">A <see cref="Matrix3F"/> instance to hold the result.</param> public static void Subtract(Matrix3F matrix, float scalar, ref Matrix3F result) { result.M11 = matrix.M11 - scalar; result.M12 = matrix.M12 - scalar; result.M13 = matrix.M13 - scalar; result.M21 = matrix.M21 - scalar; result.M22 = matrix.M22 - scalar; result.M23 = matrix.M23 - scalar; result.M31 = matrix.M31 - scalar; result.M32 = matrix.M32 - scalar; result.M33 = matrix.M33 - scalar; }
/// <summary> /// Subtracts a matrix from a matrix and put the result in a third matrix. /// </summary> /// <param name="left">A <see cref="Matrix3F"/> instance to subtract from.</param> /// <param name="right">A <see cref="Matrix3F"/> instance to subtract.</param> /// <param name="result">A <see cref="Matrix3F"/> instance to hold the result.</param> /// <remarks>result[x][y] = left[x][y] - right[x][y]</remarks> public static void Subtract(Matrix3F left, Matrix3F right, ref Matrix3F result) { result.M11 = left.M11 - right.M11; result.M12 = left.M12 - right.M12; result.M13 = left.M13 - right.M13; result.M21 = left.M21 - right.M21; result.M22 = left.M22 - right.M22; result.M23 = left.M23 - right.M23; result.M31 = left.M31 - right.M31; result.M32 = left.M32 - right.M32; result.M33 = left.M33 - right.M33; }
/// <summary> /// Subtracts a scalar from a matrix and put the result in a third matrix. /// </summary> /// <param name="a">A <see cref="Matrix3F"/> instance.</param> /// <param name="s">A scalar.</param> /// <param name="result">A <see cref="Matrix3F"/> instance to hold the result.</param> public static void Subtract(Matrix3F a, float s, ref Matrix3F result) { result.M11 = a.M11 - s; result.M12 = a.M12 - s; result.M13 = a.M13 - s; result.M21 = a.M21 - s; result.M22 = a.M22 - s; result.M23 = a.M23 - s; result.M31 = a.M31 - s; result.M32 = a.M32 - s; result.M33 = a.M33 - s; }
/// <summary> /// Adds a matrix and a scalar and put the result in a third matrix. /// </summary> /// <param name="matrix">A <see cref="Matrix3F"/> instance.</param> /// <param name="scalar">A single-precision floating-point number.</param> /// <param name="result">A <see cref="Matrix3F"/> instance to hold the result.</param> public static void Add(Matrix3F matrix, float scalar, ref Matrix3F result) { result.M11 = matrix.M11 + scalar; result.M12 = matrix.M12 + scalar; result.M13 = matrix.M13 + scalar; result.M21 = matrix.M21 + scalar; result.M22 = matrix.M22 + scalar; result.M23 = matrix.M23 + scalar; result.M31 = matrix.M31 + scalar; result.M32 = matrix.M32 + scalar; result.M33 = matrix.M33 + scalar; }
/// <summary> /// Adds two matrices and put the result in a third matrix. /// </summary> /// <param name="left">A <see cref="Matrix3F"/> instance.</param> /// <param name="right">A <see cref="Matrix3F"/> instance.</param> /// <param name="result">A <see cref="Matrix3F"/> instance to hold the result.</param> public static void Add(Matrix3F left, Matrix3F right, ref Matrix3F result) { result.M11 = left.M11 + right.M11; result.M12 = left.M12 + right.M12; result.M13 = left.M13 + right.M13; result.M21 = left.M21 + right.M21; result.M22 = left.M22 + right.M22; result.M23 = left.M23 + right.M23; result.M31 = left.M31 + right.M31; result.M32 = left.M32 + right.M32; result.M33 = left.M33 + right.M33; }
/// <summary> /// Multiplies two matrices and put the result in a third matrix. /// </summary> /// <param name="a">A <see cref="Matrix3F"/> instance.</param> /// <param name="b">A <see cref="Matrix3F"/> instance.</param> /// <param name="result">A <see cref="Matrix3F"/> instance to hold the result.</param> public static void Multiply(Matrix3F a, Matrix3F b, ref Matrix3F result) { result.M11 = a.M11 * b.M11 + a.M12 * b.M21 + a.M13 * b.M31; result.M12 = a.M11 * b.M12 + a.M12 * b.M22 + a.M13 * b.M32; result.M13 = a.M11 * b.M13 + a.M12 * b.M23 + a.M13 * b.M33; result.M21 = a.M21 * b.M11 + a.M22 * b.M21 + a.M23 * b.M31; result.M22 = a.M21 * b.M12 + a.M22 * b.M22 + a.M23 * b.M32; result.M23 = a.M21 * b.M13 + a.M22 * b.M23 + a.M23 * b.M33; result.M31 = a.M31 * b.M11 + a.M32 * b.M21 + a.M33 * b.M31; result.M32 = a.M31 * b.M12 + a.M32 * b.M22 + a.M33 * b.M32; result.M33 = a.M31 * b.M13 + a.M32 * b.M23 + a.M33 * b.M33; }
/// <summary> /// Multiplies two matrices. /// </summary> /// <param name="left">A <see cref="Matrix3F"/> instance.</param> /// <param name="right">A <see cref="Matrix3F"/> instance.</param> /// <returns>A new <see cref="Matrix3F"/> instance containing the result.</returns> public static Matrix3F Multiply(Matrix3F left, Matrix3F right) { return(new Matrix3F( left.M11 * right.M11 + left.M12 * right.M21 + left.M13 * right.M31, left.M11 * right.M12 + left.M12 * right.M22 + left.M13 * right.M32, left.M11 * right.M13 + left.M12 * right.M23 + left.M13 * right.M33, left.M21 * right.M11 + left.M22 * right.M21 + left.M23 * right.M31, left.M21 * right.M12 + left.M22 * right.M22 + left.M23 * right.M32, left.M21 * right.M13 + left.M22 * right.M23 + left.M23 * right.M33, left.M31 * right.M11 + left.M32 * right.M21 + left.M33 * right.M31, left.M31 * right.M12 + left.M32 * right.M22 + left.M33 * right.M32, left.M31 * right.M13 + left.M32 * right.M23 + left.M33 * right.M33 )); }
/// <summary> /// Multiplies two matrices. /// </summary> /// <param name="a">A <see cref="Matrix3F"/> instance.</param> /// <param name="b">A <see cref="Matrix3F"/> instance.</param> /// <returns>A new <see cref="Matrix3F"/> instance containing the result.</returns> public static Matrix3F Multiply(Matrix3F a, Matrix3F b) { return(new Matrix3F( a.M11 * b.M11 + a.M12 * b.M21 + a.M13 * b.M31, a.M11 * b.M12 + a.M12 * b.M22 + a.M13 * b.M32, a.M11 * b.M13 + a.M12 * b.M23 + a.M13 * b.M33, a.M21 * b.M11 + a.M22 * b.M21 + a.M23 * b.M31, a.M21 * b.M12 + a.M22 * b.M22 + a.M23 * b.M32, a.M21 * b.M13 + a.M22 * b.M23 + a.M23 * b.M33, a.M31 * b.M11 + a.M32 * b.M21 + a.M33 * b.M31, a.M31 * b.M12 + a.M32 * b.M22 + a.M33 * b.M32, a.M31 * b.M13 + a.M32 * b.M23 + a.M33 * b.M33 )); }
/// <summary> /// Build a 3x3 matrix from from the current matrix without the given row and column. /// </summary> /// <param name="row">The row to remove.</param> /// <param name="column">The column to remove.</param> /// <returns>A <see cref="Matrix3D"/> instance containing the result Minor.</returns> public Matrix3F Minor(int row, int column) { int r = 0; Matrix3F result = new Matrix3F(); for (int iRow = 0; iRow < 4; iRow++) { int c = 0; if (iRow != row) { for (int iCol = 0; iCol < 4; iCol++) { if (iCol != column) { result[r, c] = this[iRow, iCol]; c++; } } r++; } } return(result); }
/// <summary> /// Adds a matrix and a scalar. /// </summary> /// <param name="matrix">A <see cref="Matrix3F"/> instance.</param> /// <param name="scalar">A single-precision floating-point number.</param> /// <returns>A new <see cref="Matrix3F"/> instance containing the sum.</returns> public static Matrix3F Add(Matrix3F matrix, float scalar) { return new Matrix3F( matrix.M11 + scalar, matrix.M12 + scalar, matrix.M13 + scalar, matrix.M21 + scalar, matrix.M22 + scalar, matrix.M23 + scalar, matrix.M31 + scalar, matrix.M32 + scalar, matrix.M33 + scalar ); }
/// <summary> /// Transforms a given vector by a matrix and put the result in a vector. /// </summary> /// <param name="matrix">A <see cref="Matrix3F"/> instance.</param> /// <param name="vector">A <see cref="Vector3F"/> instance.</param> /// <param name="result">A <see cref="Vector3F"/> instance to hold the result.</param> public static void Transform(Matrix3F matrix, Vector3F vector, ref Vector3F result) { result.X = (matrix.M11 * vector.X) + (matrix.M12 * vector.Y) + (matrix.M13 * vector.Z); result.Y = (matrix.M21 * vector.X) + (matrix.M22 * vector.Y) + (matrix.M23 * vector.Z); result.Z = (matrix.M31 * vector.X) + (matrix.M32 * vector.Y) + (matrix.M33 * vector.Z); }
/// <summary> /// Subtracts a scalar from a matrix. /// </summary> /// <param name="matrix">A <see cref="Matrix3F"/> instance.</param> /// <param name="scalar">A single-precision floating-point number.</param> /// <returns>A new <see cref="Matrix3F"/> instance containing the difference.</returns> public static Matrix3F Subtract(Matrix3F matrix, float scalar) { return new Matrix3F( matrix.M11 - scalar, matrix.M12 - scalar, matrix.M13 - scalar, matrix.M21 - scalar, matrix.M22 - scalar, matrix.M23 - scalar, matrix.M31 - scalar, matrix.M32 - scalar, matrix.M33 - scalar ); }
/// <summary> /// Subtracts a scalar from a matrix. /// </summary> /// <param name="a">A <see cref="Matrix3F"/> instance.</param> /// <param name="s">A scalar.</param> /// <returns>A new <see cref="Matrix3F"/> instance containing the difference.</returns> public static Matrix3F operator-(Matrix3F a, float s) { return(Matrix3F.Subtract(a, s)); }
/// <summary> /// Subtracts a matrix from a matrix. /// </summary> /// <param name="a">A <see cref="Matrix3F"/> instance.</param> /// <param name="b">A <see cref="Matrix3F"/> instance.</param> /// <returns>A new <see cref="Matrix3F"/> instance containing the difference.</returns> public static Matrix3F operator-(Matrix3F a, Matrix3F b) { return(Matrix3F.Subtract(a, b)); }
/// <summary> /// Adds a matrix and a scalar. /// </summary> /// <param name="a">A <see cref="Matrix3F"/> instance.</param> /// <param name="s">A scalar.</param> /// <returns>A new <see cref="Matrix3F"/> instance containing the sum.</returns> public static Matrix3F operator+(float s, Matrix3F a) { return(Matrix3F.Add(a, s)); }
/// <summary> /// Subtracts a matrix from a matrix. /// </summary> /// <param name="left">A <see cref="Matrix3F"/> instance to subtract from.</param> /// <param name="right">A <see cref="Matrix3F"/> instance to subtract.</param> /// <returns>A new <see cref="Matrix3F"/> instance containing the difference.</returns> /// <remarks>result[x][y] = left[x][y] - right[x][y]</remarks> public static Matrix3F Subtract(Matrix3F left, Matrix3F right) { return new Matrix3F( left.M11 - right.M11, left.M12 - right.M12, left.M13 - right.M13, left.M21 - right.M21, left.M22 - right.M22, left.M23 - right.M23, left.M31 - right.M31, left.M32 - right.M32, left.M33 - right.M33 ); }
/// <summary> /// Multiplies two matrices. /// </summary> /// <param name="a">A <see cref="Matrix3F"/> instance.</param> /// <param name="b">A <see cref="Matrix3F"/> instance.</param> /// <returns>A new <see cref="Matrix3F"/> instance containing the result.</returns> public static Matrix3F operator*(Matrix3F a, Matrix3F b) { return(Matrix3F.Multiply(a, b)); }
/// <summary> /// Transforms a given vector by a matrix. /// </summary> /// <param name="matrix">A <see cref="Matrix3F"/> instance.</param> /// <param name="vector">A <see cref="Vector3F"/> instance.</param> /// <returns>A new <see cref="Vector3F"/> instance containing the result.</returns> public static Vector3F operator*(Matrix3F matrix, Vector3F vector) { return(Matrix3F.Transform(matrix, vector)); }
/// <summary> /// Multiplies two matrices. /// </summary> /// <param name="left">A <see cref="Matrix3F"/> instance.</param> /// <param name="right">A <see cref="Matrix3F"/> instance.</param> /// <returns>A new <see cref="Matrix3F"/> instance containing the result.</returns> public static Matrix3F Multiply(Matrix3F left, Matrix3F right) { return new Matrix3F( left.M11 * right.M11 + left.M12 * right.M21 + left.M13 * right.M31, left.M11 * right.M12 + left.M12 * right.M22 + left.M13 * right.M32, left.M11 * right.M13 + left.M12 * right.M23 + left.M13 * right.M33, left.M21 * right.M11 + left.M22 * right.M21 + left.M23 * right.M31, left.M21 * right.M12 + left.M22 * right.M22 + left.M23 * right.M32, left.M21 * right.M13 + left.M22 * right.M23 + left.M23 * right.M33, left.M31 * right.M11 + left.M32 * right.M21 + left.M33 * right.M31, left.M31 * right.M12 + left.M32 * right.M22 + left.M33 * right.M32, left.M31 * right.M13 + left.M32 * right.M23 + left.M33 * right.M33 ); }
/// <summary> /// Initializes a new instance of the <see cref="Matrix3F"/> class using a given matrix. /// </summary> public Matrix3F(Matrix3F m) { _m11 = m.M11; _m12 = m.M12; _m13 = m.M13; _m21 = m.M21; _m22 = m.M22; _m23 = m.M23; _m31 = m.M31; _m32 = m.M32; _m33 = m.M33; }
/// <summary> /// Transforms a given vector by a matrix. /// </summary> /// <param name="matrix">A <see cref="Matrix3F"/> instance.</param> /// <param name="vector">A <see cref="Vector3F"/> instance.</param> /// <returns>A new <see cref="Vector3F"/> instance containing the result.</returns> public static Vector3F Transform(Matrix3F matrix, Vector3F vector) { return new Vector3F( (matrix.M11 * vector.X) + (matrix.M12 * vector.Y) + (matrix.M13 * vector.Z), (matrix.M21 * vector.X) + (matrix.M22 * vector.Y) + (matrix.M23 * vector.Z), (matrix.M31 * vector.X) + (matrix.M32 * vector.Y) + (matrix.M33 * vector.Z)); }
/// <summary> /// Converts the specified string to its <see cref="Matrix3F"/> equivalent. /// A return value indicates whether the conversion succeeded or failed. /// </summary> /// <param name="value">A string representation of a <see cref="Matrix3F"/>.</param> /// <param name="result"> /// When this method returns, if the conversion succeeded, /// contains a <see cref="Matrix3F"/> representing the vector specified by <paramref name="value"/>. /// </param> /// <returns><see langword="true"/> if value was converted successfully; otherwise, <see langword="false"/>.</returns> /// <remarks> /// The string should be in the following form: "3x3..matrix elements..>".<br/> /// Exmaple : "3x3[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]" /// </remarks> public static bool TryParse(string value, out Matrix3F result) { Regex r = new Regex(regularExp, RegexOptions.Singleline); Match m = r.Match(value); if (m.Success) { result = new Matrix3F( float.Parse(m.Result("${m11}")), float.Parse(m.Result("${m12}")), float.Parse(m.Result("${m13}")), float.Parse(m.Result("${m21}")), float.Parse(m.Result("${m22}")), float.Parse(m.Result("${m23}")), float.Parse(m.Result("${m31}")), float.Parse(m.Result("${m32}")), float.Parse(m.Result("${m33}")) ); return true; } result = Matrix3F.Zero; return false; }
/// <summary> /// Transposes a matrix. /// </summary> /// <param name="m">A <see cref="Matrix3F"/> instance.</param> /// <returns>A new <see cref="Matrix3F"/> instance containing the transposed matrix.</returns> public static Matrix3F Transpose(Matrix3F m) { Matrix3F t = new Matrix3F(m); t.Transpose(); return t; }
/// <summary> /// Adds two matrices. /// </summary> /// <param name="left">A <see cref="Matrix3F"/> instance.</param> /// <param name="right">A <see cref="Matrix3F"/> instance.</param> /// <returns>A new <see cref="Matrix3F"/> instance containing the sum.</returns> public static Matrix3F Add(Matrix3F left, Matrix3F right) { return new Matrix3F( left.M11 + right.M11, left.M12 + right.M12, left.M13 + right.M13, left.M21 + right.M21, left.M22 + right.M22, left.M23 + right.M23, left.M31 + right.M31, left.M32 + right.M32, left.M33 + right.M33 ); }