Computer Graphics: Lecture 06-Transformations
Computer Graphics: Lecture 06-Transformations
• size and
• Why it is needed?
• To manipulate the initially created object
• Translation
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(θ)
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(coscos -sinsin)
r
= r.coscos - r.sinsin
= x.cos – y.sin y’ P(x,y)
r
y
=>sin (+ ) = y’/r
=>y’ = r. sin (+ )
x
= r(sincos + cossin) x’
=r.sincos + r.cossin
= 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)
Let new ending coordinates of the line after rotation = (x’, y’).
Rotation about the Origin
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.
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
C(3, 0):-
Applying the scaling equations, we have-
•X’= 3 x 2 = 6
•Y’= 0 x 3 = 0
D(0, 0):-
Applying the scaling equations, we have-
•X’= 0 x 2 = 0
•Y’= 0 x 3 = 0
• Calculate, T = T1 x T2 x T3
then P’ = T x P
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