Example #1
0
        public static Matrix2x2d PolarDecomposition(Matrix2x2d m)
        {
            Matrix2x2d q = m + new Matrix2x2d(m.m11, -m.m10, -m.m01, m.m00);

            Vector2d c0 = q.GetColumn(0);
            Vector2d c1 = q.GetColumn(1);

            double s = c0.Magnitude;

            q.SetColumn(0, c0 / s);
            q.SetColumn(1, c1 / s);

            return(q);
        }
        /// <summary>
        /// The Inverse of the matrix copied into mInv.
        /// Returns false if the matrix has no inverse.
        /// A matrix multipled by its inverse is the idenity.
        /// </summary>
        public bool TryInverse(ref Matrix2x2d mInv)
        {
            double det = Determinant;

            if (Math.Abs(det) <= 1e-09)
            {
                return(false);
            }

            double invDet = 1.0 / det;

            mInv.m00 = m11 * invDet;
            mInv.m01 = -m01 * invDet;
            mInv.m10 = -m10 * invDet;
            mInv.m11 = m00 * invDet;
            return(true);
        }
        /// <summary>
        /// Are these matrices equal.
        /// </summary>
        public bool EqualsWithError(Matrix2x2d m, double eps)
        {
            if (Math.Abs(m00 - m.m00) > eps)
            {
                return(false);
            }
            if (Math.Abs(m10 - m.m10) > eps)
            {
                return(false);
            }
            if (Math.Abs(m01 - m.m01) > eps)
            {
                return(false);
            }
            if (Math.Abs(m11 - m.m11) > eps)
            {
                return(false);
            }

            return(true);
        }
 /// <summary>
 /// A matrix copied from the matrix m.
 /// </summary>
 public Matrix2x2d(Matrix2x2d m)
 {
     m00 = m.m00; m01 = m.m01;
     m10 = m.m10; m11 = m.m11;
 }
 /// <summary>
 /// Are these matrices equal.
 /// </summary>
 public bool Equals(Matrix2x2d mat)
 {
     return(this == mat);
 }