Chapter 6

Moving Things Around: Affine Maps in 2D

Imagine playing a video game. As you press a button, figures and objects on the screen start moving around; they shift their positions, they rotate, they zoom in or out. As you see this kind of motion, the game software must carry out quite a few transformations. In Figure 6.1, they have been applied to a familiar face in gaming. These computations are implementations of affine maps, the subject of this chapter.

Figure 6.1

Figure showing moving things around: affine maps in 2D applied to an old and familiar video game character.

Moving things around: affine maps in 2D applied to an old and familiar video game character.

6.1 Coordinate Transformations

In Section 4.1 the focus was on constructing a linear map that takes a vector v in the [e1, e2]-system,

v=v1e1+v2e2,

to a vector v′ in the [a1, a2]-system

v=v1a1+v2a2.

Recall that this latter system describes a parallelogram (skew) target box with lower-left corner at the origin. In this chapter, we want to construct this skew target box anywhere, and we want to map points rather than vectors, as illustrated by Sketch 6.1.

Sketch 6.1

Sketch showing a skew target box.

A skew target box.

Now we will describe a skew target box by a point p and two vectors a1, a2. A point x is mapped to a point x′ by

x=p+x1a1+x2a2,(6.1)

=p+Ax,(6.2)

as illustrated by Sketch 6.1. This simply states that we duplicate the [e1, e2]-geometry in the [a1, a2]-system: x′ has the same coordinates in the new system as x did in the old one. Technically, the linear map A in (6.2) is applied to the vector x − o, so it should be written as

x=p+A(xo),(6.3)

where o is the origin of x’s coordinate system. In most cases, we will have the familiar

o=[00],

and then we will simply drop the “−o” part, as in (6.2).

Affine maps are the basic tools to move and orient objects. All are of the form given in (6.3) and thus have two parts: a translation, given by p, and a linear map, given by A.

Let’s try representing the coordinate transformation of Section 1.1 as an affine map. The point u lives in the [e1, e2]-system, and we wish to find x in the [a1, a2]-system. Recall that the extents of the target box defined Δ1 = max1 − min1 and Δ2 = max2 − min2, so we set

p=[min1min2],a1=[Δ10],a2=[0Δ2].

The affine map is defined as

[x1x2]=[min1min2]+[Δ100Δ2] [u1u2],

and we recover (1.3) and (1.4).

Of course we are not restricted to target boxes that are parallel to the [e1, e2]-coordinate axes. Let’s look at such an example.

Example 6.1

Let

p=[22],a1=[21],a2=[24]

define a new coordinate system, and let

x=[21/2]

be a point in the [e1, e2]-system. In the new coordinate system, the [a1, a2]-system, the coordinates of x define a new point x′. What is this point with respect to the [e1, e2]-system? The solution:

x=[22]+[2214] [21/2]=[56].(6.4)

Thus, x′ has coordinates

[21/2]

with respect to the [a1, a2]-system; with respect to the [e1, e2]-system, it has coordinates

[56]..

(See Sketch 6.2 for an illustration.)

Sketch 6.2

Sketch showing mapping a point and a vector.

Mapping a point and a vector.

And now an example of a skew target box. Let’s revisit Example 5.1 from Section 5.1, and add an affine aspect to it by translating our target box.

Example 6.2

Sketch 6.3 illustrates the given geometry,

p=[22],a1=[21],a2=[46],

Sketch 6.3

Sketch showing a new coordinate system.

A new coordinate system.

and the point

r=[66]

with respect to the [e1, e2]-system. We may ask, what are the coordinates of r with respect to the [a1, a2]-system? This was the topic of Chapter 5; we simply set up the linear system, Au = (rp), or

[2416] [u1u2]=[44].

Using Cramer’s rule or Gauss elimination from Chapter 5, we find that u=[11/2].

6.2 Affine and Linear Maps

A map of the form v′ = Av is called a linear map because it preserves linear combinations of vectors. This idea is expressed in (4.11) and illustrated in Sketch 4.4. A very fundamental property of linear maps has to do with ratios, which are defined in Section 2.5. What happens to the ratio of three collinear points when we map them by an affine map? The answer to this question is fairly fundamental to all of geometry, and it is: nothing. In other words, affine maps leave ratios unchanged, or invariant. To see this, let

p2=(1t)p1+tp3

Sketch 6.4

Sketch showing ratios are invariant under affine maps.

Ratios are invariant under affine maps.

and let an affine map be defined by

x=Ax+p.

We now have

p2=A((1t)p1+tp3)+p=(1t)Ap1+tAp3+[(1t)+t]p=(1t)[Ap1+p]+t[Ap3+p]=(1t)p1+tp3.

The step from the first to the second equation may seem a bit contrived; yet it is the one that makes crucial use of the fact that we are combining points using barycentric combinations: (1 − t) + t = 1.

The last equation shows that the linear (1 − t), t relationship among three points is not changed by affine maps—meaning that their ratio is invariant, as is illustrated in Sketch 6.4. In particular, the midpoint of two points will be mapped to the midpoint of the image points.

The other basic property of affine maps is this: they map parallel lines to parallel lines. If two lines do not intersect before they are mapped, then they will not intersect afterward either. Conversely, two lines that intersect before the map will also do so afterward. Figure 6.2 shows how two families of parallel lines are mapped to two families of parallel lines. The two families intersect before and after the affine map. The map uses the matrix

A=[1221].

Figure 6.2

Figure showing affine maps: parallel lines are mapped to parallel lines.

Affine maps: parallel lines are mapped to parallel lines.

6.3 Translations

If an object is moved without changing its orientation, then it is translated. See Figure 6.3 in which points on a circle have been translated by a fixed amount.

Figure 6.3

Figure showing translations: points on a circle are translated by a fixed amount, and a line connects corresponding points.

Translations: points on a circle are translated by a fixed amount, and a line connects corresponding points.

How is this action covered by the general affine map in (6.3)? Recall the identity matrix from Section 5.9, which has no effect whatsoever on any vector: we always have

Ix=x,

which you should be able to verify without effort.

A translation is thus written in the context of (6.3) as

x=p+Ix.

One property of translations is that they do not change areas; the two circles in Figure 6.3 have the same area. A translation causes a rigid, body motion. Recall that rotations are also of this type.

6.4 More General Affine Maps

In this section, we present two very common geometric problems that demand affine maps. It is one thing to say “every affine map is of the form Ax + p,” but it is not always clear what A and p should be for a given problem. Sometimes a more constructive approach is called for, as is the case with Problem 2 in this section.

Problem 1: Let r be some point around which you would like to rotate some other point x by a degrees, as shown in Sketch 6.5. Let x′ be the rotated point.

Sketch 6.5

Sketch showing rotating a point about another point.

Rotating a point about another point.

Rotations have been defined only around the origin, not around arbitrary points. Hence, we translate our given geometry (the two points r and x) such that r moves to the origin. This is easy:

r¯=r-r=0,x¯=x-r.

Now we rotate the vector x¯ around the origin by α degrees:

x¯¯=Ax¯.

The matrix A would be taken directly from (4.16). Finally, we translate x¯¯ back to the center r of rotation:

x=Ax¯+r.

Let’s reformulate this in terms of the given information. This is achieved by replacing x¯ by its definition:

x=A(x-r)+r.(6.5)

Example 6.3

Let

r=[21],x=[30],

and a = 90°. We obtain

x=[0110] [11]+[21]=[32].

See Sketch 6.6 for an illustration.

Sketch 6.6

Sketch showing rotate x 90° around r.

Rotate x 90° around r.

Problem 2: Let l be a line and x be a point. You want to reflect x across l, with result x′, as shown in Sketch 6.7. This problem could be solved using the following affine maps. Find the intersection r of l with the e1-axis. Find the cosine of the angle between l and e1. Rotate x around r such that l is mapped to the e1-axis. Reflect the rotated x across the e1-axis, and finally undo the rotation. Complicated!

Sketch 6.7

Sketch showing reflect a point across a line.

Reflect a point across a line.

It is much easier to employ the “foot of a point” algorithm that finds the closest point p on a line l to a point x, which was developed in Section 3.7. Then p must be the midpoint of x and x′:

p=12x+12x,

from which we conclude

x=2p-x.(6.6)

While this does not have the standard affine map form, it is equivalent to it, yet computationally much less complex.

6.5 Mapping Triangles to Triangles

Affine maps may be viewed as combinations of linear maps and translations. Another flavor of affine maps is described in this section; it draws from concepts in Chapter 5.

This other flavor arises like this: given a (source) triangle T with vertices a1, a2, a3, and a (target) triangle T′ with vertices a′1, a′2, a′3, what affine map takes T to T′? More precisely, if x is a point inside T, it will be mapped to a point x′ inside T′: how do we find x? For starters, see Sketch 6.8.

Sketch 6.8

Sketch showing two triangles define an affine map.

Two triangles define an affine map.

Our desired affine map will be of the form

x=A[x-a1]+a1,

thus we need to find the matrix A. (We have chosen a1 and a′1) arbitrarily as the origins in the two coordinate systems.) We define

v2=a2a1,v3=a3a1,

and

v2=a2a1,v3=a3a1.

We know

Av2=v2,Av3=v3.

These two vector equations may be combined into one matrix equation:

A[v2v3]=[v2v3],

which we abbreviate as

AV=V.

We multiply both sides of this equation by V’s inverse V−1 and obtain A as

A=VV1.

This is the matrix we derived in Section 5.10, “Defining a Map.”

Example 6.4

Triangle T is defined by the vertices

a1=[01],a2=[11],a3=[11],

and triangle T′ is defined by the vertices

a1=[01],a2=[13],a3=[13].

The matrices V and V′ are then defined as

V=[1122],V=[1122].

The inverse of the matrix V is

V1=[1/21/41/21/4],

thus the linear map A is defined as

A=[1001].

Do you recognize the map?

Let’s try a sample point

x=[01/3]

in T. This point is mapped to

x=[1001] [[01/3][01]]+[01]=[07/3]

in T′.

Note that V’s inverse V−1 might not exist; this is the case when v2 and v3 are linearly dependent and thus |V| = 0.

6.6 Composing Affine Maps

Linear maps are an important theoretical tool, but ultimately we are interested in affine maps; they map objects that are defined by points to other such objects.

If an affine map is given by

x=A(x-o)+p,

nothing keeps us from applying it twice, resulting in x″:

x=A(x-o)+p.

This may be repeated several times—for interesting choices of A and p, interesting images will result.

Example 6.5

For Figure 6.4 (left), the affine map is defined by

A=[cos45°sin45°sin45°cos45°] [0.50.000.5]andp=[00].(6.7)

Figure 6.4

Figure showing composing affine maps: The affine maps from (6.7) and (6.8) are applied iteratively, resulting in the left and right images, respectively. The starting object is a set of points on the unit circle centered at the origin. Successive iterations are lighter gray. The same linear map is used for both images; however, a translation has been added to create the right image.

Composing affine maps: The affine maps from (6.7) and (6.8) are applied iteratively, resulting in the left and right images, respectively. The starting object is a set of points on the unit circle centered at the origin. Successive iterations are lighter gray. The same linear map is used for both images; however, a translation has been added to create the right image.

In Figure 6.4 (right), a translation was added:

p=[0.20].(6.8)

For both images, the linear map is a composition of a scale and a rotation. In the left image, each successive iteration is applied to geometry that is centered about the origin. In the right image, the translation steps away from the origin, thus the rotation action moves the geometry in the e2-direction even though the translation is strictly in e1.

Example 6.6

For Figure 6.5 (left), the affine map is

A=[cos90°sin90°sin90°cos90°] [0.50.000.5] [1101]andp=[00].(6.9)

Figure 6.5

Figure showing composing affine maps: The affine maps from (6.9) and (6.10) are applied iteratively, resulting in the left and right images, respectively. The starting object is a set of points on the unit circle centered at the origin. Successive iterations are lighter gray. The same linear map is used for both images; however, a translation has been added to create the right image.

Composing affine maps: The affine maps from (6.9) and (6.10) are applied iteratively, resulting in the left and right images, respectively. The starting object is a set of points on the unit circle centered at the origin. Successive iterations are lighter gray. The same linear map is used for both images; however, a translation has been added to create the right image.

In Figure 6.5 (right), a translation was added:

p=[20].(6.10)

For both images, the linear map is a composition of a shear, scale, and rotation. In the left image, each successive iteration is applied to geometry that is centered about the origin. In the right image, the translation steps away from the origin, thus the rotation action moves the geometry in the e2-direction even though the translation is strictly in e1. Same idea as in Example 6.5, but a very different affine map! One interesting artifact of this map: We expect a circle to be mapped to an ellipse, but by iteratively applying the shear and rotation, the ellipse is stretched just right to morph back to a circle!

Rotations can also be made more interesting. In Figure 6.6, you see the letter S rotated several times around the origin, which is near the lower left of the letter.

Figure 6.6

Figure showing rotations: the letter S is rotated several times; the origin is at the lower left of the letter.

Rotations: the letter S is rotated several times; the origin is at the lower left of the letter.

Adding scaling and rotation results in Figure 6.7. The basic affine map for this case is given by

x=S[Rx+p]

Figure 6.7

Figure showing rotations: the letter S is rotated several times; scalings and translations are also applied.

Rotations: the letter S is rotated several times; scalings and translations are also applied.

where R rotates by −20°, S scales nonuniformly, and p translates:

R=[cos(20)sin(20)sin(20)cos(20)],S=[1.25001.1],p=[55].

We finish this chapter with Figure 6.8 by the Dutch artist, M.C. Escher [5], who in a very unique way mixed complex geometric issues with a unique style. The figure plays with reflections, which are affine maps.

Figure 6.8

Figure showing M.C. Escher: Magic Mirror (1949).

M.C. Escher: Magic Mirror (1949).

Figure 6.8 is itself a 2D object, and so may be subjected to affine maps. Figure 6.9 gives an example. The matrix used here is

A=[0.70.350.140.49].(6.11)

Figure 6.9

Figure showing M.C. Escher: Magic Mirror (1949); affine map applied.

M.C. Escher: Magic Mirror (1949); affine map applied.

No translation is applied.

image

  • linear map
  • affine map
  • translation
  • identity matrix
  • barycentric combination
  • invariant ratios
  • rigid body motion
  • rotate a point about another point
  • reflect a point about a line
  • three points mapped to three points
  • mapping triangles to triangles

6.7 Exercises

For Exercises 1 and 2 let an affine map be defined by

A=[2112]andp=[22].

  1. Let

    r=[01],s=[13/2],

    and q = (1/3)r + (2/3)s. Compute r′, s′, q′ ; e.g., r′ = Ar + p. Show that q′ = (1/3) r′ + (2/3)s′.

  2. Let

    t=[01]andm=[21].

    Compute t′ and m′. Sketch the lines defined by t, m and t′, m′. Do the same for r and s from Exercise 1. What does this illustrate?

  3. Map the three collinear points

    x1=[00],x2=[11],x3=[22],

    to points xi by the affine map Ax + p, where

    A=[1201]andp=[40].

    What is the ratio of the xi? at is the ratio of the xi?

  4. Rotate the point

    x=[22]

    by 90° around the point

    r=[22].

    Define the matrix and point for this affine map.

  5. Rotate the points

    p0=[10],p1=[20],p2=[30],p3=[40]

    by 45° around the point p0. Define the affine map needed here in terms of a matrix and a point. Hint: Note that the points are evenly spaced so some economy in calculation is possible.

  6. Reflect the point x=[02] about the line l(t)=p+tv,l(t)=[00]+t[12].

  7. Reflect the points

    p0=[21],p1=[11],p2=[01],p3=[11],p4=[21]

    about the line l(t) = p0 + tv, where

    v=[22].

    Hint: Note that the points are evenly spaced so some economy in calculation is possible.

  8. Given a triangle T with vertices

    a1=[00],a2=[10],a3=[01],

    and T′ with vertices

    a1=[10],a2=[01],a3=[00],

    what is the affine map that maps T to T′ What are the coordinates of the point x′ corresponding to x = [1/2 1/2]T ?

  9. Given a triangle T with vertices

    a1=[20],a2=[01],a3=[20],

    and T′ with vertices

    a1=[20],a2=[01],a3=[20],

    suppose that the triangle T has been mapped to T′ via an affine map. What are the coordinates of the point x′ corresponding to

    x=[00]?

  10. Construct the affine map that maps any point x with respect to triangle T to x′ with respect to triangle T′ using the vertices in Exercise 9.
  11. Let’s revisit the coordinate transformation from Exercise 10 in Chapter 1. Construct the affine map which takes a 2D point x in NDC coordinates to the 2D point x′ in a viewport. Recall that the extents of the NDC system are defined by the lower-left and upper-right points

    ln=[11]andun=[11],

    respectively. Suppose we want to map to a viewport with extents

    lv=[1010]anduv=[3020].

    After constructing the affine map, find the points in the viewport associated with the NDC points

    x1=[11],x2=[11],x3=[1/21/2].

  12. Affine maps transform parallel lines to parallel lines. Do affine maps transform perpendicular lines to perpendicular lines?
  13. Which affine maps are rigid body motions?
  14. The solution to the problem of reflecting a point across a line is given by (6.6). Why is this a valid combination of points?
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.137.93