0% found this document useful (0 votes)
102 views34 pages

CST 304 - Computer Graphics: 2D Transformations

This document discusses 2D transformations including translation, rotation, scaling, and combining transformations. Translation moves all points along a straight line path defined by a translation vector. Rotation repositions points along a circular path centered at a pivot point defined by an angle of rotation. Scaling changes the size of an object using scale factors that move points closer to or further from the origin. Combining transformations can be represented by pre-multiplying the point coordinates by a transformation matrix.

Uploaded by

Malu Vavu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
102 views34 pages

CST 304 - Computer Graphics: 2D Transformations

This document discusses 2D transformations including translation, rotation, scaling, and combining transformations. Translation moves all points along a straight line path defined by a translation vector. Rotation repositions points along a circular path centered at a pivot point defined by an angle of rotation. Scaling changes the size of an object using scale factors that move points closer to or further from the origin. Combining transformations can be represented by pre-multiplying the point coordinates by a transformation matrix.

Uploaded by

Malu Vavu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 34

CST 304 - Computer Graphics

Module-2 Part-2
2D TRANSFORMATIONS
• Basic
Transformations
• Matrix representations, Homogeneous coordinates
• Composite Transformations
2D Transformations
• Geometric Transformation
– The geometrical change of an object from a current state to
modified state.
– To manipulate the initially created object and to alter and display
the modified object without having to redraw it.
Eg : designing, animation
– Two types:-
– Object Transformation
• Changes orientation, size and shape of object
• Alter the coordinates descriptions an object
• Translation, rotation, scaling, shear, reflection, etc.
• Coordinate system unchanged
– Coordinate transformation
• Produce a different coordinate system
Matrix Representation
• Column-vector representation for a point.
• Pre-multiplication of the transformation – it appears
before the point to be transformed in the equation.

A B   x   Ax  By 
C    
 D   y  Cx  Dy 

• Advantages of Matrix
– More convenient organization of data
– More efficient processing
– Enable the combination of various concatenations
2D Translation
A translation moves all points in an
object along the same straight-line
path from original position (x, y) to
new position (x’, y’)
The translation distance pair (tx , ty),
P ?
is called translation or shift vector. (8,6)
Translation equations are: 2)(

x' = x + tx ty = 4
P
y' = y + ty tx = 6
(2, 2)
or in matrix form:
P' = P + T
x’ x tx
y’ = y + t
y
2D Translation
A translation is a rigid body transformation that moves objects
without deformation. That is every point on the object is translated
by the same amount.
• Line segment - add translation vector to each of line end points
and redrawing line between new end point positions.
• Polygons - add translation vector to coordinate position of each
vertex and regenerate polygon using new set of vertex coordinates
and current attribute settings
• Circle or Ellipse - add translation vector to center coordinate and
redraw it in new location
• Curves (splines) - add translation vector to coordinate positions of
object and reconstruct curve paths using new set of coordinates
2D Rotation
• Rotation - a rigid body transformation
that repositions all points in an object
along a circular path in the xy plane
centered at the pivot point.
• A rotation angle  and position (xr ,yr) P’
of rotation point or pivot point about
which object is to be rotated is 
specified.
• can be clockwise (-ve) or P
counterclockwise (+ve).
• Rotation is about a rotation axis
perpendicular to xy plane and passes
through the pivot point.
2D Rotation
• First, assume that pivot is at the origin (0,0).
• Review Trigonometry
=> cos  = x/r , sin = y/r
x = r cos , y = r sin  P’(x’, y’)

=> cos (+ ) = x’/r



x’ = r. cos (+ )
r
x’ = r coscos - r sinsin y’ P(x,y)
x’ = x cos  – y sin 
 r y
=> sin (+ ) = y’/r 
x’ x
y’ = r. sin (+ )
y’ = r cossin + r sincos Identity of Trigonometry

y’ = x sin  + y cos 
2D Rotation
• Rotation equations:
x’ = x cos  – y sin 
y’ = x sin  + y cos 
• or in matrix form:
P’(x’, y’)
P' = R • P
 x '   cos   sin    x 
 y '   sin  cos    y  
    
y’
P(x,y)
• Rotation matrix
cos  sin    r y
R 
 sin  cos  x
x’
• For a rotation matrix transpose
is got by simply changing sign
of sine terms
2D Rotation
y
Rotation in angle  about a

pivot (rotation) point  xr , yr .



yr
x
xr x  xr   x  xr  cos    y  yr  sin 
y
 x, y  y  yr   x  xr  sin    y  yr  cos 

 x, y  P  Pr  R   P  Pr 

 xr , yr  x cos 
R
 sin  
 sin  cos  
2D Rotation
Example - Find the transformed point, P’, caused by rotating
P= (5, 1) about the origin through an angle of 90.

cos  sin    x   x  cos  y  sin  


 sin     
 cos   y   x  sin   y  cos 

5  cos 90  1  sin 90


 
5  sin 90  1  cos 90
5  0  1 1
 
5  1  1  0 
  1
 
 5 
2D Scaling
• Scaling alters the size of an object
and involves two scale factors, sx
and sy for the x and y coordinates
P’
respectively.
• Scales are about the origin (0,0).
• Scaling equations:
x' = sx • x
P
y' = sy • y
or in matrix form:
P' = S • P
Scale matrix as:
sx 0
S 
0 sy 

Scaling
If the scale factors are in between 0
and 1  the points will be moved
closer to the origin  the object will
be smaller.
• Example :
•P(2, 5), Sx = 0.5, Sy = 0.5
P(2, 5)
•Find P’ ?

P’

Scaling
If the scale factors are in between 0
and 1  the points will be moved
P’
closer to the origin  the object will
be smaller.
• Example :
•P(2, 5), Sx = 0.5, Sy = 0.5
P(2, 5)
•Find P’ ?
•If the scale factors are larger than 1
 the points will be moved away P’

from the origin  the object will be


larger.
• Example :
•P(2, 5), Sx = 2, Sy = 2
•Find P’ ?
2D Scaling
• Uniform scaling
- scale factors are the same, Sx = Sy
P’
- only change in size (previous example)

• Differential scaling.
- scale factors are different, Sx  Sy 
- change in size and shape
- Example : square  rectangle
P(1, 3), Sx = 2, Sy = 5 , P’ ? P(1, 3)

• Unit Scaling
- scale factors are both 1, Sx = Sy = 1
- size and shape unchanged
2D Scaling
Scaling about a fixed point  x f , y f 
Sx
x'  x f  ( x  x f ) s x
Sy y'  y f  ( y  y f )s y
or
y
x  x  s x  x f 1  s x 

y   y  s y  y f 1  s y 
x f , yf 
x
P  P  S  P f  1 - S 
Note: the additive terms xf (1-Sx) and yf (1-Sy) are constants for
all points in the object
Combining Transformations
General transformation of a point:
P' = M1 • P + M2
P' and P - column matrix (2 x 1) of new and original coordinates
M1 - 2 x 2 matrix for scaling and rotation
M2 - column matrix (2 x 1) for translation
• For scaling or rotation, we set M2 as the additive identity.
• For translation, we set M1 is the multiplicative identity.
• To combine multiple transformations, we must explicitly compute
each transformed point. It is better to use the same matrix operation
all the time, so have to combine multiplication and addition into a
single matrix representation by expanding 2x2 to 3x3 matrices
• Cartesian coordinate (x, y) replaced by homogeneous coordinate
triplet (xh ,yh, h) equal to (x.h, y.h, h) where x = xh/ h, y = yh / h
• Homogeneous representation allows to represent all geometric
transformation equations as concatenated matrix multiplications
Homogeneous Coordinates
y y
w
x 
x
• Let point (x, y) in 2D be represented by point (x, y, 1) in the new
space. Scaling our new point by any value a puts us somewhere
along a particular line: (ax, ay, a).
• A point in 2D can be represented in many ways in the new space.
• (2, 4)  (8, 16, 4) or (6, 12, 3) or (2, 4, 1) or etc.
• We can always map back to the original 2D point by dividing by the
last coordinate (15, 6, 3) (5, 2)
• Since all the points along each line can be mapped back to the same
point in 2D this coordinate system –> homogeneous coordinates
Homogeneous Transform Advantages

• Homogeneous representation allows to represent all


geometric transformation equations as concatenated
matrix multiplications
• Unified view of transformation as matrix multiplication
– Easier in hardware and software
• To compose transformations, simply multiply matrices
– Order matters: AB is generally not the same as BA
• Allows for non-affine transformations:
– Perspective projections!
– Bends, tapers, many others
Homogeneous Coordinates
 x   1 0 t x   x 
 y     0 1 t    y  , P  T t , t  P
2D
Translation    y    x y
 1   0 0 1   1 

 x  cos   sin  0   x 
2D  y   sin  cos  0    y  , P  R   P
Rotation        
 1   0 0 1   1 

 x   S x 0 0   x 
 y     0 S 0    y  , P  S S , S  P
2D
Scaling    y     x y
 1   0 0 1   1 
19
Homogeneous Coordinates
Inverse transformations:
 1 0 t x   cos  sin  0 1 S x 0 0
T1  0 1 t y  , R 1    sin  cos  0  , S1   0 1 S y 0 
0 0 1   0 0 1   0 0 1 
Composite Transformations:
P   M 2  M1  P    M 2  M 1   P  M  P
Composite Translation:
  
P  T t2 x , t2 y  T t1x , t1 y   P  T t2 x , t 2 y   T t1x , t1 y   P 
1 0 t2 x  1 0 t1x  1 0 t1x  t 2 x 
0 1 t   0 1 t   0 1 t  t 
 2y   1y   1y 2y 

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

T t2 x , t2 y   T t1x , t1 y   T t1x  t 2 x , t1 y  t 2 y20


Homogeneous Coordinates
Composite Rotation:
P  R  2 R 1   P  R  2   R 1  P

R  2   R 1   R 1   2 

P  R 1   2   P

Composite Scaling:

 S2 x 0 0   S1x 0 0   S1x  S 2 x 0 0
 0 S2 y 0    0 S1 y 0    0 S1 y  S 2 y 0 

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

April 2010 S  S 2 x , S 2 y   S  S1x , S1 y   S  S1x  S 2 x , S1 y  S 2 y 21



General Pivot Point 2D Rotation

Move to Rotate Move back


origin
 xr , yr 

2D Rotation Steps  T(-xr , -yr ) = R ( xr , yr ,)


T( xr , yr ).R (.
1. Translate object such that 1 0 xr  cos   sin  0  1 0  xr 
pivot point moves to origin 0 1 y    sin  cos  0   0 1  yr  
2. Rotate object about origin
 r 

0 0 1   0 0 1  0 0 1 
3. Translate pivot point back
to original position cos   sin  xr 1  cos    yr sin  
 
 sin  cos  yr 1  cos    xr sin  
22
 0 0 1 
General Fixed Point 2D Scaling

Move to Scale Move back


x f
origin
, yf  x f , yf 

1 0 x f   S x 0 0  1 0  x f   S x 0 x f 1  S x  
0 1 y    0 S 0   0 1  y    0 S y 1  S 
 f   y   f   y f  y 

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

 
T(xf , yf ) . S (sx , sy  T(- xf , - yf ) = S ( xf , yf , sx , sy )
2D Scaling Steps
1. Translate object such that fixed point moves to origin
2. Scale object about origin
April 2010 23
3. Translate fixed point back to original position
2D Directional Scaling
x
S2
R 1    S  S1 , S 2   R   

 S1 cos 2   S 2 sin 2   S 2  S1  cos  sin  0 


 
y   S2  S1  cos  sin  S1 sin   S 2 cos  0 
2 2

  0 0 1 
 
S1 S1  1
2D Directional Scaling Steps: x S2  2 x
1. Rotate (scaling direction
align   45O
with the coordinate axes)
2. Scale with respect to origin
3. Rotate (scaling direction is y y
returned to original position)
April 2010 24
R(–) • S(scale) • R()
2D Reflections
Reflection- Transformation that produces a mirror image. Rotation about
reflection axis by 1800 . Reflection axis can be in xy plane or perpendicular to
xy plane. Rotation path will be in a perpendicular plane.
The inverse of a reflection corresponds to its transpose
y y y

x x

1 0 0   1 0 0   1 0 0 
0 1 0   0 1 0  0 1 0 
     
0 0 1   0 0 1   0 0 1 
Reflection about line y = 0 Reflection about line x = 0 Reflection about origin
25
(x - axis) (y - axis) (xy - axis)
2D Reflections
3

2
yx y  x
2
1
1

3
2 1 1 3

0 1 0  0 1 0 
1 0 0   1 0 0 
  
 0 0 1   0 0 1 
Reflection about line y = x Reflection about line y = - x
Clockwise Rotation by 450 Clockwise Rotation by 450
Reflection about X-axis Reflection about Y-axis
Counter - Clockwise Rotation by 450
April 2010 Counter - Clockwise Rotation by 45
26 0
2D Shear
• A shear is a transformation that distorts the shape of an object such
that the transformed shape appears as if the object was composed of
internal layers that had been caused to slide over each other.
• Two common shearing transformations are those that shift coordinate
x values and those that shift coordinate y values y

• X-direction shear relative to x-axis (y=0)


1
shifts the points in the x-direction proportional to
the y-coordinate. But y-coordinate of points are
unaffected. Eg. Square converted to a 1 x
parallelogram Initial object
Matrix y
Equations
form
x   x  shx . y 1 sh x 0 1
y  y 0 1 0
 1 2 3 x
April 2010
0 0 1 shx = 2
2D Shear
• X-direction shear relative to reference lines ( y= yref )
Eg. Square converted to horizontally shifted parallelogram
y

Equations 1

x  x  shx ( y  yref )
1 x
y  y yref = -1

Matrix form y

 x   1 shx  shx  yref  x  1

    
 y   0 1 0  y  1 2 3 x
 1  0 0 1  1 
     yref = -1
shx = ½, yref =28-1
2D Shear
• Y-direction shear relative to y-axis (x=0)
shifts the points in the y-direction proportional
to the x-coordinate. But x-coordinate of points y
are unaffected.
1
Eg. Square converted to a parallelogram
Equations 1 x
x  x Initial object

y   y  shy  x y
3

Matrix form 2

 x   1 0 0 x  1

    
 y    shy 1 0 y  1 x
1  0 0 1   1  shy = 2
   29
2D Shear
• Y-direction shear relative to reference lines (x=x ref )
Eg. Square converted to vertically shifted parallelogram y

Equations
x  x 1
y  y  shy ( x  xref )
xref = -1 1 x
Matrix form
y

 x   1 0 0  x  2

    
 y    shx 1  shy  xref  y 
1

1  0 0 1  1 
     xref = -1 1 x
shy = ½, xref = -1 30
Transformations between 2D Coordinate Systems

y
y’
x’
y0 

x0 x

•To translate the object descriptions from xy coordinates to x’y’


coordinates, we set up a transformation that superimposes the
x’y’ axes onto the xy axes. This is done in two steps:
1.Translate so that the origin (x0, y0) of the x’y’ system is moved
to the origin (0, 0) of the xy system.
2.Rotate the x’ axis onto the x axis.
31
Transformations between 2D Coordinate Systems
• Steps in matrix form:
 1 0  x0 
1)  
T ( x0 ,  y0 )   0 1  y0 
0 0 1 
 
2)  cos  sin  0 
 
R ( )    sin  cos  0 
 0 0 1 
 
Concatenating:

M xy , xy  R ( )  T ( x0 ,  y0 )
32
Order of Transformations

y y

x x
Object first translated in the x Object first rotated 90º and then
direction and then rotated 90º translated in the x direction

Matrix multiplication does not commute.


The order of transformations makes a difference

33
Composite Transformation
• We can represent any sequence of transformations
as a single matrix.
–No special cases when transforming a point – matrix • vector.
–Composite transformations – matrix • matrix.

• Composite transformations:
Rotate about an arbitrary point – translate, rotate, translate
Scale about an arbitrary point – translate, scale, translate
Change coordinate systems – translate, rotate, scale

• But the order of operations important

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy