示例#1
0
        /// <summary>
        /// Converts the specified string to its <see cref="Matrix2"/> equivalent.
        /// A return value indicates whether the conversion succeeded or failed.
        /// </summary>
        /// <param name="value">A string representation of a <see cref="Matrix2"/>.</param>
        /// <param name="result">
        /// When this method returns, if the conversion succeeded,
        /// contains a <see cref="Matrix2"/> 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 Matrix2 result)
        {
            Regex r = new Regex(regularExp, RegexOptions.Singleline);
            Match m = r.Match(value);

            if (m.Success)
            {
                result = new Matrix2(
                    float.Parse(m.Result("${m11}")),
                    float.Parse(m.Result("${m12}")),

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

                return(true);
            }

            result = Matrix2.Zero;
            return(false);
        }
示例#2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Matrix2"/> class using a given matrix.
 /// </summary>
 public Matrix2(Matrix2 m)
 {
     _m11 = m.M11; _m12 = m.M12;
     _m21 = m.M21; _m22 = m.M22;
 }
示例#3
0
 /// <summary>
 /// Transforms a given vector by a matrix.
 /// </summary>
 /// <param name="matrix">A <see cref="Matrix2"/> instance.</param>
 /// <param name="vector">A <see cref="Vector2"/> instance.</param>
 /// <returns>A new <see cref="Vector2"/> instance containing the result.</returns>
 public static Vector2 operator *(Matrix2 matrix, Vector2 vector)
 {
     return(Matrix2.Transform(matrix, vector));
 }
示例#4
0
 /// <summary>
 /// Multiplies two matrices.
 /// </summary>
 /// <param name="left">A <see cref="Matrix2"/> instance.</param>
 /// <param name="right">A <see cref="Matrix2"/> instance.</param>
 /// <returns>A new <see cref="Matrix2"/> instance containing the result.</returns>
 public static Matrix2 operator *(Matrix2 left, Matrix2 right)
 {
     return(Matrix2.Multiply(left, right));
 }
示例#5
0
 /// <summary>
 /// Subtracts a scalar from a matrix.
 /// </summary>
 /// <param name="matrix">A <see cref="Matrix2"/> instance.</param>
 /// <param name="scalar">A single-precision floating-point number.</param>
 /// <returns>A new <see cref="Matrix2"/> instance containing the difference.</returns>
 public static Matrix2 operator -(Matrix2 matrix, float scalar)
 {
     return(Matrix2.Subtract(matrix, scalar));
 }
示例#6
0
 /// <summary>
 /// Subtracts a matrix from a matrix.
 /// </summary>
 /// <param name="left">A <see cref="Matrix2"/> instance.</param>
 /// <param name="right">A <see cref="Matrix2"/> instance.</param>
 /// <returns>A new <see cref="Matrix2"/> instance containing the difference.</returns>
 public static Matrix2 operator -(Matrix2 left, Matrix2 right)
 {
     return(Matrix2.Subtract(left, right));
 }
示例#7
0
 /// <summary>
 /// Adds a matrix and a scalar.
 /// </summary>
 /// <param name="matrix">A <see cref="Matrix2"/> instance.</param>
 /// <param name="scalar">A single-precision floating-point number.</param>
 /// <returns>A new <see cref="Matrix2"/> instance containing the sum.</returns>
 public static Matrix2 operator +(float scalar, Matrix2 matrix)
 {
     return(Matrix2.Add(matrix, scalar));
 }
示例#8
0
 /// <summary>
 /// Adds two matrices.
 /// </summary>
 /// <param name="left">A <see cref="Matrix2"/> instance.</param>
 /// <param name="right">A <see cref="Matrix2"/> instance.</param>
 /// <returns>A new <see cref="Matrix2"/> instance containing the sum.</returns>
 public static Matrix2 operator +(Matrix2 left, Matrix2 right)
 {
     return(Matrix2.Add(left, right));
 }
示例#9
0
 /// <summary>
 /// Transforms a given vector by a matrix and put the result in a vector.
 /// </summary>
 /// <param name="matrix">A <see cref="Matrix2"/> instance.</param>
 /// <param name="vector">A <see cref="Vector2"/> instance.</param>
 /// <param name="result">A <see cref="Vector2"/> instance to hold the result.</param>
 public static void Transform(Matrix2 matrix, Vector2 vector, ref Vector2 result)
 {
     result.X = (matrix.M11 * vector.X) + (matrix.M12 * vector.Y);
     result.Y = (matrix.M21 * vector.X) + (matrix.M22 * vector.Y);
 }
示例#10
0
 /// <summary>
 /// Transforms a given vector by a matrix.
 /// </summary>
 /// <param name="matrix">A <see cref="Matrix2"/> instance.</param>
 /// <param name="vector">A <see cref="Vector2"/> instance.</param>
 /// <returns>A new <see cref="Vector2"/> instance containing the result.</returns>
 public static Vector2 Transform(Matrix2 matrix, Vector2 vector)
 {
     return(new Vector2(
                (matrix.M11 * vector.X) + (matrix.M12 * vector.Y),
                (matrix.M21 * vector.X) + (matrix.M22 * vector.Y)));
 }