2D Transformation, OCW_2
2D Transformation, OCW_2
Two-Dimensional
Transformations
Edited by
Dr. Md. Manjur Ahmed
Faculty of Computer Systems and Software
Engineering
[email protected]
Chapter Description
• Aims
– Basic of Computer Graphics.
• Expected Outcomes
– Understand the basic concept of computer graphics. (CO1: Knowledge)
– Ability to use the computer graphics technology. (CO1: Knowledge)
• References
– Dr. Masudul Ahsan, Dept. Of CSE, Khulna University of Engineering and Technology
(KUET), Bangladesh.
– Computer Graphics by Zhigang Xiang, Schaum’s Outlines.
– Donald Hearn & M. Pauline Baker, Computer Graphics with OpenGL, 4th Edition, Boston :
Addison Wesley, 2011.
2
Modeling Transformations
• Simulate the manipulation of objects in space
• Two contrary points of view for describing
object
– Geometric transformation –
• Relative to a stationary coordinate system
• Changes in orientation, size and shape
– Coordinate Transformation – Keeping the object
stationary while coordinate system is transformed
with respect to the stationary object.
Geometric transformation
– Basic Transformations
• Translation
• Rotation
• Scaling
• Shear
• Mirror reflection
Translation – 2D Transformation
(about the Origin)
• Object is moved to a new position
Considering distance and direction P’
• Let, new point P(x,y) is found by P
adding translation distance (tx,ty) to P(x,y).
Then displacement vector is
y
x x t x and y y t y - - - - (1)
Let’s column vector
x x t x
P P T
y y t y
Therefore, Eqn (1) can be rewritten as P P T
Rotation – 2D
• Object is rotated along a circular path using
rotation angle ()
– Rotation angle ()
• Counter clockwise, +
• Clockwise, -
– Consider center (0,0) of rotation means that origin
as pivot point
Rotation – 2D y
x r cos
P
P
y r sin
r sin( + )
r
P
r sin
x r cos( ) r
P
y
r sin( ) r cos( + ) x
r cos
r cos cos r sin sin
r cos sin r sin cos
x cos y sin
x sin y cos
Rotation – 2D
Matrix form
x x cos y sin cos sin x
y x sin y cos sin cos y
Therefore,
P R P
R is called Rotation
Matrix
Scaling – 2D
• Consider the dimensions of an object, either Expand or compress
• Scaling factors for XY Plane (2D) are defined as sx and sy.
magnification if sx (or sy) > 1
reduction if sx (or sy) < 1
x sx x , y s y y
In matrix form where S is scaling matrix.
P S P
x sx sx 0 x
ys 0
sy y
y
Scaling – 2D
• After scaling,
– Centroid can be changed and new object will be located at a different
position relative to origin
scale factors, s 2, s 1
x y 2
2 2
1 1
1/2
Types of Scaling:
Differential ( sx != sy )
Uniform ( sx = sy )
Homogeneous Co-ordinates
• Non-homogeneously: In matrix form, translation, scaling and
rotation are defined as:
– translation: P = P + T, 22 Matrix form
– Scale: P = S · P 33 Matrix form
– Rotate: P = R · P 33 Matrix form
• Composition Transformations (??)---- more than one
transformations at a time
– But translation not expressed as a matrix multiplication method, thus
difficult to determine
• Homogeneously: Allow all three transformation by the
multiplication of 33 matrices
• Each Cartesian position (x,y) is represented by a triple (xh, yh,
h), where,
xh yh
x y
h h
Homogeneous Co-ordinates
• h can have any non zero value, better to use h = 1
• allows all transformation eq as matrix multiplication,
and
1)Transformation matrices for translation
x x t x , y y t y
x 1 0 t x x
y 0 1 t y * y
1 0 0 1 1
T(t x ,t y )
Homogeneous Co-ordinates
2) Transformation matrices for rotation
x x cos y sin , y x sin y cos
x cos sin 0 x
y sin cos 0 * y
1 0 0 1 1
R( )
3) Transformation matrices for Scaling
x sx x , y s y y
x s x 0 0 x
y 0 sx 0 * y
1 0 0 1 1
S( sx ,s y )
Mirror Reflection
Y Y
(1,1)
(-1,1) (1,1)
X X
(1,-1)
B(x,y)
B1(x’,y’) B2(x’,y’)
A(h,k)
A1 (0,0) A2 (0,0)
Fixed point P(h,k) Scaling : Ssx,sy,p
Step 1: Translate P(h,k) to origin
Step 2: Scale S(sx,sy) w.r.t origin
(7,2)
Step 3: Translate (0,0) to P(h,k)
(1,1) (7,1)
Ssx,sy,P= T(h ,k) * S(sx,sy)* T(-h ,-k)
T(1,1)
(4,3)
(4,2)
(6,1)
(1,1) (4,1)
(0,0) (4,0) (0,0) (6,0)
S3/2,1/2,(1,1) T(-1,-1) S(3/2,1/2)
18