Graphics Reference
In-Depth Information
13.2 A 2D Example
While Chapter 10 showed how to build transformations and compose them, it's
often easiest to use a higher-level construction to build transformations: Rather
than saying how to create a transformation as a sequence of elementary trans-
formations, we say what we want the transformation to accomplish. Using our
linear algebra package (see Chapter 12), we can simply say that we want a linear
map that takes certain points to certain others, and let the package find the unique
solution to this problem.
Suppose we want to map the square
(0,0)
Pixel (0,0)
1 (which we'll call the
imaging rectangle in anticipation of a later use of such a transformation) to a
display with square pixels, 1024 pixels wide, 768 pixels tall. The upper-left pixel is
called ( 0, 0 ) ; the lower-left is ( 0, 767 ) ; and the lower-right is ( 1023, 767 ) . We want
to find a transformation T with the property that it sends the square
1
u , v
(0.5, 0.5) (1.5, 0.5)
1
to a square region on the left-hand side of the display, one that fills as much of
the display as possible. To do so, we need coordinates on the plane of the display.
Because pixel coordinates refer to the upper-left corner of each pixel, as shown in
Figure 13.1, that is, the center of pixel ( 0, 0 ) is at ( 0.5, 0.5 ) , the display coordinates
range from ( 0, 0 ) to ( 1024, 768 ) .
1
u , v
Figure 13.1: The center of the
upper-left pixel has coordinates
( 0. 5, 0. 5 ) ; the pixel is called
pixel (0,0). In other words, it is
named by its upper-left corner.
1 ) (the lower-left corner of the imag-
ing rectangle) to be sent to ( 0, 768 ) (the lower-left corner of the display), and we
want (
This means that we want the point (
1,
1, 1 ) (the upper-left corner) to be sent to ( 0, 0 ) . To completely specify an
affine transformation on a two-dimensional space, we need to know where three
independent points are sent. We've already determined where two are sent. For
our third point, we choose the lower-right corner: ( 1,
1 ) must go to ( 768, 768 )
(to keep the image square). The code that implements this is
1
2
3
4
Transform t =
Transform.PointsToPoints(
Point2(-1, -1),
Point2(-1, 1),
Point2(1, -1),
Point2(0, 768),
Point2(0, 0),
Point2(768, 768));
For a specification like this (specifying which points go to which points) we
must be certain that the source points constitute a coordinate frame; in two dimen-
sions, this means “noncollinear,” which is clearly the case here: Any three corners
of a square are noncollinear.
The obvious generalization of this to an arbitrary viewing window of r rows by
k columns (without the constraint on squareness) is called the windowing trans-
formation, with matrix M wind . It can be generated by code like
1
2
3
4
Transform t =
Transform.PointsToPoints(
Point2(-1, -1),
Point2(-1, 1),
Point2(1, -1),
Point2(0, k),
Point2(0, 0),
Point2(r, k));
or, for those who prefer the matrix to be expressed directly, as
= 1
2
M wind = r 00
0
1
2
1
2
r
.
0
0
r
1
2
001
1
2
(13.1)
0
k
0
0
kk
 
 
 
Search WWH ::




Custom Search