2D transformations

-  What are we transforming?

-  Why consider 2D transformations?

-  Definition of common 2D a±ne transformations.

-  Homogeneous coordinates.

Start by considering 2D objects.

-  Later we will consider scan conversion:

objects primitives pixels.

-  This section discusses the methods we use to model 2D objects and transformations of those objects: objects ! objects.

-  In 2D, possible primitives are points, lines and polygons, which can be combined to give higher level objects.

-  In 2D it is generally easy to see how to represent certain objects.

-  To understand transformations we need to use basic vector algebra!

Vectors

A vector is an n-tuple of numbers:

The rule for the addition is:

Vector addition is commutative: r +s = s+r.

Translations are offsets from the existing position of the object. Consider a point at r.

Translate it by an amount t = (tx; ty)0: new location will be r¤ = r +t.

Scalings are stretchings of the object, about the origin. The scaling matrix S is:

r* = Sr : sx is the x-axis scaling and sy is the y-axis scaling

If sx = sy = s the scaling is said to be uniform. If not the scaling is called differential.

Rotations about the origin by an angle q are defined by the rotation matrix R which is given by:

The rotated point, r*¤ = Rr.

A positive q implies an anti-clockwise rotation.

Homogeneous coordinates

-  Homogeneous coordinates allow us to treat all transformations in the same way, as matrix multiplications.

-  The consequence is that our 2-vectors become extended to 3-vectors, with a resulting increase in storage and processing.

-  We represent a point (x; y) by the extended triple (x; y; w).

-  The normalised homogeneous coordinates are (x/w; y/w; 1).

-  Points with w = 0 are called points at infinity, and are not frequently used.

-  If you like then you can think of 2D space corresponding to plane w = 1.

² In homogeneous coordinates the transformations are:

Composition of transformations

One of the big advantages of homogeneous coordinates is that transformations can be very easily combined. All that is required is multiplication of the transformation matrices. This makes otherwise complex transformations very easy to compute. For instance if we wanted to rotate an object about some point, p, on (or in) that object, this can easily be achieved by:

1.  translate object by -p,

2.  rotate object by angle q,

3.  translate object by p.

This can be written as:

Window to viewport transformation

In general the objects and primitives represented in the application model will be stored in world coordinates, that is their size, shape, position, etc. will be given in terms of logical units for whatever the object represent (e.g. mm, cm, m, km or light years). Thus to display the appropriate images on the screen (or other device) it is necessary to map from world coordinates to screen or device coordinates. This transformation is known as the window to viewport transformation, the mapping from the world coordinate window2 to the viewport (which is given in screen coordinates).

In general the window to viewport transformation will involve a scaling and translation as where the scaling in non-uniform (the vertical axis has been stretched). Non uniform sculling result from the world coordinate window and viewport having different aspect ratios. In Figure 3.7 the screen window (that is the viewport) covers only part of the screen.The transformation is generally achieved by a translation in world coordinates, a scaling to viewport coordinates and another translation in viewport coordinates, which are generally composed to give a single transformation matrix.

Often the clipping of visible elements will be carried out at the same time as the transformation is applied.Typically the region will be clipped in world coordinates and then transformed.

Inverse transformations

Since M is a matrix representing transformations this inverse matrix will exist (because a general transformation matrix is non-singular). The matrix inverse is defined so that MM-1 = I where I is the 3 x 3 identity matrix,

For most transformations is is quite obvious, from ¯rst principles what the inverse transformations are, for instance the translation matrix has inv[‘erse:

2

Transformation