Documente Academic
Documente Profesional
Documente Cultură
Technology (NUST)
School of Electrical Engineering and Computer Science
(SEECS)
• Rotation
• Translation
• Shear
• Combination of transformations
• Matrix representation
• Matrix composition
2D Modeling Transformations
Modeling Coordinates
Scale
y Translate
Scale
Rotate
Translate
World Coordinates
2D Modeling Transformations
Modeling Coordinates
y
Let’s look
at this in
detail…
World Coordinates
2D Modeling Transformations
Modeling Coordinates
y
Initial location
at (0, 0) with
x- and y-axes
aligned
2D Modeling Transformations
Modeling Coordinates
y
Scale .3, .3
Rotate -90
Translate 5, 3
2D Modeling Transformations
Modeling Coordinates
y
Scale .3, .3
Rotate -90
Translate 5, 3
2D Modeling Transformations
Modeling Coordinates
y
Scale .3, .3
Rotate -90
Translate
World Coordinates
Scaling
• Scaling a coordinate means multiplying each of its
components by a scalar
• Uniform scaling means this scalar is the same for all
components:
2
Scaling
• Non-uniform scaling: different scalars per
component:
X 2,
Y 0.5
scaling matrix
Rotation
(x’, y’)
(x, y)
x’ = x cos() - y sin()
y’ = x sin() + y cos()
Rotation
x = r cos (f)
y = r sin (f)
x’ = r cos (f + )
y’ = r sin (f + )
(x’, y’)
Trig Identity…
(x, y) x’ = r cos(f) cos() – r sin(f) sin()
y’ = r cos(f) sin() + r sin(f) cos()
f
Substitute…
x’ = x cos() - y sin()
y’ = x sin() + y cos()
Rotation
• This is easy to capture in matrix form:
• Translation:
– x’ = x + tx
– y’ = y + ty
• Scale:
– x’ = x * sx
– y’ = y * sy
• Shear:
– x’ = x + hx*y
– y’ = y + hy*x
• Rotation: Transformations
– x’ = x*cosQ - y*sinQ
– y’ = x*sinQ + y*cosQ can be combined
(with simple algebra)
Basic 2D Transformations
• Translation:
– x’ = x + tx
– y’ = y + ty
• Scale:
– x’ = x * sx
– y’ = y * sy
• Shear:
– x’ = x + hx*y
– y’ = y + hy*x
• Rotation:
– x’ = x*cosQ - y*sinQ
– y’ = x*sinQ + y*cosQ
Basic 2D Transformations
• Translation:
– x’ = x + tx
– y’ = y + ty
• Scale:
– x’ = x * sx (x,y)
– y’ = y * sy
(x’,y’)
• Shear:
– x’ = x + hx*y
– y’ = y + hy*x
• Rotation:
– x’ = x*cosQ - y*sinQ x’ = x*sx
– y’ = x*sinQ + y*cosQ y’ = y*sy
Basic 2D Transformations
• Translation:
– x’ = x + tx
– y’ = y + ty
• Scale:
– x’ = x * sx
– y’ = y * sy
• Shear:
– x’ = x + hx*y
– y’ = y + hy*x
• Rotation: (x’,y’)
– x’ = x*cosQ - y*sinQ
– y’ = x*sinQ + y*cosQ x’ = (x*sx)*cosQ - (y*sy)*sinQ
y’ = (x*sx)*sinQ + (y*sy)*cosQ
Basic 2D Transformations
• Translation:
– x’ = x + tx
– y’ = y + ty
• Scale:
– x’ = x * sx
– y’ = y * sy (x’,y’)
• Shear:
– x’ = x + hx*y
– y’ = y + hy*x
• Rotation:
– x’ = x*cosQ - y*sinQ x’ = ((x*sx)*cosQ - (y*sy)*sinQ) + tx
– y’ = x*sinQ + y*cosQ y’ = ((x*sx)*sinQ + (y*sy)*cosQ) + ty
Basic 2D Transformations
• Translation:
– x’ = x + tx
– y’ = y + ty
• Scale:
– x’ = x * sx
– y’ = y * sy
• Shear:
– x’ = x + hx*y
– y’ = y + hy*x
• Rotation:
– x’ = x*cosQ - y*sinQ x’ = ((x*sx)*cosQ - (y*sy)*sinQ) + tx
– y’ = x*sinQ + y*cosQ y’ = ((x*sx)*sinQ + (y*sy)*cosQ) + ty
Matrix Representation
• Represent 2D transformation by a
matrix
a b
c d
• Multiply matrix by column vector
apply transformation to point
x' a b x x' ax by
y' c d y y ' cx dy
Matrix Representation
• Transformations combined by
multiplication
x' a b e f i j x
y ' c d g h k l y
2D Shear?
x ' x shx * y x ' 1 shx x
y ' shy * x y y ' sh 1 y
y
2x2 Matrices
• What types of transformations can be
represented with a 2x2 matrix?
2D Mirror about Y axis?
x' x x ' 1 0 x
y' y y' 0 1 y
2D Translation?
x' x t x
NO!
y' y t y
Homogeneous Coordinates
x' x t x
y' y t y
Homogeneous Coordinates
•Homogeneous coordinates
x
x homogeneous coords
– represent coordinates in 2 y y
dimensions with a 3-vector 1
y' y t y
1 0 t x
Translation 0 1 t y
0 0 1
Translation
Example of translation •Homogeneous Coordinates
x ' 1 0 t x x x t x
y ' 0 1 t y y t
y y
1 0 0 1 1 1
tx = 2
ty = 1
Basic 2D Transformations
• Basic 2D transformations as 3x3 matrices
x ' s x 0 0 x
x ' 1 0 t x x y ' 0 sy 0 y
y ' 0 1 t y
y 1 0 0 1 1
1 0 0 1 1
Translate Scale
Rotate Shear
Reflection
• Reflection with respect to the axis
• x • y • xy
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
y 1 y y
1 1’ 1’
2 3 2 3 3’ 2 3’ 2
x x 3 x
2’ 3’ 1
1’ 2
Reflection
Reflection with respect to a Line
y
0 1 0
1 0 0
x
0 0 1
y=x
1’
Matrix Composition
• Transformations can be combined by matrix
multiplication
p’ = (T * (R * (S*p) ) )
p’ = (T*R*S) * p
Matrix Composition
• Be aware: order of transformations
matters
• Matrix multiplication is not commutative
p’ = T * R * S * p
Matrix Composition
•What if we want to rotate?
– Ex: Rotate line segment by 45 degrees about
endpoint ‘a’
a a
Multiplication Order – Wrong Way
a
a a
Wrong Correct
R(45) T(-3) R(45) T(3)
3D Concept
• Besides the 2D xy plane, a third dimension of depth is
added Y
x' a b c d x
y' e f g h y
z' i j k l z
w' m p w
n o
3D Translation
• Translation of a Point
x' x t x , y' y t y , z' z t z
x
z
3D Translation
• Translation of a Point
x' 1 0 0 tx x
y ' 0 1 0
t y y
z ' 0 0 1 tz z
1 0 0 0 1 1
3D Scaling
• Uniform Scaling
x' x s x , y' y s y , z' z sz
x
z
3D Scaling
x' s x 0 0 0 x
y ' 0 sy 0 0 y
z' 0 0 sz 0 z
1 0 0 0 1 1
y y y y
z x z x z x z x
z x z x z x z x
x' 1 0 0 x f sx 0 0 0 1 0 0 x f x
y ' 0 1 0 y f 0 s y 0 0 0 1 0 y f y
T ( x f , y f , z f ) S ( s x , s y , s z ) T ( x f , y f , z f )
z ' 0 0 1 z f 0 0 sz 0 0 0 1 z f z
1 0 0 0 1 0 0 0 1 0 0 0 1 1
3D Rotation
• Coordinate-Axes Rotations
– X-axis rotation
– Y-axis rotation
– Z-axis rotation
• General 3D Rotations
– Rotation about an axis that is parallel to one of the
coordinate axes
– Rotation about an arbitrary axis
Coordinate-Axes Rotations
• X-Axis Rotation
x' 1 0 0 0 x
y ' 0 cos sin 0 y
z ' 0 sin cos 0 z
1 0 0 0 1 1
x
z
Coordinate-Axes Rotations
• Y-Axis Rotation
x
z
Coordinate-Axes Rotations
• Z-Axis Rotation
x
z
Coordinate-Axes Rotations
• X-Axis Rotation • Y-Axis Rotation • Z-Axis Rotation
y y y
x x x
z z z
Order of Rotations
X-axis Z-axis
Z-axis X-axis
End
Image
Transformations
Khawar Khurshid, 2012