Example #1
0
 public Matrix2x2(Matrix2x2 m)
 {
     a11 = m.a11;
     a12 = m.a12;
     a21 = m.a21;
     a22 = m.a22;
 }
Example #2
0
        public static Matrix2x2 inv(Matrix2x2 m)
        {
            double det = m.det;

            if (det == 0)
            {
                throw new Exception("Division by Zero in Matrix2x2 Inversion");
            }
            return(new Matrix2x2(m.a22 / det, -m.a12 / det, -m.a21 / det, m.a11 / det));
        }
Example #3
0
        public static bool intersect(VectorLine U, VectorLine V, ref Vector ip)
        {
            if (!U.isLine || !V.isLine)
            {
                return(false);
            }

            Matrix2x2 M   = new Matrix2x2(V.B - V.A, U.A - U.B);
            Vector    Q   = U.A - V.A;
            double    det = M.det;

            if (det == 0)
            {
                return(false); // parallel or overlapping
            }
            Vector st = Matrix2x2.inv(M) * Q;

            if (U.isOnLine(st.y) && V.isOnLine(st.x))
            {
                ip = U.A + (U.B - U.A) * st.y;
                return(true);
            }
            return(false);
        }