public static LinearTransform2 VectorsToVectors(Vector v1, Vector v2, Vector w1, Vector w2)
        {
            LinearTransform2 V = new LinearTransform2(v1, v2);
            LinearTransform2 W = new LinearTransform2(w1, w2);

            return(W * V.InverseTransform());
        }
        public static LinearTransform2 operator *(LinearTransform2 T1, LinearTransform2 T2)
        {
            LinearTransform2 S = new LinearTransform2();

            S.mat = MatrixProduct(T1.mat, T2.mat);
            return(S);
        }
Пример #3
0
        public static AffineTransform2 PointAndVectorsToPointAndVectors(
            Point p1, Vector v1, Vector v2,
            Point q1, Vector w1, Vector w2)
        {
            AffineTransform2 Trans1 = AffineTransform2.Translate(p1, new Point(0, 0));
            LinearTransform2 T      = LinearTransform2.VectorsToVectors(v1, v2, w1, w2);
            AffineTransform2 Trans2 = AffineTransform2.Translate(new Point(0, 0), q1);
            AffineTransform2 S      = new AffineTransform2();

            S.mat = T.Matrix();

            return(Trans2 * S * Trans1);

            /*
             * double[,] linmat = T.Matrix();
             * for (int i = 0; i < 2; i++)
             * {
             *  for (int j = 0; j < 2; j++)
             *  {
             *      W.mat[i, j] = linmat[i, j];
             *  }
             * }
             * return W;
             */
        }
        public LinearTransform2 InverseTransform()
        {
            double[,] m = MatrixInverse(mat);
            LinearTransform2 T = new LinearTransform2();

            T.mat = m;
            return(T);
        }
        public static LinearTransform2 RotateXY(double angle)
        {
            LinearTransform2 T = new LinearTransform2();

            T.mat[0, 0] = Math.Cos(angle);
            T.mat[1, 1] = T.mat[0, 0];
            T.mat[1, 0] = Math.Sin(angle);
            T.mat[0, 1] = -T.mat[1, 0];
            return(T);
        }
        public static ProjectiveTransform2 StandardFrameToPoints(Point p0, Point p1, Point p2, Point p3)
        {
            //
            ProjectiveTransform2 T = new ProjectiveTransform2();
            // idea:
            // Send e1, e2, e3 to p0, p1, p2 by a map K.
            // Let L be Kinverse.
            // Then L sends p0, p1, p2 to e1, e2 and e3 . See where p4 goes; call this q.
            // build projective map P sending e1, e2, e3, and u= (e1+e2+e3) to e1, e2, e3, and q.
            // then let L = Kinverse; K * P sends e1 to p1; e2 to p2; e3 to p3; and u to q to e4.
            ProjectiveTransform2 K = new ProjectiveTransform2();

            for (int i = 0; i < 3; i++)
            {
                K.mat[2, i] = 1.0d;
            }
            K.mat[0, 0] = p0.X;
            K.mat[1, 0] = p0.Y;
            K.mat[0, 1] = p1.X;
            K.mat[1, 1] = p1.Y;
            K.mat[0, 2] = p2.X;
            K.mat[1, 2] = p2.Y;

            ProjectiveTransform2 L = new ProjectiveTransform2();

            L.mat = LinearTransform2.MatrixInverse(K.mat);
            double[] v = new double[3];
            v[0] = p3.X;
            v[1] = p3.Y;
            v[2] = 1.0d;

            double[] q = new double[3];
            for (int i = 0; i < 3; i++)
            {
                double tally = 0.0d;
                for (int j = 0; j < 3; j++)
                {
                    tally += L.mat[i, j] * v[j];
                }
                q[i] = tally;
            }
            double[,] p = new double[3, 3];
            for (int i = 0; i < 3; i++)
            {
                p[i, i] = q[i];
            }
            ProjectiveTransform2 S = new ProjectiveTransform2();

            S.mat = ProjectiveTransform2.MatrixProduct(K.mat, p);
            return(S);
        }
Пример #7
0
        new private static double[,] MatrixInverse(double[,] mat)
        {
            double[] translation = new double[3];
            translation[0] = mat[0, 2];
            translation[1] = mat[1, 2];
            translation[2] = 1.0d;

            double[,] mm = new double[3, 3];
            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    mm[i, j] = mat[i, j];
                }
            }
            mm[2, 2] = 1.0d;

            double[,] minv = LinearTransform2.MatrixInverse(mm);
            double[] reverseTranslation = new double[3];
            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    reverseTranslation[i] -= minv[i, j] * translation[j];
                }
            }
            reverseTranslation[2] = 1.0d;


            double[,] res = new double[3, 3];
            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    res[i, j] = minv[i, j];
                }
                res[i, 2] = reverseTranslation[i];
            }
            res[2, 2] = 1.0d;
            return(res);
        }