Mod1_2
Mod1_2
Lecture 4
Transformations
Transformations
- altering or manipulating displays
- animation sequences
◼ 2D Transformations
◼ Homogeneous Coordinates
◼ 3D Transformations
Transformations
◼ Translation
◼ Rotation
◼ Scaling
◼ Reflection
◼ Shearing
Transformations
◼ transforming an object = transforming all its
points
x' a b x x' = ax + by
y ' = c d y y ' = cx + dy
◼ transformations combined by multiplication
x' a b d e h i x
y ' = c d f
g j k y
◼ matrices are efficient, convenient way to represent
sequence of transformations!
2D Translation
vector addition
(x′,y′)
x a x + a x'
(x,y) ( a, b) y + b = y + b = y '
2
Scaling
◼ non-uniform scaling: different scalars per
component:
X 2,
Y 0.5
SCALING
Uniform scaling
◼
scaling matrix
2D rotation
2D rotation
2D Rotation
◼ counterclockwise
(x′, y′)
◼ RHS
(x, y)
x′ = x cos() - y sin()
y′ = x sin() + y cos()
2D Rotation From Trig Identities
x = r cos ()
y = r sin ()
x′ = r cos ( + )
y′ = r sin ( + )
(x′, y′)
Trig Identity…
(x, y) x′ = r cos() cos() – r sin() sin()
y′ = r sin() cos() + r cos() sin()
Substitute…
x ′ = x cos() - y sin()
y ′ = x sin() + y cos()
2D Rotation Matrix
x x
Reflection
◼ reflect across x axis
◼ mirror x 1 0 x 0
y = 0 +
− 1 y 0
x x
◼ Reflection about y=0; ie the x axis is obtained by
0 − 1
[T ] =
1 0
8 1 8 − 1
7 3 1 0 = 7 − 3
0 − 1
6 2 6 − 2
◼ Reflection about the line y=x occurs for
0 1
[T ] =
1 0
8 1 1 8
7 3 0 1 = 3 7
1 0
6 2 2
6
◼ Similarly reflection about x=0, the y axis is
given by
− 1 0
[T ] =
0 1
◼ Similarly a reflection about the line y=-x is
given by
0 −1
[T ] =
− 1 0
(x’,y’)
x a x + a x'
(x,y) ( a, b) y + b = y + b = y '
2D Translation
(x′,y′)
x a x + a x'
(x,y) ( a, b) y + b = y + b = y '
vector addition
(x′,y′)
x a x + a x'
(x,y) ( a, b) y + b = y + b = y '
matrix multiplication matrix multiplication
x ' a 0 x x' cos( ) − sin ( ) x
y ' = 0 b y y ' = sin ( ) cos( ) y
◼ Reflecting the 4 − 1 1 − 4
0 − 1
triangle A*B*C* [ X + ] = [ X *] [T2 ] = 5 − 2 = −
− 1 0
2 5
4 − 3 3 − 4
about the line y=-x
yields
If two pure reflection transformations about
lines passing through the origin are applied
successively, the result is pure rotation about the
origin.
◼ Rotation about the origin by an angle
θ=270º yields the identical results.
4 1 1 − 4
+ 0 − 1
[ X ] = [ X *] [T3 ] = 5 2 = −
0
2 5
4 3 1
3 − 4
Combined 2D transformations
◼ Consider the
triangle ABC, the 0 1
two transformation [T1 ] =
− 1 0
are +90 degree
rotation about the
origin: 0 − 1
◼ And a reflection [T2 ] =
− 1 0
through the line
y=-x
◼Intermediate
◼ result
Final result
◼
◼ The effect of the combined transformation [T3] =
[T1] [T2] on the triangle ABC is
[X*] =[X ][T1] [T2] = [X][T3] ----(A)
(A)≠(B)
The results are different confirming that the order of
application of the transformation is important.
Exercises 1
◼ Translate the shape below by (7, 2)
◼ y
◼ 6
◼ 5
◼ 4
◼ 3 ◼ (2, 3)
◼ 2◼ (1, 2) (3, 2)
◼
◼ 1
◼ (2, 1)
0
◼
◼ 1 ◼ 2 ◼ 3 ◼ 4 ◼ 5 ◼ 6 ◼ 7 ◼ 8 ◼ 9 ◼ 10 x
◼
Exercises 2
◼ 5
◼ 4
◼ 3 ◼ (2, 3)
◼ 2◼ (1, 2) (3, 2)
◼
◼ 1
◼ (2, 1)
0
◼
◼ 1 ◼ 2 ◼ 3 ◼ 4 ◼ 5 ◼ 6 ◼ 7 ◼ 8 ◼ 9 ◼ 10 x
◼
Exercises 3
◼ 5
◼ 4
◼ 3 ◼ (7, 3)
◼ 2 (6, 2)
◼ (8, 2)
◼
◼ 1
◼ (7, 1)
0
◼
◼ 1 ◼ 2 ◼ 3 ◼ 4 ◼ 5 ◼ 6 ◼ 7 ◼ 8 ◼ 9 ◼ 10 x
◼
Exercise 4
◼ Write out the homogeneous matrices for the
previous three transformations
◼ 4
◼ (5, 4)
◼ 3 (4, 3)
◼ (6, 3)
◼
◼ 2
◼ (5, 2)
◼ 1
◼ 0 ◼ 1 ◼ 2 ◼ 3 ◼ 4 ◼ 5 ◼ 6 ◼ 7 ◼ 8 ◼ 9 ◼ 10
Scratch
◼ y
◼ 6
◼ 5
◼ 4
◼ 3
◼ 2
◼ 1
0
◼
◼ 1 ◼ 2 ◼ 3 ◼ 4 ◼ 5 ◼ 6 ◼ 7 ◼ 8 ◼ 9 ◼ 10 x
◼
Equations
◼ Translation:
◼ xnew = xold + dx ynew = yold + dy
◼ Scaling:
◼ xnew = Sx × xold ynew = Sy × yold
◼ Rotation
◼ xnew = xold × cosθ – yold × sinθ
◼ ynew = xold × sinθ + yold × cosθ
Linear Transformations
◼ linear transformations are combinations of
◼ scale
x' a b x x' = ax + by
y ' = c d y
◼ rotate
◼ Reflect y ' = cx + dy
a b c x a * x + b * y + c * z
d e
f y = d * x + e * y + f * z
g h i z g * x + h * y + i * z
Homogenous Coordinates
sx 0 0 x sx x
0 sy 0 y = sy y : v' = S ( sx, sy )v
Scaling:
◼
0 0 1 1 1
Homogenous Coordinates (cont…)
◼ Rotation:
1 0 − dx
−1 1
T = 0 1 − dy s 0 0
0 0 1 x
1
S −1 = 0 0
cos sin 0 sy
0 0 1
R = − sin cos 0
−1
0 0 1
Composite Transformation (1/2)
◼ Translation
◼ If two successive translation factor (t , t ) and x1 y1
◼ then
P' = T2(tX2,ty2) {T1(tx1,ty1) P} = {T2(tX2,ty2) T1(tx1,ty1)} P
1 0 tx2 1 0 tx1 1 0 tx1 + tx2
◼ ex) 0 1 ty2 0 1 ty1 = 0 1 ty1 + ty2
0 0 1 0 0 1 0 0 1
i.e,
◼ Two successive Translation are additive
Composite Transformation (2/2)
◼ Rotation
◼ two successive rotation
,
P = R( 2) {R( 1) P} = {R( 2) R( 1)} P
R( 1) R( 2) = R( 1 + 2)
P' = R( 1 + 2) P
◼ two successive rotations are also additive
◼ Scaling
sx2 0 0 sx1 0 0 sx1 sx2 0 0
0 sy2 0 0 sy1 0 = 0 sy1 sy2 0
0 0 1
0 0 1
0 0 1
S(SX2,SY2) S(SX1,SY1) = S(SX1 SX2,SY1 SY2)
General pivot-point Rotation (1/2)
◼ Rotation about arbitrary point p (x , y )
r r
xr cos − sin − xr
yr sin cos − yr
cos − sin xr ( − cos ) + yr sin
= sin cos yr ( − cos ) − xr sin
World Coordinates
Windowing:
◼ When we display a scene/picture only
those objects within a particular window
are displayed
◼Window
wymax
◼
wymin
◼
◼ wxmin ◼wxmax
World Coordinates
Windowing:
◼ Because drawing things to a display takes
time we clip everything outside the window
◼Window
wymax
◼
wymin
◼
◼wxmin ◼wxmax
World Coordinates
Clipping:
◼ When we have to display a large portion of the
picture, then not only scaling & translation is
necessary, the visible part of picture is also
identified. This process is not easy. Certain parts of
the image are inside, while others are partially
inside. The lines or elements which are partially
visible will be omitted.
◼ For deciding the visible and invisible portion, a
particular process called clipping is used. Clipping
determines each element into the visible and
invisible portion. Visible portion is selected. An
invisible portion is discarded.
Types of clipped lines:
◼ Visible: A line or lines entirely inside the
window is considered visible
◼ Invisible: A line entirely outside the window
is considered invisible
◼ Clipped: A line partially inside the window
and partially outside is clipped. For clipping
point of intersection of a line with the window
is determined.
Types of clipped lines:
Continued..
◼ Clipping can be applied through hardware as
well as software.
◼ In some computers, hardware devices
automatically do work of clipping. In a system
where hardware clipping is not available
software clipping applied.
Application of clipping:
◼ It will extract part we desire.
◼ For identifying the visible and invisible area in
the 3D object.
◼ For creating objects using solid modeling.
◼ For drawing operations.
◼ Operations related to the pointing of an
object.
◼ For deleting, copying, moving part of an
object.
Types of clipping:
◼ Point Clipping
◼ Line Clipping
◼ Area Clipping (Polygon)
◼ Curve Clipping
◼ Text Clipping
◼ Exterior Clipping
Point clipping:
Point Clipping is used to determining, whether
the point is inside the window or not. For this
following conditions are checked.
◼ x ≤ xmax
◼ x ≥ xmin
◼ y ≤ ymax
◼ y ≥ ymin