/// <summary> /// Transposes a matrix. /// </summary> /// <param name="m">A <see cref="Matrix2D"/> instance.</param> /// <returns>A new <see cref="Matrix2D"/> instance containing the transposed matrix.</returns> public static Matrix2D Transpose(Matrix2D m) { Matrix2D t = new Matrix2D(m); t.Transpose(); return t; }
/// <summary> /// Transforms a given vector by a matrix. /// </summary> /// <param name="matrix">A <see cref="Matrix2D"/> instance.</param> /// <param name="vector">A <see cref="Vector2D"/> instance.</param> /// <returns>A new <see cref="Vector2D"/> instance containing the result.</returns> public static Vector2D Transform(Matrix2D matrix, Vector2D vector) { return(new Vector2D( (matrix.M11 * vector.X) + (matrix.M12 * vector.Y), (matrix.M21 * vector.X) + (matrix.M22 * vector.Y))); }
/// <summary> /// Adds two matrices. /// </summary> /// <param name="a">A <see cref="Matrix2D"/> instance.</param> /// <param name="b">A <see cref="Matrix2D"/> instance.</param> /// <returns>A new <see cref="Matrix2D"/> instance containing the sum.</returns> public static Matrix2D Add(Matrix2D a, Matrix2D b) { return new Matrix2D( a.M11 + b.M11, a.M12 + b.M12, a.M21 + b.M21, a.M22 + b.M22 ); }
/// <summary> /// Transforms a given vector by a matrix and put the result in a vector. /// </summary> /// <param name="matrix">A <see cref="Matrix2D"/> instance.</param> /// <param name="vector">A <see cref="Vector2D"/> instance.</param> /// <param name="result">A <see cref="Vector2D"/> instance to hold the result.</param> public static void Transform(Matrix2D matrix, Vector2D vector, ref Vector2D result) { result.X = (matrix.M11 * vector.X) + (matrix.M12 * vector.Y); result.Y = (matrix.M21 * vector.X) + (matrix.M22 * vector.Y); }
/// <summary> /// Subtracts a scalar from a matrix. /// </summary> /// <param name="a">A <see cref="Matrix2D"/> instance.</param> /// <param name="s">A scalar.</param> /// <returns>A new <see cref="Matrix2D"/> instance containing the difference.</returns> public static Matrix2D operator-(Matrix2D a, double s) { return(Matrix2D.Subtract(a, s)); }
/// <summary> /// Transforms a given vector by a matrix. /// </summary> /// <param name="matrix">A <see cref="Matrix2D"/> instance.</param> /// <param name="vector">A <see cref="Vector2D"/> instance.</param> /// <returns>A new <see cref="Vector2D"/> instance containing the result.</returns> public static Vector2D operator*(Matrix2D matrix, Vector2D vector) { return(Matrix2D.Transform(matrix, vector)); }
/// <summary> /// Subtracts a matrix from a matrix. /// </summary> /// <param name="a">A <see cref="Matrix2D"/> instance to subtract from.</param> /// <param name="b">A <see cref="Matrix2D"/> instance to subtract.</param> /// <returns>A new <see cref="Matrix2D"/> instance containing the difference.</returns> /// <remarks>result[x][y] = a[x][y] - b[x][y]</remarks> public static Matrix2D Subtract(Matrix2D a, Matrix2D b) { return new Matrix2D( a.M11 - b.M11, a.M12 - b.M12, a.M21 - b.M21, a.M22 - b.M22 ); }
/// <summary> /// Adds a matrix and a scalar. /// </summary> /// <param name="a">A <see cref="Matrix2D"/> instance.</param> /// <param name="s">A scalar.</param> /// <returns>A new <see cref="Matrix2D"/> instance containing the sum.</returns> public static Matrix2D operator+(double s, Matrix2D a) { return(Matrix2D.Add(a, s)); }
/// <summary> /// Multiplies two matrices. /// </summary> /// <param name="a">A <see cref="Matrix2D"/> instance.</param> /// <param name="b">A <see cref="Matrix2D"/> instance.</param> /// <returns>A new <see cref="Matrix2D"/> instance containing the result.</returns> public static Matrix2D Multiply(Matrix2D a, Matrix2D b) { return new Matrix2D( a.M11 * b.M11 + a.M12 * b.M21, a.M11 * b.M12 + a.M12 * b.M22, a.M11 * b.M12 + a.M12 * b.M22, a.M21 * b.M12 + a.M22 * b.M22 ); }
/// <summary> /// Multiplies two matrices and put the result in a third matrix. /// </summary> /// <param name="a">A <see cref="Matrix2D"/> instance.</param> /// <param name="b">A <see cref="Matrix2D"/> instance.</param> /// <param name="result">A <see cref="Matrix2D"/> instance to hold the result.</param> public static void Multiply(Matrix2D a, Matrix2D b, ref Matrix2D result) { result.M11 = a.M11 * b.M11 + a.M12 * b.M21; result.M12 = a.M11 * b.M12 + a.M12 * b.M22; result.M21 = a.M11 * b.M12 + a.M12 * b.M22; result.M22 = a.M21 * b.M12 + a.M22 * b.M22; }
/// <summary> /// Adds a matrix and a scalar and put the result in a third matrix. /// </summary> /// <param name="a">A <see cref="Matrix2D"/> instance.</param> /// <param name="s">A scalar.</param> /// <param name="result">A <see cref="Matrix2D"/> instance to hold the result.</param> public static void Add(Matrix2D a, double s, ref Matrix2D result) { result.M11 = a.M11 + s; result.M12 = a.M12 + s; result.M21 = a.M21 + s; result.M22 = a.M22 + s; }
/// <summary> /// Adds two matrices and put the result in a third matrix. /// </summary> /// <param name="a">A <see cref="Matrix2D"/> instance.</param> /// <param name="b">A <see cref="Matrix2D"/> instance.</param> /// <param name="result">A <see cref="Matrix2D"/> instance to hold the result.</param> public static void Add(Matrix2D a, Matrix2D b, ref Matrix2D result) { result.M11 = a.M11 + b.M11; result.M12 = a.M12 + b.M12; result.M21 = a.M21 + b.M21; result.M22 = a.M22 + b.M22; }
/// <summary> /// Adds a matrix and a scalar. /// </summary> /// <param name="a">A <see cref="Matrix2D"/> instance.</param> /// <param name="s">A scalar.</param> /// <returns>A new <see cref="Matrix2D"/> instance containing the sum.</returns> public static Matrix2D Add(Matrix2D a, double s) { return new Matrix2D( a.M11 + s, a.M12 + s, a.M21 + s, a.M22 + s ); }
/// <summary> /// Subtracts a scalar from a matrix. /// </summary> /// <param name="a">A <see cref="Matrix2D"/> instance.</param> /// <param name="s">A scalar.</param> /// <returns>A new <see cref="Matrix2D"/> instance containing the difference.</returns> public static Matrix2D Subtract(Matrix2D a, double s) { return new Matrix2D( a.M11 - s, a.M12 - s, a.M21 - s, a.M22 - s ); }
/// <summary> /// Adds two matrices. /// </summary> /// <param name="a">A <see cref="Matrix2D"/> instance.</param> /// <param name="b">A <see cref="Matrix2D"/> instance.</param> /// <returns>A new <see cref="Matrix2D"/> instance containing the sum.</returns> public static Matrix2D operator+(Matrix2D a, Matrix2D b) { return(Matrix2D.Add(a, b)); }
/// <summary> /// Subtracts a matrix from a matrix and put the result in a third matrix. /// </summary> /// <param name="a">A <see cref="Matrix2D"/> instance to subtract from.</param> /// <param name="b">A <see cref="Matrix2D"/> instance to subtract.</param> /// <param name="result">A <see cref="Matrix2D"/> instance to hold the result.</param> /// <remarks>result[x][y] = a[x][y] - b[x][y]</remarks> public static void Subtract(Matrix2D a, Matrix2D b, ref Matrix2D result) { result.M11 = a.M11 - b.M11; result.M12 = a.M12 - b.M12; result.M21 = a.M21 - b.M21; result.M22 = a.M22 - b.M22; }
/// <summary> /// Subtracts a matrix from a matrix. /// </summary> /// <param name="a">A <see cref="Matrix2D"/> instance.</param> /// <param name="b">A <see cref="Matrix2D"/> instance.</param> /// <returns>A new <see cref="Matrix2D"/> instance containing the difference.</returns> public static Matrix2D operator-(Matrix2D a, Matrix2D b) { return(Matrix2D.Subtract(a, b)); }
/// <summary> /// Subtracts a scalar from a matrix and put the result in a third matrix. /// </summary> /// <param name="a">A <see cref="Matrix2D"/> instance.</param> /// <param name="s">A scalar.</param> /// <param name="result">A <see cref="Matrix2D"/> instance to hold the result.</param> public static void Subtract(Matrix2D a, double s, ref Matrix2D result) { result.M11 = a.M11 - s; result.M12 = a.M12 - s; result.M21 = a.M21 - s; result.M22 = a.M22 - s; }
/// <summary> /// Multiplies two matrices. /// </summary> /// <param name="a">A <see cref="Matrix2D"/> instance.</param> /// <param name="b">A <see cref="Matrix2D"/> instance.</param> /// <returns>A new <see cref="Matrix2D"/> instance containing the result.</returns> public static Matrix2D operator*(Matrix2D a, Matrix2D b) { return(Matrix2D.Multiply(a, b)); }
/// <summary> /// Transforms a given vector by a matrix. /// </summary> /// <param name="matrix">A <see cref="Matrix2D"/> instance.</param> /// <param name="vector">A <see cref="Vector2D"/> instance.</param> /// <returns>A new <see cref="Vector2D"/> instance containing the result.</returns> public static Vector2D Transform(Matrix2D matrix, Vector2D vector) { return new Vector2D( (matrix.M11 * vector.X) + (matrix.M12 * vector.Y), (matrix.M21 * vector.X) + (matrix.M22 * vector.Y)); }
/// <summary> /// Initializes a new instance of the <see cref="Matrix2D"/> class using a given matrix. /// </summary> public Matrix2D(Matrix2D m) { _m11 = m.M11; _m12 = m.M12; _m21 = m.M21; _m22 = m.M22; }