/// <summary> /// Subtracts a scalar from a matrix. /// </summary> /// <param name="matrix">A <see cref="Matrix2F"/> instance.</param> /// <param name="scalar">A single-precision floating-point number.</param> /// <returns>A new <see cref="Matrix2F"/> instance containing the difference.</returns> public static Matrix2F Subtract(Matrix2F matrix, float scalar) { return new Matrix2F( matrix.M11 - scalar, matrix.M12 - scalar, matrix.M21 - scalar, matrix.M22 - scalar ); }
/// <summary> /// Adds a matrix and a scalar and put the result in a third matrix. /// </summary> /// <param name="matrix">A <see cref="Matrix2F"/> instance.</param> /// <param name="scalar">A single-precision floating-point number.</param> /// <param name="result">A <see cref="Matrix2F"/> instance to hold the result.</param> public static void Add(Matrix2F matrix, float scalar, ref Matrix2F result) { result.M11 = matrix.M11 + scalar; result.M12 = matrix.M12 + scalar; result.M21 = matrix.M21 + scalar; result.M22 = matrix.M22 + scalar; }
/// <summary> /// Subtracts a matrix from a matrix. /// </summary> /// <param name="left">A <see cref="Matrix2F"/> instance to subtract from.</param> /// <param name="right">A <see cref="Matrix2F"/> instance to subtract.</param> /// <returns>A new <see cref="Matrix2F"/> instance containing the difference.</returns> /// <remarks>result[x][y] = left[x][y] - right[x][y]</remarks> public static Matrix2F Subtract(Matrix2F left, Matrix2F right) { return new Matrix2F( left.M11 - right.M11, left.M12 - right.M12, left.M21 - right.M21, left.M22 - right.M22 ); }
/// <summary> /// Transposes a matrix. /// </summary> /// <param name="m">A <see cref="Matrix2F"/> instance.</param> /// <returns>A new <see cref="Matrix2F"/> instance containing the transposed matrix.</returns> public static Matrix2F Transpose(Matrix2F m) { Matrix2F t = new Matrix2F(m); t.Transpose(); return t; }
/// <summary> /// Transforms a given vector by a matrix and put the result in a vector. /// </summary> /// <param name="matrix">A <see cref="Matrix2F"/> instance.</param> /// <param name="vector">A <see cref="Vector2F"/> instance.</param> /// <param name="result">A <see cref="Vector2F"/> instance to hold the result.</param> public static void Transform(Matrix2F matrix, Vector2F vector, ref Vector2F result) { result.X = (matrix.M11 * vector.X) + (matrix.M12 * vector.Y); result.Y = (matrix.M21 * vector.X) + (matrix.M22 * vector.Y); }
/// <summary> /// Multiplies two matrices. /// </summary> /// <param name="left">A <see cref="Matrix2F"/> instance.</param> /// <param name="right">A <see cref="Matrix2F"/> instance.</param> /// <returns>A new <see cref="Matrix2F"/> instance containing the result.</returns> public static Matrix2F Multiply(Matrix2F left, Matrix2F right) { return new Matrix2F( left.M11 * right.M11 + left.M12 * right.M21, left.M11 * right.M12 + left.M12 * right.M22, left.M21 * right.M11 + left.M22 * right.M21, left.M21 * right.M12 + left.M22 * right.M22 ); }
/// <summary> /// Transforms a given vector by a matrix. /// </summary> /// <param name="matrix">A <see cref="Matrix2F"/> instance.</param> /// <param name="vector">A <see cref="Vector2F"/> instance.</param> /// <returns>A new <see cref="Vector2F"/> instance containing the result.</returns> public static Vector2F Transform(Matrix2F matrix, Vector2F vector) { return new Vector2F( (matrix.M11 * vector.X) + (matrix.M12 * vector.Y), (matrix.M21 * vector.X) + (matrix.M22 * vector.Y)); }
/// <summary> /// Transforms a given vector by a matrix. /// </summary> /// <param name="matrix">A <see cref="Matrix2F"/> instance.</param> /// <param name="vector">A <see cref="Vector2F"/> instance.</param> /// <returns>A new <see cref="Vector2F"/> instance containing the result.</returns> public static Vector2F operator *(Matrix2F matrix, Vector2F vector) { return(Matrix2F.Transform(matrix, vector)); }
/// <summary> /// Initializes a new instance of the <see cref="Matrix2F"/> class using a given matrix. /// </summary> public Matrix2F(Matrix2F m) { _m11 = m.M11; _m12 = m.M12; _m21 = m.M21; _m22 = m.M22; }
/// <summary> /// Subtracts a scalar from a matrix. /// </summary> /// <param name="matrix">A <see cref="Matrix2F"/> instance.</param> /// <param name="scalar">A single-precision floating-point number.</param> /// <returns>A new <see cref="Matrix2F"/> instance containing the difference.</returns> public static Matrix2F operator -(Matrix2F matrix, float scalar) { return(Matrix2F.Subtract(matrix, scalar)); }
/// <summary> /// Multiplies two matrices. /// </summary> /// <param name="left">A <see cref="Matrix2F"/> instance.</param> /// <param name="right">A <see cref="Matrix2F"/> instance.</param> /// <returns>A new <see cref="Matrix2F"/> instance containing the result.</returns> public static Matrix2F operator *(Matrix2F left, Matrix2F right) { return(Matrix2F.Multiply(left, right));; }
/// <summary> /// Subtracts a matrix from a matrix. /// </summary> /// <param name="left">A <see cref="Matrix2F"/> instance.</param> /// <param name="right">A <see cref="Matrix2F"/> instance.</param> /// <returns>A new <see cref="Matrix2F"/> instance containing the difference.</returns> public static Matrix2F operator -(Matrix2F left, Matrix2F right) { return(Matrix2F.Subtract(left, right));; }
/// <summary> /// Adds a matrix and a scalar. /// </summary> /// <param name="matrix">A <see cref="Matrix2F"/> instance.</param> /// <param name="scalar">A single-precision floating-point number.</param> /// <returns>A new <see cref="Matrix2F"/> instance containing the sum.</returns> public static Matrix2F operator +(float scalar, Matrix2F matrix) { return(Matrix2F.Add(matrix, scalar)); }
/// <summary> /// Adds two matrices. /// </summary> /// <param name="left">A <see cref="Matrix2F"/> instance.</param> /// <param name="right">A <see cref="Matrix2F"/> instance.</param> /// <returns>A new <see cref="Matrix2F"/> instance containing the sum.</returns> public static Matrix2F operator +(Matrix2F left, Matrix2F right) { return(Matrix2F.Add(left, right));; }
/// <summary> /// Subtracts a matrix from a matrix and put the result in a third matrix. /// </summary> /// <param name="left">A <see cref="Matrix2F"/> instance to subtract from.</param> /// <param name="right">A <see cref="Matrix2F"/> instance to subtract.</param> /// <param name="result">A <see cref="Matrix2F"/> instance to hold the result.</param> /// <remarks>result[x][y] = left[x][y] - right[x][y]</remarks> public static void Subtract(Matrix2F left, Matrix2F right, ref Matrix2F result) { result.M11 = left.M11 - right.M11; result.M12 = left.M12 - right.M12; result.M21 = left.M21 - right.M21; result.M22 = left.M22 - right.M22; }
/// <summary> /// Converts the specified string to its <see cref="Matrix2F"/> equivalent. /// A return value indicates whether the conversion succeeded or failed. /// </summary> /// <param name="value">A string representation of a <see cref="Matrix2F"/>.</param> /// <param name="result"> /// When this method returns, if the conversion succeeded, /// contains a <see cref="Matrix2F"/> 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: "2x2..matrix elements..>".<br/> /// Exmaple : "2x2[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]" /// </remarks> public static bool TryParse(string value, out Matrix2F result) { Regex r = new Regex(regularExp, RegexOptions.Singleline); Match m = r.Match(value); if (m.Success) { result = new Matrix2F( float.Parse(m.Result("${m11}")), float.Parse(m.Result("${m12}")), float.Parse(m.Result("${m21}")), float.Parse(m.Result("${m22}")) ); return true; } result = Matrix2F.Zero; return false; }
/// <summary> /// Subtracts a scalar from a matrix and put the result in a third matrix. /// </summary> /// <param name="matrix">A <see cref="Matrix2F"/> instance.</param> /// <param name="scalar">A single-precision floating-point number.</param> /// <param name="result">A <see cref="Matrix2F"/> instance to hold the result.</param> public static void Subtract(Matrix2F matrix, float scalar, ref Matrix2F result) { result.M11 = matrix.M11 - scalar; result.M12 = matrix.M12 - scalar; result.M21 = matrix.M21 - scalar; result.M22 = matrix.M22 - scalar; }
/// <summary> /// Adds two matrices. /// </summary> /// <param name="left">A <see cref="Matrix2F"/> instance.</param> /// <param name="right">A <see cref="Matrix2F"/> instance.</param> /// <returns>A new <see cref="Matrix2F"/> instance containing the sum.</returns> public static Matrix2F Add(Matrix2F left, Matrix2F right) { return new Matrix2F( left.M11 + right.M11, left.M12 + right.M12, left.M21 + right.M21, left.M22 + right.M22 ); }
/// <summary> /// Multiplies two matrices and put the result in a third matrix. /// </summary> /// <param name="left">A <see cref="Matrix2F"/> instance.</param> /// <param name="right">A <see cref="Matrix2F"/> instance.</param> /// <param name="result">A <see cref="Matrix2F"/> instance to hold the result.</param> public static void Multiply(Matrix2F left, Matrix2F right, ref Matrix2F result) { result.M11 = left.M11 * right.M11 + left.M12 * right.M21; result.M12 = left.M11 * right.M12 + left.M12 * right.M22; result.M21 = left.M21 * right.M11 + left.M22 * right.M21; result.M22 = left.M21 * right.M12 + left.M22 * right.M22; }
/// <summary> /// Adds a matrix and a scalar. /// </summary> /// <param name="matrix">A <see cref="Matrix2F"/> instance.</param> /// <param name="scalar">A single-precision floating-point number.</param> /// <returns>A new <see cref="Matrix2F"/> instance containing the sum.</returns> public static Matrix2F Add(Matrix2F matrix, float scalar) { return new Matrix2F( matrix.M11 + scalar, matrix.M12 + scalar, matrix.M21 + scalar, matrix.M22 + scalar ); }
/// <summary> /// Adds two matrices and put the result in a third matrix. /// </summary> /// <param name="left">A <see cref="Matrix2F"/> instance.</param> /// <param name="right">A <see cref="Matrix2F"/> instance.</param> /// <param name="result">A <see cref="Matrix2F"/> instance to hold the result.</param> public static void Add(Matrix2F left, Matrix2F right, ref Matrix2F result) { result.M11 = left.M11 + right.M11; result.M12 = left.M12 + right.M12; result.M21 = left.M21 + right.M21; result.M22 = left.M22 + right.M22; }
/// <summary> /// Transforms a given vector by a matrix. /// </summary> /// <param name="matrix">A <see cref="Matrix2F"/> instance.</param> /// <param name="vector">A <see cref="Vector2F"/> instance.</param> /// <returns>A new <see cref="Vector2F"/> instance containing the result.</returns> public static Vector2F Transform(Matrix2F matrix, Vector2F vector) { return(new Vector2F( (matrix.M11 * vector.X) + (matrix.M12 * vector.Y), (matrix.M21 * vector.X) + (matrix.M22 * vector.Y))); }