0% found this document useful (0 votes)
52 views

Computer Graphics (CSE 4103)

The document discusses geometric transformations in 2D graphics. It describes translations, rotations, reflections, and scaling as the main types of geometric transformations. It explains how transformations can be represented using homogeneous coordinates and matrix multiplication, allowing multiple transformations to be combined. This allows complex transformations to be computed by multiplying matrices in sequence.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views

Computer Graphics (CSE 4103)

The document discusses geometric transformations in 2D graphics. It describes translations, rotations, reflections, and scaling as the main types of geometric transformations. It explains how transformations can be represented using homogeneous coordinates and matrix multiplication, allowing multiple transformations to be combined. This allows complex transformations to be computed by multiplying matrices in sequence.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

Department of Computer Science and Engineering,

Computer Graphics (CSE 4103)

University of Dhaka
Lecture 10
Geometric Transformation
Transformation
Ability to simulate both the movement and the manipulation of
objects in the plane.

Types of Transformation:
i) Geometric Transformation
ii) Coordinate Transformation
Geometric Transformation
Translation

• Simple move from one location to another location


• Same distance
• Same direction
April 2010
Geometric Transformation
Translation

y
x′ = x + t x , y ′ = y + t y
P′
 x  x′  t x 
T P =   , P′ =   , T =  
 y  y′ t y 
P x P′ = P + T
Geometric Transformation
Rotation

• Turning around a center


• The distance from the center to any point on the shape stays
the same.
• Every point makes a circle around the center.
April 2010
Geometric Transformation
Rotation
Rotation in angle θ about a

pivot (rotation) point ( xr , yr ) .


y
P’(x’,y ’ )

x′ = xr + ( x − xr ) cos θ − ( y − yr ) sin θ
r P(x,y)
θ
r y′ = yr + ( x − xr ) sin θ + ( y − yr ) cos θ
x
P′ = Pr + R ⋅ ( P − Pr )
Φ

cos θ − sin θ 
R=
 sin θ cos θ 

7
April 2010
Geometric Transformation
Scaling

Dilation changes the size of the shape without changing the


shape.
Enlarge means to make a shape bigger.

Reduce means to make a shape smaller.


The scale factor tells you how much something is enlarged or
reduced.
April 2010
Geometric Transformation
Scaling x′ = x ⋅ s x , y ′ = y ⋅ s y
Sx
 x′   s x 0   x
 y′ =  0 s y   y 
Sy   
P′ = S ⋅ P
y Scaling about a fixed point ( x f , y f )
x′ = x ⋅ sx + x f (1 − sx )

y′ = y ⋅ s y + y f (1 − s y )
(x f , yf )
x
P′ = P ⋅ S + P f ⋅ ( 1 - S )

9
Homogeneous Coordinates
Rotation and scaling can be represented by matrix
multiplication, but translation is a vector addition.
It would be nice if all the basic transformations are matrix
multiplication. Then it is possible to represent multiplying
matrices.
It turns out we can do this if we represent 2-D points not by a
pair of numbers (x, y), but by triple (X, Y, Z), which is called a set
of homogeneous coordinates.
Homogeneous Coordinates
 x′   1 0 t x   x 
2D Translation
   y   ( x y)
 y ′  =  0 1 t  ⋅  y  , P′ = T t , t ⋅ P
 1  0 0 1   1 

 x′  cos θ − sin θ 0  x 
2D Rotation  y′ =  sin θ cos θ 0  ⋅  y  , P′ = R (θ ) ⋅ P
  
 1   0 0 1   1 

 x′   S x 0 0  x 
2D Scaling  y′ =  0
   Sy 0  ⋅  y  , P′ = S ( S x , S y ) ⋅ P
 1   0 0 1   1 
April 2010
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 ⋅ M1 ) ⋅ P = M ⋅ P

{ } { }
P′ = T ( t2 x , t2 y ) T ( t1x , t1 y ) ⋅ P = T ( t2 x , t2 y ) ⋅ T ( t1x , t1 y ) ⋅ P

1 0 t2 x  1 0 t1x  1 0 t1x + t2 x 
0 1 t  ⋅ 0 1 t  = 0 1 t + t 
Composite translations:
 2y   1y   1y 2y 

0 0 1  0 0 1  0 0 1 

T ( t2 x , t2 y ) ⋅ T ( t1x , t1 y ) = T ( t1x + t2 x , t1 y + t2 y )

12
April 2010
Homogeneous Coordinates
P′ = R (θ 2 ) {R (θ1 ) ⋅ P} = {R (θ 2 ) ⋅ R (θ1 )} ⋅ P

Composite Rotations: R (θ 2 ) ⋅ R (θ1 ) = R (θ1 + θ 2 )

P′ = R (θ1 + θ 2 ) ⋅ P

 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 

Composite Scaling: S ( S 2 x , S 2 y ) ⋅ S ( S1x , S1 y ) = S ( S1x ⋅ S 2 x , S1 y ⋅ S 2 y )

13
Geometric Transformation
CHANGE THE POSTION CHANGE THE SIZE OF A
OF A SHAPE SHAPE

TRANSLATION ROTATION REFLECTION Scaling/Dialation

Change in Turn around a Flip over a Change size of


location point line a shape
Geometric Transformations by Rasterization
• The transformed shape needs to be filled.
– A whole scan-line filling is usually in order.
• However, simple transformations can save new filling by
manipulating blocks in the frame buffer.

Pmax

Pmin
P0

Translation:
Move block of pixels of frame buffer into new destination.
April 2010
Geometric Transformation
2D Reflection
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 

16
April 2010
Geometric Transformation
Move to origin Rotate Move back

( xr , yr )

1 0 xr  cos θ − sin θ 0  1 0 − xr 
0 1 yr  ⋅  sin θ cos θ 0  ⋅ 0 1 − yr  =

0 0 1   0 0 1  0 0 1 

cos θ − sin θ xr (1 − cos θ ) + yr sin θ 


 
 sin θ cos θ yr (1 − cos θ ) − xr sin θ 
 0 0 1 

17
Geometric Transformation
Move to origin
Scaling Scale Move back

(x f , yf )

1 0 x f  Sx 0 0  1 0 − x f   S x 0 x f (1 − S x ) 
 
0 1
 y f  ⋅  0 Sy   
0  ⋅ 0 1 − y f  =  0 Sy y f (1 − S y ) 
0 0 1   0 0 1  0 0 1   0 0 1

 
Composition of 2D Transformation
There are many situations in which the final transformation of a point is a
combination of several individual transformations. For example, the position of the
finger of a robot might be a function of the rotation of the robots hand, arm, and
torso, as well as the position of the robot on the railroad train and the position of the
train in the world, and the rotation of the planet around the sun, and . ….

Applying each transformation individually to all points in a model would take a lot
of time. Instead of applying several transformations matrices to each point we want
to combine the transformations to produce 1 matrix which can be applied to each
point.
Composition of 2D Transformation
Example: Consider any arbitrary point P (x, y). To perform a simple rotation. We need
to perform the following steps
i) Translate such that P1 is in origin
ii) Rotate
iii) Translate such that the point at the origin returns to P1
Composition of 2D Transformation
Composition of 2D Transformation
Example 1: Write a general form of the matrix for rotation about
a point P(h, k)

1 0 h cos Φ -sin Φ 0 1 0 -h
R Φ, P = 0 1 k sin Φ cos Φ 0 0 1 -k
0 0 1 0 0 1 0 0 1

cos Φ -sin Φ [-h cos Φ + k sin Φ+ h]

= sin Φ cos Φ [-h sin Φ - k cos Φ+ k]


0 0 1
Composition of 2D Transformation
Example 2: Perform a 450 rotation of triangle A(0, 1), B(1, 1), C(5, 2)
(a) About Origin (b) about P (-1,-1)
A B C
0 1 5
0 1 2
1 1 1

(a) About Origin

A B C
cos 45 -sin 45 0 0 1 5
R 45 = sin 45 cos 45 0 0 1 2
0 0 1 1 1 1
Composition of 2D Transformation
Example 2: Perform a 450 rotation of triangle A(0, 1), B(1, 1), C(5, 2)
(a) About Origin (b) about P (-1,-1)
A B C
0 1 5
0 1 2
1 1 1

(b) About P (-1, -1)

1 0 -1 cos 45 -sin 45 0 1 0 1 0 1 5
R 45, P = 0 1 -1 sin 45 cos 45 0 0 1 1 0 1 2
0 0 1 0 0 1 0 0 1 1 1 1
Composition of 2D Transformation
Example 3: 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.
A B C
0 1 5
0 1 2
1 1 1

1 0 5 2 0 0 1 0 -5 0 1 5
R 2,2,C = 0 1 2 0 2 0 0 1 -2 0 1 2
0 0 1 0 0 1 0 0 1 1 1 1
April 2010
3D Transformations
Translation
Very similar to 2D. Using 4x4 matrices rather than 3x3.

Translation
x′ = x + t x
y
y′ = y + t y

z′ = z + t z

( x′, y′, z′ )  x′   1 0 0 tx   x 
( x, y , z )  y′  0
 = 1 0 t y   y 

 z′  0 0 1 tz   z 
z x      
 1  0 0 0 1  1 

26
April 2010
3D Transformations
Rotation

cos Φ -sin Φ 0
R Φ, Z= sin Φ cos Φ 0
0 0 1

cos Φ 0 sin Φ
R Φ, Y= 0 1 0
-sin Φ 0 cos Φ

1 0 0
R Φ, X= 0 cos Φ -sin Φ
0 sin Φ cos Φ
April 2010
General 3D Rotation

1. Translate the object such that rotation axis passes through


the origin.
2. Rotate the object such that rotation axis coincides with one
of Cartesian axes.
3. Perform specified rotation about the Cartesian axis.
4. Apply inverse rotation to return rotation axis to original
direction.
5. Apply inverse translation to return rotation axis to original
position.

28
April 2010
y y y
P2
P2′
P1
P1′ P1′
x x x
P2′′
z z z

y y y
P2′ P2

P1′ P1′ P1

P2′′ x x x
θ
z z z

29
April 2010
1 0 0 − x1 
0 1 0 − y1 
The vector from P1 to P2 is: T=
0 0 1 − z1 
V = P2 − P1 = ( x2 − x1 , y2 − y1 , z2 − z1 ) 
0 0 0 1 

Unit rotation vector: u = V | V |= ( a, b, c )

a = ( x2 − x1 ) | V | y u = ( a , b, c )
b = ( y2 − y1 ) | V |

c = ( z2 − z1 ) | V |
x
a 2 + b2 + c2 = 1
z

30
April 2010
Rotating u to coincide with z axis

First rotate u around x axis to lay in x − z plane.

Equivqlent to rotation u 's projection on y − z plane around x axis.

cos α = c b 2 + c 2 = c d , sin α = b d .

( )
We obtained a unit vector w = a, 0, b 2 + c 2 = d in x − z plane.
y u = ( a, b, c )
1 0 0 0
0 c d −b d 0  u′
R x (α ) = 
0 b d c d 0 α
  α x
0 0 0 1
z

31
April 2010
Rotate w counterclockwise around y axis.

w is a unit vector whose x − component is a, y − component is 0,

hence z − component is b 2 + c 2 = d . y u = ( a, b, c )
cos β = d , sin β = −a

d 0 a 0 β x
0 1 0 0 
Ry (β ) = 
−a 0 d 0 z
 
0 0 0 1 w = ( a, 0, d )

R (θ ) = T−1 ⋅ R −x 1 (α ) ⋅ R −y1 ( β ) ⋅ R z (θ ) ⋅ R y ( β ) ⋅ R x (α ) ⋅ T

32
April 2010
cos θ − sin θ 0 0
 sin θ cos θ 0 0 
R z (θ ) = 
 0 0 1 0
 
 0 0 0 1

R (θ ) = T−1 ⋅ R −x 1 (α ) ⋅ R −y1 ( β ) ⋅ R z (θ ) ⋅ R y ( β ) ⋅ R x (α ) ⋅ T

MR (θ ) =

 a2 (1 − cosθ ) + cosθ ab (1 − cosθ ) − c sin θ ac (1 − cosθ ) + b sin θ 


 
ba (1 − cos θ ) + c sin θ b2
(1 − cos θ ) + cos θ bc (1 − cos θ ) − a sin θ 
ca (1 − cosθ ) − b sin θ cb (1− cosθ ) + a sin θ c2 (1 − cosθ ) + cosθ 
 

33
April 2010
3D Scaling
y y
x′ = x ⋅ S x

y′ = y ⋅ S y

z′ = x ⋅ S z

z x z x
Enlarging object also moves it from origin

 x′   S x 0 0 0  x 
 y′  0 Sy 0 0   y 
P′ =   =  ⋅ = S⋅P
 z′   0 0 Sz 0  z 
     
1  0 0 0 1  1 

34
April 2010
Scaling with respect to a fixed point (not necessarily of object)

y y y

(x f , yf , zf ) (x f , yf , zf ) (x f , yf , zf )
z x z x z x

y
Sx 0 0 (1 − S x ) x f 
 
−1 
T⋅S ⋅T = 
0 Sy 0 (1 − S y ) y f 
( xf , yf , z f ) 0 0 Sz (1 − S z ) z f 
 0 0 0 1 
z x

35
Thank you

You might also like