/// <summary>
        /// Given a point p1 and linearly independent vectors v1 and v2, build the unique transformation taking p1 to q1, v1 to w1, and v2 to w2.
        /// <param name="p1">The point to be moved</param>
        /// <param name="v1">The first vector</param>
        /// <param name="v2">The second vector</param>
        /// <param name="q1">The point to which p1 will be moved</param>
        /// <param name="w1">The vector to which v1 will be moved</param>
        /// <param name="w2">The vector to which v2 will be moved</param>
        /// <returns>The affine transform. </returns>
        /// </summary>
        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;
             */
        }
Exemplo n.º 2
0
        private static void testLT()
        {
            // Results: inverse is broken for LinearTransform; otherwise OK.
            Debug.Print(new LinearTransform2() + "\nshould be identity\n");
            Vector           v1 = new Vector(2, 3); Vector v2 = new Vector(-1, 4);
            LinearTransform2 T1 = new LinearTransform2(v1, v2);

            Debug.Print(T1 + "\nshould be 2, -1; 3 4.\n");
            Debug.Print(T1.Det() + "\n should be 11; " + T1.Trace() + "\nshould be 6\n");
            Vector           w1 = new Vector(0, 1); Vector w2 = new Vector(1, 1);
            LinearTransform2 Tvw = LinearTransform2.VectorsToVectors(v1, v2, w1, w2);
            LinearTransform2 T30 = LinearTransform2.RotateXY(30 * Math.PI / 180.0);
            LinearTransform2 Ti  = T1.InverseTransform();

            Debug.Print(T30 + "\nshould be Rot30; lower left = 0.5\n");
            Debug.Print(Ti * v1 + "\nshould be e1\n");
            Debug.Print(Ti * v2 + "\nshould be e2\n");
            Debug.Print(T1 * T1 + "\nshould be [1 -6; 18 13]\n");
            Debug.Print(T1 * Ti + "\n should be identity\n");
        }