Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 64

Geometric Transformations

OVERVIEW

• Two Dimensional Transformations


• Matrix Representations
• Inverse Transformations
• Three dimensional transformations
Transformation

Transformation: Fundamental to all computer graphics


system is the ability to simulate the manipulation of
objects in space. This simulated spatial manipulation is
referred to as Transformation. They are of two types:

1. Geometric Transformation
2. Co-ordinate Transformation
Transformation

1. Geometric Transformation: When the object itself is


transformed relative to a stationary coordinate
system or back ground. The mathematical statement
of this viewpoint is described as geometric
transformation.
For example: Movement of automobile against a scenic
background.
Transformation

2. Coordinate Transformation: When the object is held


stationary while coordinate system is transformed
relative to the object is known as coordinate
transformation.
For example: Keep the car fixed while moving the
backdrop scenery.
2D Geometric Transformation

• Translation
• Rotation
• Scaling
• Reflection
• Shearing

• We first discuss the 2D transformations, then we


will continue with 3D.
2D Translation from origin

Point P defined as P( x, y ),
translate to Point P( x, y) a distance d x parallel to x axis, d y parallel to y axis.
x  x  d x y   y  d y
Define the column vec tors
 x  x  d x 
P    , P    , T   
 y  y  dy  P’
P
Now
P  P  T
2D Scaling from the origin.

Point P defined as P( x, y ),
Perform a scale (stretch) to Point P( x, y) by a factor s x along the x axis,
and s y along the y axis.
x  s x . x, y  s y . y
Define the matrix P’
sx 0 P
S
0 s y 
Now
 x   s x 0  x 
P  S  P or  y   0 . 
   s y   y
2D Rotation about the origin.


P’(x’,y’)

P(x,y)
r

r
x
2D Rotation about the origin.

P’(x’,y’)

r
P(x,y) x  r. cos 
y  r. sin 
 y
r

x
x
2D Rotation about the origin.

x  r. cos(   )  r. cos  . cos  r. sin  . sin 


y y  r. sin(    )  r. cos  . sin   r. sin  . cos

P’(x’,y’)

P(x,y)
r x  r. cos 
y  r. sin 
 y
r

x
x
2D Rotation about the origin.

x  r. cos(   )  r. cos  . cos   r. sin  . sin 


y  r. sin(    )  r. cos  . sin   r. sin  . cos 
Substituting for r :

x  r. cos 
y  r. sin 
Gives us :

x  x. cos  y. sin 
y  x. sin   y. cos
2D Rotation about the origin.

x  x. cos  y. sin 
y  x. sin   y. cos

Rewriting in matrix form gives us :

 x cos   sin    x 


 y   sin  . 
cos    y 
  

cos  sin  
Define the matrix R    , P  R  P
 sin  cos 
2D Basic Transformations
Translation. Scale Rotation
P=T + P P=S  P P=R  P

We would like all transformations to be


multiplications so we can concatenate them 
express points in homogenous coordinates.
Homogeneous Coordinates

• Add an extra coordinate, W, to a point.


• P(x,y,W).
• Two sets of homogeneous coordinates represent the same
point if they are a multiple of each other.
• (2,5,3) and (4,10,6) represent the same point.
• At least one component must be non-zero  (0,0,0) is not
defined.
• If W 0 , divide by it to get Cartesian coordinates of point
(x/W,y/W,1).
• If W=0, point is said to be at infinity.
Homogeneous Coordinates
• If we represent (x,y,W) in 3-space, all triples representing the same point
describe a line passing through the origin.
• If we homogenize the point, we get a point of form (x,y,1)
• homogenised points form a plane at W=1.

W P

W=1 plane

Y
Translation in homogenised
coordinates

• Transformation matrices for 2D translation are


now 3x3.

 x  1 0 d x   x  x  x  d x
 y  0 1 d . y 
   y   y  y  d y
 1  0 0 1   1  11
Scaling in homogenised
coordinates

• Transformation matrices for 2D Scaling are now


3x3.

 x   S x 0 0  x  x  S x . x
 y   0 0. y 
   Sy y  S y . y
 1   0 0 1  1  11
Rotation in homogenised
coordinates

• Transformation matrices for 2D Rotation are


now 3x3.

 x  cos   sin  0  x  x  x. cos   y. sin 


 y   sin  cos   .
0   y  y  x. sin   y. cos 
   1 1
1  0 0 1  1 
Concatenation.

• We perform 2 translations on the same point:

P  P  T (d x1 , d y1 )
P  P  T ( d x 2 , d y 2 )
P  P  T (d x1 , d y1 )  T (d x 2 , d y 2 )  P  T (d x1  d x 2 , d y1  d y 2 )
So we expect :
T (d x1 , d y1 )  T (d x 2 , d y 2 )  T (d x1  d x 2 , d y1  d y 2 )
Concatenation.

The matrix product T (d x1 , d y1 )  T (d x 2 , d y 2 ) is :


1 0 d x1  1 0 d x 2 
0 1 d .0 1 d   ?
 y1   y2 

0 0 1  0 0 1 
Matrix product is variously referred to as compounding,
concatenation, or composition
Concatenation.

The matrix product T (d x1 , d y1 )  T (d x 2 , d y 2 ) is :


1 0 d x1  1 0 d x 2  1 0 d x1  d x 2 
0 1 d .0 1 d   0 1 d  d 
 y1   y2   y1 y2 

0 0 1  0 0 1  0 0 1 


Matrix product is variously referred to as compounding, concatenation, or
composition.
This single matrix is called the Coordinate Transformation Matrix or CTM.
Properties of Translations

1. T (0,0)  I
2. T ( s x , s y )  T (t x , t y )  T ( s x  t x , s y  t y )
3. T ( s x , s y )  T (t x , t y )  T (t x , t y )  T ( s x , s y )
4. T -1 ( s x , s y )  T ( s x , s y )

Note : 3. Translation matrices are commutative.


Homogeneous form of scale

Recall the (x,y) form of Scale : sx 0


S (sx , s y )  
0 s y 

In homogeneous coordinates :

sx 0 0
S ( s x , s y )   0 sy 0
 0 0 1
Concatenation of scales

The matrix product S ( s x1 , s y1 )  S ( s x 2 , s y 2 ) is :


s x1 0 0  s x2 0 0  s x1  s x2 0 0
0 s 0 . 0 s 0  0 s  s 0 
 y1  y2   y1 y2 
 0 0 1   0 0 1   0 0 1
Only diagonal elements in the matrix - easy to multiply !
Reflection

Corresponds to negative scale factors

sx = -1 sy = 1 original
Along y-axis

sx = 1 sy = -1
sx = -1 sy = -1
Along x-axis
Along xy-plane
Homogeneous form of rotation.

 x cos  sin  0   x


 y   sin  cos 0 . y 
  
 1   0 0 1   1 

For rotation matrices,


R 1 ( )  R( ).
Rotation matrices are orthogonal , i.e :
R ( )  R ( )
1 T

i.e. the inverse is the transpose


Orthogonality of rotation matrices.
cos   sin  0   cos  sin  0 
R( )   sin  cos  0 , RT ( )   sin  cos  0 
 0 0 1   0 0 1 

cos   sin   0   cos sin  0 


R( )   sin   cos  0    sin  cos 0 
 0 0 1   0 0 1 
Other properties of rotation.
R(0)  I
R( )  R( )  R(   )
and
R( )  R( )  R( )  R( )
only if the centres of rotation are the same,
Otherwise order matters.
2D Composite Transformations

• Combine transformations of different type


• translate, rotate, translate
• translate, scale, translate
• translate, reflect, translate
• Use to rotate or scale an object w.r.t. a point that is
not the origin
• Implement by multiplication of the corresponding
homogeneous matrices
2D Composite
Rotation about a pivot point
Transformations
reflection in x and y axes reflection in origin
1 a   x   x  a y 
0 1   y    y 
     
1 0   x   x 
b 1   y   b xShgives 
the slope
     of a vertical
y  line
x

after shear, as dx/dy


Example 1

 1 0  x 
y T ( x, y )     
0.4 1  y 
(0,1)  x 
(1,1)  
0.4 x  y 
S
(0,0) (1,0) x
Example 1

y T ( x, y ) 
 x 
(0,1)  0 .4 x  y 
 
(1,1)

S
(0,0) (1,0) x
Example 1

y (1, 1.4) T ( x, y ) 
 x 
(0,1)  0 .4 x  y 
 
T(S)
(1, 0.4)

(0,0)
x
Example 2

1 0.6  x 
T ( x, y )     
y 0 1   y 
 x  0.6 y 
(0,1) (1,1)  
 y 
S
(0,0) (1,0) x
Example 2

 x  0.6 y 
y
T ( x, y )   
 y 
(0,1) (1,1)

S
(0,0) (1,0) x
Example 2

 x  0.6 y 
y T ( x, y )   y 
 
(0,1) (0.6, 1) (1.6, 1)

T(S)
(0,0) (1, 0) x
Summary
Shear in x:
1 shx   x   x  shx y 
Shx        
Shear in y:
 0 1   y  y 

 1 0  x   x 
Shy       
sh
 y 1  y  shy .x  y 
Double Shear: not commutative!

1 a  1 0 (1  ab) a 
0 1  b 1   b 
    1

1 0 1 a  1 a 

b 1 0 1  b (1  ab)
    
Questions on 2D Composite
Transformations
Q1 Find the transformation that scales by
(a) A units in X direction
(b) B unit in Y direction
(c) Simultaneously a unit in X direction and b unit in Y
direction.
Q2 Write the general form of scaling matrix with respect
to a fixed point p(h, k).
Q3 Magnify the triangle with vertices A(0, 0), B(1, 1) and
C(5, 2) to twice its size while keeping C(5, 2) fixed.
Q4 Describe the transformation ML which reflects an
object about a line L.
Q5 Find the form of the matrix for reflection about a line
L with slope m and y intercept (0,b).
Viewing Transformations
Much like, what we see in real life through a small
window on the wall or the viewfinder of a camera, a
computer generated image often depicts a partial view
of a large scene.
World Coordinate System: Objects are placed into the
scene by modelling transformations to a master
coordinate system known as world coordinate system.
Window: A rectangular window with its edges parallel
to the axes of the WCS is used to select the portion of
the scene for which an image is to be generated.
Viewing Transformations

On the other hand an image representing a view


often becomes part of a larger image, like a photo
on an album page, which model’s a computer
monitor display area. Since album pages vary and
monitor sizes differ from one system to other
system, we want to introduce a device independent
tool to describe the display area. This tool is called
Normalized device coordinate system (NDCS) in
which a unit (1 x 1) square whose lower left corner
is at the origin of the coordinate system define the
display area of a virtual display device .
Viewing Transformations

• World coordinate system: The master coordinate


system is called World Coordinate System.
• Window : A world coordinate area which is selected
for displaying a object. In other words, “What we
want to see”.
• Viewport : An area where the mapped object is
displayed. In other words, “Where we want to see
object”.
• Clipping window: The area of object which is
required is taken, remaining area is neglected.
Viewing Transformations
Window to Viewport Mapping

The process that converts objects


coordinates in WCS to normalized device
coordinates is called window to viewport
mapping.
The process that maps normalized device
coordinates to describe device/image
coordinates is called workstation
transformation, which is second window to
viewport transformation.
Thus

Window to Viewport Mapping


In order to maintain same relative placement of the point in
viewport as in the window, we require:
Window to Viewport Mapping

By proportionality factor, following ratio must be equal for


mapping:
Window to Viewport Mapping
Where

Window to Viewport Mapping

Window to viewport mapping in the form of homogeneous


coordinates:
Where

Window to Viewport Mapping

Q1. Find the complete viewing transformation that maps a window in WCS
with x extent 1 to 10 and y extent 1 to 10 onto a viewport with x extent ¼ to ¾
ant y extent 0 to ½ and y extent 0 to ½ in normalized device space and then
maps a workstation window with x extent ¼ to ½ and y extent ¼ to ½ in the
normalized device space into a workstation viewport with x extent 1 to 10 and y
extent 1 to 10.
Q2. Find a normalization transformation from the window whose lower left
corner is at (0, 0) and upper right corner is at (4, 3) onto normalized device
screen so that aspect ratio are preserved.
Where

Window to Viewport Mapping

Q. Find the normalization transformation N which uses the rectangle A(1, 1),
B(5,3), C(4,5) and D(0,3) as a window and the normalized device screen as a
viewport.
Q. Illustrate the effect of shearing transformation on the square A(0, 0), B(1, 0),
C(1, 1) and D(0,1) when a=2 and b=3.
Where

Window to Viewport Mapping


Q1. Reflect a polygon with vertices A(-1, 0) B(0,-2)
C(1,0) and D(0, 2) about
(a) The horizontal line y = 2.
(b) The vertical line x = 2.
(c) The line y = x + 2.
Q2. Find the normalization transformation that maps a
window whose lower left corner is at (1, 1) and upper
right corner is at (3, 5) onto
(a) A viewport that is the entire normalized device
screen.
(b) A viewport that has lower left corner is at (0, 0) and
upper right corner is at (½, ½).

You might also like