コード例 #1
0
        /// <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;
             */
        }
コード例 #2
0
        /// <summary>
        /// Construct a translation that displaces any point by the amount specified by the vector "v"
        /// <param name="v">The displacement vector</param>
        /// <returns>The translation transform. </returns>
        /// </summary>
        public static ProjectiveTransform2 Translate(Vector v)
        {
            AffineTransform2     T  = AffineTransform2.Translate(v);
            ProjectiveTransform2 T2 = new ProjectiveTransform2();

            T2.mat = T.mat;
            T.mat  = null;
            return(T2);
        }
コード例 #3
0
        /// <summary>
        /// Construct a translation that displaces the Point p to the Point q
        /// <param name="P">A point that will be translated.</param>
        /// <param name="Q">The point where P will end up after translation.</param>
        /// <returns>The translation transform. </returns>
        /// </summary>
        public static ProjectiveTransform2 Translate(Point p, Point q)
        {
            AffineTransform2     T  = AffineTransform2.Translate(p, q);
            ProjectiveTransform2 T2 = new ProjectiveTransform2();

            T2.mat = T.mat;
            T.mat  = null;
            return(T2);
        }
コード例 #4
0
        private static void testAT()
        {
            // Results: inverse is broken for LinearTransform; otherwise OK.
            Debug.Print("T0:" + new AffineTransform2() + "\nshould be identity\n");
            Vector v1 = new Vector(2, 3); Vector v2 = new Vector(-1, 4);
            Vector w1 = new Vector(0, 1); Vector w2 = new Vector(1, 1);
            Point  p1 = new Point(1, 5);
            Point  p2 = new Point(1, 1);
            Point  p3 = new Point(4, 4);
            Point  p4 = new Point(2, 5);
            Point  q1 = new Point(1, 1);
            Point  q2 = new Point(0, 0);
            Point  q3 = new Point(1, 2);
            Point  q4 = new Point(-1, 0);
            Point  pt = p1 + 0.5 * (p2 - p1);
            Point  qt = q1 + 0.5 * (q2 - q1);

            AffineTransform2 T1 = AffineTransform2.Translate(p1, q1);

            Debug.Print("T1:" + T1 * p1 + "\n should be " + q1 + "\n");
            AffineTransform2 T2 = AffineTransform2.PointAndVectorsToPointAndVectors(p1, v1, v2, q1, w1, w2);

            Debug.Print("T2:" + T2 * (v1 + v2) + "\n should be " + (w1 + w2) + "\n"); /// Broken
            Debug.Print("T2:" + T2 * p1 + "\n should be " + q1 + "\n");
            AffineTransform2 T3 = AffineTransform2.RotateXY(30 * Math.PI / 180);
            LinearTransform2 T4 = LinearTransform2.RotateXY(30 * Math.PI / 180);

            Debug.Print("T3,4:" + T3 + "\n should equal " + T4 + "\n");
            AffineTransform2 T5 = AffineTransform2.AxisScale(2, -3);

            Debug.Print("T5:" + T5 + "\n should be [2 0 ; 0 -3]\n");
            AffineTransform2 T6 = AffineTransform2.RotateAboutPoint(p1, 30 * Math.PI / 180);

            Debug.Print("T6:" + T6 * p1 + "\n should be " + p1 + "\n");
            Debug.Print("T6:" + T6 * new Vector(1, 0) + "\n should be [.866, .5]\n");

            AffineTransform2 TPV = AffineTransform2.PointAndVectorsToPointAndVectors(p1, v1, v2, q1, w1, w2); // Broken

            Debug.Print("TPV:" + TPV * p1 + "\n should be " + q1 + "\n");
            Debug.Print("TPV:" + TPV * (p1 + 0.3 * v2) + "\n should be " + (q1 + 0.3 * w2) + "\n");

            AffineTransform2 T7 = AffineTransform2.PointsToPoints(p1, p2, p3, q1, q2, q3);

            Debug.Print("T7:" + T7 * pt + "\n should be " + qt + "\n");
            Debug.Print("T7:" + T7 * p1 + "\n should be " + q1 + "\n");
            Debug.Print("T7:" + T7 * p2 + "\n should be " + q2 + "\n");
            Debug.Print("T7:" + T7 * p3 + "\n should be " + q3 + "\n");
            Debug.Print("Inverse:" + T7 * (T7.InverseTransform()) + "\n should be identity\n"); //BROKEN
            AffineTransform2 T7i = T7.InverseTransform();

            Debug.Print("T7i:" + T7i * q1 + "\n should be " + p1 + "\n");
            Debug.Print("T7i:" + T7i * q2 + "\n should be " + p2 + "\n");
            Debug.Print("T7i:" + T7i * q3 + "\n should be " + p3 + "\n");

            AffineTransform2 T8 = AffineTransform2.PointsAndVectorToPointsAndVector(p1, p2, p3 - p1, q1, q2, q3 - q1);

            Debug.Print("T8:" + T7 * (T8.InverseTransform()) + "\n should be identity\n"); //BROKEN
            Debug.Print("T8:" + T8 * p1 + "\n should be " + q1 + "\n");
            Debug.Print("T8:" + T8 * p2 + "\n should be " + q2 + "\n");
            Debug.Print("T8:" + T8 * p3 + "\n should be " + q3 + "\n");
        }