Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
26 views

Computer Graphics: Lecture 06-Transformations

The document discusses various 2D and 3D transformations including translation, rotation, scaling, and reflection. It provides the mathematical formulas to perform each transformation using matrix multiplication. For example, translation is represented by a matrix adding offsets to x and y, rotation uses trigonometric functions of the angle to modify x and y, and scaling multiples x and y by separate factors. The order of multiple transformations matters as the result depends on the matrix multiplication order.

Uploaded by

any name
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Computer Graphics: Lecture 06-Transformations

The document discusses various 2D and 3D transformations including translation, rotation, scaling, and reflection. It provides the mathematical formulas to perform each transformation using matrix multiplication. For example, translation is represented by a matrix adding offsets to x and y, rotation uses trigonometric functions of the angle to modify x and y, and scaling multiples x and y by separate factors. The order of multiple transformations matters as the result depends on the matrix multiplication order.

Uploaded by

any name
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

Computer Graphics

Lecture 06- Transformations


Lecture Outlines
• Transformation
• Types of 2D Transformation
• 2D Transformation
• Geometric
• Composite
• 3D Transformation
What is Transformation?
• The geometrical changes of an object from a current state to
modified state is referred to as TRANSFORMATION. It allows us
to change the
• position

• size and

• orientation of the objects.

• Why it is needed?
• To manipulate the initially created object

• to display the modified object without having to redraw it


Two Dimensional Transformation
• There are two complementary points of view for describing
object movement.
• The first is that the object itself is moved relative to a
stationary coordinate system or background. [Geometric
Transformations]
• The second point of view holds that the object is held
stationary while the coordinate system is moved relative to
the object. [Coordinate Transformations]
Geometric Transformations

• Translation

• Rotation about the Origin

• Scaling with Respect to the Origin

• Mirror Reflection about an Axis


Translation
• A translation moves an object to a different position on the screen

x = x + t x , y  = y + t y
P’(x’,y’)

 x  x  t x  𝑇(𝑡𝑥 , 𝑡𝑦 )
P =   , P =   , T =  
 y  y t y 
P(x,y)
P = P + T
Translation

X’=5+6=11
P’(x’,y’)
Y’=3+7= 10
𝑇(6,7)

P(5,3)
Translation

1 0 t x 
0 1 t 
 y 
0 0 1 
Rotation about the Origin
• In rotation, the object is rotated θ° about the origin.
• The convention is that the direction of rotation is counterclockwise if θ is
a positive angle .
• and clockwise if θ is a negative angle.

y y P’(x’,y’)
P(x,y)

x x
Rotation about the Origin
The transformation of rotation R is
P’ = R.P
where x’ = xcos(θ) - y sin(θ)
and y’ = xsin(θ) + ycos(θ)

 x  cos − sin   x 


 y =  sin cos   y 
  

cos − sin 0
Rotation =
 sin cos 0
 
 0 0 1
Rotation about the Origin
sin(A + B) = sin A cos B + cos A sin B
cos(A + B) = cos A cos B − sin A sin B
• Derivation of the rotation equation
=> cos  = x/r , sin = y/r
• x = r. cos , y = r.sin 
P’(x’, y’)
=> cos (+ ) = x’/r
=> x’ = r. cos (+ )
= r(coscos -sinsin) 
r
= r.coscos - r.sinsin
= x.cos  – y.sin  y’ P(x,y)
 r
y
=>sin (+ ) = y’/r 
=>y’ = r. sin (+ )
x
= r(sincos + cossin) x’
=r.sincos + r.cossin
= y.cos  + x.sin  = x.sin  +y.cos 
Rotation about the Origin
Given point as (4, 4). Apply 30 degree rotation anticlockwise direction on the line
segment and find out the new coordinates of the line .
y
P’(x’,y’)
30𝑜 P(4,4)

Given Point= (X, Y) = (4, 4)


Rotation angle = θ = 30º

Let new ending coordinates of the line after rotation = (x’, y’).
Rotation about the Origin

Applying the rotation equations, we have-

X’= xcos(θ) - y sin(θ) Y’ = xsin(θ) + ycos(θ)


= 4 x cos30º – 4 x sin30º = 4 x sin30º + 4 x cos30º
= 4 x (√3 / 2) – 4 x (1 / 2) = 4 x (1 / 2) + 4 x (√3 / 2)
= 2√3 – 2 = 2 + 2√3
= 2(√3 – 1) = 2(1 + √3)
= 2(1.73 – 1) = 2(1 + 1.73)
= 1.46 = 5.46

Thus, New ending coordinates of the line after rotation = (1.46, 5.46).
Scaling with Respect to the origin
• Scaling is the process of expanding or compressing the dimension of an object. To
change the size of an object, scaling transformation is used.
• Positive scaling constants sx and sy are used to describe changes in length with
respect to the x direction and y direction, respectively.
• The scaling transformation ssx.sy is given by P’ = S.P
where, x’ = sxx and y’ = syy.
• After a scaling transformation is performed, the new object is located at a different
position relative to the origin.

Original Object Scaling factors sx =2


Scaling factors sy =1/2
Scaling with Respect to the origin

 sx 0 0
0 sy 0 
 
 0 0 1
Scaling with Respect to the origin
x’ = sxx Given a square object with coordinate points A(0, 3), B(3, 3),
y’ = syy C(3, 0), D(0, 0). Apply the scaling parameter 2 towards X axis
and 3 towards Y axis and obtain the new coordinates of the
object.

Given-
•Scaling factor along X axis, sx = 2
•Scaling factor along Y axis, sy = 3

A(0, 3):- B(3, 3):-


new coordinates of corner A after scaling
=(x’,y’). •X’ = 3 x 2 = 6
•Y’ = 3 x 3 = 9
•X’= 0 x 2 = 0 New coordinates of corner B after
• y’= 3 x 3 = 9 scaling = (6, 9).
New coordinates of corner A after scaling =
(0, 9).
Scaling with Respect to the origin
Given-
x’ = sxx •Scaling factor along X axis, sx = 2
•Scaling factor along Y axis, sy = 3
y’ = syy

C(3, 0):-
Applying the scaling equations, we have-
•X’= 3 x 2 = 6
•Y’= 0 x 3 = 0

Thus, New coordinates of corner C after scaling = (6, 0).

D(0, 0):-
Applying the scaling equations, we have-
•X’= 0 x 2 = 0
•Y’= 0 x 3 = 0

Thus, New coordinates of corner D after scaling = (0, 0).


Scaling with Respect to the origin
Mirror Reflection about an Axis
• If either the x and y axis is treated as a mirror,
the object has a mirror image or reflection.
• Since the reflection P’ of an object point P is
located the same distance from the mirror as
P (Fig. 4.5), the mirror reflection transformation
Mx about the x-axis is given by P’= Mx(P)
where x’ = x and y’ = −y.
• Similarly, the mirror reflection about the y-axis is
P’= My(P) .
where, x’ = -x and y’ = y.
Composite Transformation

• If we want to apply a series of transformation T1,T2,T3 to a


set of points, we can do it like below-

• Calculate, T = T1 x T2 x T3

then P’ = T x P

• This method saves large number of adds and multiplications.


• We can represent any sequence of transformations as a single
matrix.
• Composite transformations – matrix • matrix.
Example
• Translation:
• Translate (x,y) by (tx1,ty1) and then again by
(tx2,ty2).
• Here, first calculate, T = T1 x T2
• Then, P’= T x P
• Scaling :
• Same as translation.
• Rotation:
• Calculate T1 for θ1, then T2 for θ2 and multiply them.
• Then P’= T x P
Transformations are NOT
Commutative
• If we scale /rotate and then translate is that equivalent to
translate first and then scale/rotate?

• No, because in general case result of matrix multiplication


depends on the order.

• So, the order of transformation has to be maintained .


Order of operations
It does matter. Let’s look at an example:

1. Translate 1. Rotate
2. Rotate 2. Translate
3D Transformations
• 3D Translation is a process of moving an object
from one position to another in a three dimensional
plane.
• Homogeneous coordinates: (x,y,z)
• Transformations are now represented as 4x4
matrices
3D 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
3D 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 
3D Rotation
• Rotation in 3D is about an axis in 3D space
• Hence, rotation matrix is different for all the x, y
and z axis!
3D Rotation
About z-axis

R * P = P
  
cos − sin  0 0  x   x * cos − y * sin  
 sin  cos 0 0  y   x * sin  + y * cos 
 * =
 0 0 1 0  z   z 
     
 0 0 0 1  1   1 
3D Rotation
About y-axis

R * P = P
  
 cos 0 sin  0  x   x * cos + z * sin  
 0 1 0 0   y  y 
 *  =  
− sin  0 cos 0  z  − x * sin  + z * cos 
     
 0 0 0 1    
1 1 
3D Rotation
About x-axis

R * P = P
  
1 0 0 0  x   x 
0 cos − sin  0  y   y * cos − z * sin  
 * =
0 sin  cos 0  z   y * sin  + z * cos 
     
0 0 0 1  1   1 

You might also like