You are on page 1of 44

2D Geometric Transformations

CMSC 161 – Interactive Computer Graphics


Geometrical Transformations

• Operations used to alter the position, shape and size of


objects
• Three kinds of basic transformation:
– Translation
– Scaling
– Rotation
• Additional transformations:
– Reflection
– Shear
Translation

• Involves adding translation amounts to the x and y


coordinates of a point
• Translating a polygon involves translating each vertex of
the polygon
Translation
Scaling

• Involves multiplying the coordinates with scale factors


• Scaling a polygon involves scaling each vertex of the
polygon
Scaling
Uniform Scaling

• Proportions are unaffected


Differential Scaling

• Proportions are changed


Reflection
Rotation
• Involves moving a point along a circular path
through an angle θ about an axis
Rotation
Rotation
Homogeneous Coordinates

• Many graphics applications, however, involve sequences of


geometric transformations
– For example, an animation in which the object is both translated
and rotated at each motion increment
Homogeneous Coordinates

• Allow us to perform all three types of transformations using


matrix multiplication only
– Translation expressed in the same form as rotation and scaling
• As a result, combining these transformations becomes
straightforward.
• Represent points as three-tuples (triples)
Homogeneous Coordinates
Translation
Scaling
Reflection – Mirror Image
Rotation

Suppose we rotate the point P = (2,4) by 30º.What


would be the coordinates of the rotated point?
Transformations and Origin

• When we transform a shape, we transform each of the


defining points of the shape, and then redraw it
• If we scale or rotate a shape that is not anchored at the
origin, it will translate as well
Transformations and Origin

• If we just want to scale or rotate, we should translate back


to the origin, scale or rotate, then translate back
Composition of Transformations

• A series of transformations can be accumulated into a


single (net) transformation matrix M
• Once we have computed the net transformation matrix, we
can apply the whole sequence of transformations to a point
by just doing a single matrix multiplication
Composition of Transformations
Composition of Transformations

• To rotate an object about an arbitrary pivot point, we need


to do a sequence of three fundamental transformations
– Translate the pivot point to origin
– Rotate about the origin
– Translate the pivot point back to the original position
Matrix Composition

• The net transformation matrix is obtained by multiplying the


series of transformation matrices in reverse order
Matrix Multiplication: Associativity

• Suppose we want to scale point (x, y) by 2


then rotate by 90º

=
Matrix Composition

• Composition of transformations is not regularly


commutative
– Order of transformation matters
• If we invert the matrix, we reverse the transformation
3D Geometric Transformations

CMSC 161 – Interactive Computer Graphics


Homogeneous Coordinates

• By representing points in their  x


homogeneous coordinates,  
translation, scaling and rotation  y
can be computed using matrix  z 
multiplication  
• 3D points need 4 coordinates  1

3D Coordinate System

y
(0,5,5)
(5,5,0)
c

g
d f
b
k
(0,5,5) (5,5,5)

a (5,0,0)

(0,0,0) j x
l
h
e

(0,0,5) i (5,0,5)
z
3D Transformations

• Since we now have an additional coordinate to cope with,


our transformation matrices must also extend to cope
• Each transformation matrix will require an extra row and an
extra column to become 4x4 matrices
Translation

x 1 0 0 Txx
    
y 0 1 0 Tyy
z0 0 1 . 
Tz z
    
1 0 0 0 1 1
    
Scaling

x Sx 0 0 0x


    
y 0 Sy 0 0y
z0 0 Sz . 
0 z
    
1 0 0 0 1 1
    
Rotation

• In 2D, rotation were


defined to take place
about some stationary
point – the center of
rotation
• In 3D, all rotation take
place about one of the
axes
Rotation
Rotation about z-axis

• Note: The 2D rotation is just a 3D rotation about the z-axis

 x   cos   sin  0 0  x 
    
 y   sin  cos  0 0  y 

 z   0 .
0 1 0  z 
    
1  0 0 0 1   1 
  
Rotation about x-axis

 x   1 0 0 0  x 
    
 y   0 cos   sin  0  y 
 z     0 sin  cos  0 z. 
    
 1  0 0 0 1   1 
  
Rotation about y-axis

x cos0 s in0x


    
y  0 1 0 0 y
zs i 
n0 co . 
s0 z
    
1  0 0 0 1 1 
    
Order of Rotation

• Affects final position


Reflection

• A three-dimensional reflection can be performed relative to


a selected reflection axis, or with respect to a selected
reflection plane
• Reflections relative to a given axis are equivalent to 180º
rotations about that axis
Reflection

• The matrix representation for reflection relative to the xy


plane is:
1 0 0 0
0 1 0 0
M zreflect 
0 0  1 0
 
0 0 0 1
• Reflections about other planes can be obtained using a
combination of rotations and coordinate-plane reflections
Shear

• Can be used to modify object shapes


• The following transformation produces a z-axis shear
Shear

• The effect of the (z-axis shear) transformation matrix is to


alter x- and y-coordinate values by an amount proportional
to the z value, while leaving the z coordinate unchanged
• Do not preserve lengths, angles, areas in all directions, but
preserve volumes
Local Rotation

• Translate the object to be rotated to the origin, perform the


rotation, then translate it back to where it started from

 =-90°

You might also like