Example #1
0
 /// <summary>
 /// Subtracts a matrix from a matrix.
 /// </summary>
 /// <param name="left">A <see cref="Matrix2D"/> instance.</param>
 /// <param name="right">A <see cref="Matrix2D"/> instance.</param>
 /// <returns>A new <see cref="Matrix2D"/> instance containing the difference.</returns>
 public static Matrix2D operator -(Matrix2D left, Matrix2D right)
 {
     return(Matrix2D.Subtract(left, right));;
 }
Example #2
0
 /// <summary>
 /// Multiplies two matrices.
 /// </summary>
 /// <param name="left">A <see cref="Matrix2D"/> instance.</param>
 /// <param name="right">A <see cref="Matrix2D"/> instance.</param>
 /// <returns>A new <see cref="Matrix2D"/> instance containing the result.</returns>
 public static Matrix2D operator *(Matrix2D left, Matrix2D right)
 {
     return(Matrix2D.Multiply(left, right));;
 }
Example #3
0
 /// <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)));
 }
Example #4
0
 /// <summary>
 /// Adds two matrices.
 /// </summary>
 /// <param name="left">A <see cref="Matrix2D"/> instance.</param>
 /// <param name="right">A <see cref="Matrix2D"/> instance.</param>
 /// <returns>A new <see cref="Matrix2D"/> instance containing the sum.</returns>
 public static Matrix2D operator +(Matrix2D left, Matrix2D right)
 {
     return(Matrix2D.Add(left, right));;
 }
Example #5
0
		/// <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);
		}
Example #6
0
		/// <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;
		}
Example #7
0
		/// <summary>
		/// Converts the specified string to its <see cref="Matrix2D"/> equivalent.
		/// A return value indicates whether the conversion succeeded or failed.
		/// </summary>
		/// <param name="value">A string representation of a <see cref="Matrix2D"/>.</param>
		/// <param name="result">
		/// When this method returns, if the conversion succeeded,
		/// contains a <see cref="Matrix2D"/> 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 Matrix2D result)
		{
			Regex r = new Regex(regularExp, RegexOptions.Singleline);
			Match m = r.Match(value);
			if (m.Success)
			{
				result = new Matrix2D(
					double.Parse(m.Result("${m11}")),
					double.Parse(m.Result("${m12}")),

					double.Parse(m.Result("${m21}")),
					double.Parse(m.Result("${m22}"))
					);

				return true;
			}

			result = Matrix2D.Zero;
			return false;
		}
Example #8
0
		/// <summary>
		/// Multiplies two matrices and put the result in a third matrix.
		/// </summary>
		/// <param name="left">A <see cref="Matrix2D"/> instance.</param>
		/// <param name="right">A <see cref="Matrix2D"/> instance.</param>
		/// <param name="result">A <see cref="Matrix2D"/> instance to hold the result.</param>
		public static void Multiply(Matrix2D left, Matrix2D right, ref Matrix2D 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;
		}
Example #9
0
 /// <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));
 }
Example #10
0
 /// <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));
 }
Example #11
0
 /// <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));
 }
Example #12
0
 /// <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));
 }
Example #13
0
 /// <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));
 }
Example #14
0
		/// <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+(Matrix2D a, double s)
		{
			return Matrix2D.Add(a,s);
		}
Example #15
0
		/// <summary>
		/// Adds two matrices.
		/// </summary>
		/// <param name="left">A <see cref="Matrix2D"/> instance.</param>
		/// <param name="right">A <see cref="Matrix2D"/> instance.</param>
		/// <returns>A new <see cref="Matrix2D"/> instance containing the sum.</returns>
		public static Matrix2D Add(Matrix2D left, Matrix2D right)
		{
			return new Matrix2D(
				left.M11 + right.M11, left.M12 + right.M12, 
				left.M21 + right.M21, left.M22 + right.M22
				);
		}
Example #16
0
		/// <summary>
		/// Multiplies two matrices.
		/// </summary>
		/// <param name="left">A <see cref="Matrix2D"/> instance.</param>
		/// <param name="right">A <see cref="Matrix2D"/> instance.</param>
		/// <returns>A new <see cref="Matrix2D"/> instance containing the result.</returns>
		public static Matrix2D Multiply(Matrix2D left, Matrix2D right)
		{
			return new Matrix2D(
				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
				);
		}
Example #17
0
		/// <summary>
		/// Adds a matrix and a scalar.
		/// </summary>
		/// <param name="matrix">A <see cref="Matrix2D"/> instance.</param>
		/// <param name="scalar">A double-precision floating-point number.</param>
		/// <returns>A new <see cref="Matrix2D"/> instance containing the sum.</returns>
		public static Matrix2D Add(Matrix2D matrix, double scalar)
		{
			return new Matrix2D(
				matrix.M11 + scalar, matrix.M12 + scalar, 
				matrix.M21 + scalar, matrix.M22 + scalar 
				);
		}
Example #18
0
		/// <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));
		}
Example #19
0
		/// <summary>
		/// Adds two matrices and put the result in a third matrix.
		/// </summary>
		/// <param name="left">A <see cref="Matrix2D"/> instance.</param>
		/// <param name="right">A <see cref="Matrix2D"/> instance.</param>
		/// <param name="result">A <see cref="Matrix2D"/> instance to hold the result.</param>
		public static void Add(Matrix2D left, Matrix2D right, ref Matrix2D 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;
		}
Example #20
0
		/// <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;
		}
Example #21
0
		/// <summary>
		/// Adds a matrix and a scalar and put the result in a third matrix.
		/// </summary>
		/// <param name="matrix">A <see cref="Matrix2D"/> instance.</param>
		/// <param name="scalar">A double-precision floating-point number.</param>
		/// <param name="result">A <see cref="Matrix2D"/> instance to hold the result.</param>
		public static void Add(Matrix2D matrix, double scalar, ref Matrix2D result)
		{
			result.M11 = matrix.M11 + scalar;
			result.M12 = matrix.M12 + scalar;

			result.M21 = matrix.M21 + scalar;
			result.M22 = matrix.M22 + scalar;
		}
Example #22
0
 /// <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;
 }
Example #23
0
		/// <summary>
		/// Subtracts a matrix from a matrix.
		/// </summary>
		/// <param name="left">A <see cref="Matrix2D"/> instance to subtract from.</param>
		/// <param name="right">A <see cref="Matrix2D"/> instance to subtract.</param>
		/// <returns>A new <see cref="Matrix2D"/> instance containing the difference.</returns>
		/// <remarks>result[x][y] = left[x][y] - right[x][y]</remarks>
		public static Matrix2D Subtract(Matrix2D left, Matrix2D right)
		{
			return new Matrix2D(
				left.M11 - right.M11, left.M12 - right.M12, 
				left.M21 - right.M21, left.M22 - right.M22
				);
		}
Example #24
0
 /// <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);
 }
Example #25
0
		/// <summary>
		/// Subtracts a scalar from a matrix.
		/// </summary>
		/// <param name="matrix">A <see cref="Matrix2D"/> instance.</param>
		/// <param name="scalar">A double-precision floating-point number.</param>
		/// <returns>A new <see cref="Matrix2D"/> instance containing the difference.</returns>
		public static Matrix2D Subtract(Matrix2D matrix, double scalar)
		{
			return new Matrix2D(
				matrix.M11 - scalar, matrix.M12 - scalar,
				matrix.M21 - scalar, matrix.M22 - scalar
				);
		}
Example #26
0
 /// <summary>
 /// Adds a matrix and a scalar.
 /// </summary>
 /// <param name="matrix">A <see cref="Matrix2D"/> instance.</param>
 /// <param name="scalar">A double-precision floating-point number.</param>
 /// <returns>A new <see cref="Matrix2D"/> instance containing the sum.</returns>
 public static Matrix2D operator +(double scalar, Matrix2D matrix)
 {
     return(Matrix2D.Add(matrix, scalar));
 }
Example #27
0
		/// <summary>
		/// Subtracts a matrix from a matrix and put the result in a third matrix.
		/// </summary>
		/// <param name="left">A <see cref="Matrix2D"/> instance to subtract from.</param>
		/// <param name="right">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] = left[x][y] - right[x][y]</remarks>
		public static void Subtract(Matrix2D left, Matrix2D right, ref Matrix2D 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;
		}
Example #28
0
 /// <summary>
 /// Subtracts a scalar from a matrix.
 /// </summary>
 /// <param name="matrix">A <see cref="Matrix2D"/> instance.</param>
 /// <param name="scalar">A double-precision floating-point number.</param>
 /// <returns>A new <see cref="Matrix2D"/> instance containing the difference.</returns>
 public static Matrix2D operator -(Matrix2D matrix, double scalar)
 {
     return(Matrix2D.Subtract(matrix, scalar));
 }
Example #29
0
		/// <summary>
		/// Subtracts a scalar from a matrix and put the result in a third matrix.
		/// </summary>
		/// <param name="matrix">A <see cref="Matrix2D"/> instance.</param>
		/// <param name="scalar">A double-precision floating-point number.</param>
		/// <param name="result">A <see cref="Matrix2D"/> instance to hold the result.</param>
		public static void Subtract(Matrix2D matrix, double scalar, ref Matrix2D result)
		{
			result.M11 = matrix.M11 - scalar;
			result.M12 = matrix.M12 - scalar;

			result.M21 = matrix.M21 - scalar;
			result.M22 = matrix.M22 - scalar;
		}
Example #30
0
 /// <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));
 }
Example #31
0
		/// <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;
		}