/// <summary>
        /// Given a point p and linearly independent vectors v1 and v2, build the unique transformation taking p to q, 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 PointsAndVectorToPointsAndVector(
            Point p1, Point p2, Vector v1,
            Point q1, Point q2, Vector w1)
        {
            Vector v2 = p2 - p1;
            Vector w2 = q2 - q1;

            return(AffineTransform2.PointAndVectorsToPointAndVectors(p1, v1, v2, q1, w1, w2));
        }
        /// <summary>
        /// Build the unique transformation taking three independent points to any three other points.
        /// <param name="p1">The 1st point to be moved</param>
        /// <param name="p2">The 2nd point to be moved</param>
        /// <param name="p3">The 3rd point to be moved</param>
        /// <param name="q1">The point to which p1 will be moved</param>
        /// <param name="q2">The point to which p2 will be moved</param>
        /// <param name="q3">The point to which p3 will be moved</param>
        /// <returns>The affine transform. </returns>
        /// </summary>
        public static AffineTransform2 PointsToPoints(
            Point p1, Point p2, Point p3,
            Point q1, Point q2, Point q3)
        {
            Vector v1 = p2 - p1;
            Vector v2 = p3 - p1;
            Vector w1 = q2 - q1;
            Vector w2 = q3 - q1;

            return(AffineTransform2.PointAndVectorsToPointAndVectors(p1, v1, v2, q1, w1, w2));
        }
예제 #3
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");
        }