Graphics Reference
In-Depth Information
Inline Exercise 12.1: Without looking at the code, consider whether you can
find a more efficient way to invert an affine transformation on R 2 than by invert-
ing its 3
3 matrix. Hint: The bottom row of the matrix is always 001 .
×
12.4 Specification of Transformations
For each kind of transformation, the default constructor generates the identity
transformation. (The constructor for MatrixTransformation2 is protected ,as
only the derived classes are supposed to ever create a MatrixTransformation .)
In general, though, transformations are constructed by static methods with
mnemonic names. For the AffineTransformation2 class, for instance, there are
eight static methods (all public static AffineTransform2 ) that construct trans-
formations.
1
2
3
4
5
6
7
8
9
10
RotateXY(double angle)
Translate(Vector v)
Translate(Point p, Point q)
AxisScale(double x_amount, double y_amount)
RotateAboutPoint(Point p, double angle)
PointsToPoints(Point p1, Point p2, Point p3,Point q1, Point q2, Point q3)
PointAndVectorsToPointAndVectors(Point p1, Vector v1, Vector v2,
Point q1, Vector w1, Vector w2)
PointsAndVectorToPointsAndVector(Point p1, Point p2, Vector v1,
Point q1, Point q2, Vector w1)
The naming convention is straightforward: “From” comes before “to” so that
Translate(Point p, Point q)
creates a translation that sends p to q , and within a collection of arguments, points
come before vectors so that in
PointAndVectorsToPointAndVectors
the point p1 is sent to the point q1 , the vector v1 is sent to the vector w1 , and the
vector v2 is sent to the vector w2 . The method name tells you that there is one point
and more than one vector; since an affine transformation of the plane is determined
by its values on three points, or one point and two vectors, or two points and one
vector, you know that the arguments must be one point and two vectors.
Methods that produce particular familiar transformations—translations, rota-
tions, axis-aligned scales—have names indicating these. While the names are
sometimes cumbersome, they are also expressive; it's easy to understand code
that uses them.
12.5 Implementation
Most of the transformations are easy to implement. For instance, we first imple-
mented the
 
 
 
 
Search WWH ::




Custom Search