06 Transformation
06 Transformation
2D and 3D
Dept. of Computer Science and Engineering
Islamic University, Kushtia
Dimensions
y
y
x
x
z
Transformations
y
Another Transformations are
• Reflection
x
• Shear
Translation
Re-position a point along a straight line
Given a point (x, y), and the translation distance (tx, ty)
x x t x (x,y)
tx
P , P , T
y y t y
x x t x
y y t
y
Translation
Translate individual
vertices
2D Rotation
Default rotation center: Origin (0,0)
Rotate clockwise
(Negative Rotation)
Rotation
y’ = r sin ()
= r sin() cos() + r cos()sin()
= y cos() + x sin()
Rotation
(x’,y’)
x’ = x cos() – y sin()
(x,y)
y’ = y cos() + x sin()
r
Matrix form?
x’ =
cos() -sin() x
y’ sin() cos() y
P/ = R(). P
Rotation
How to rotate an object with multiple
vertices?
Rotate individual
Vertices
Scaling
Scale: Alter the size of an object by a scaling factor
(Sx, Sy), i.e.
x’ = x . Sx x ' s x 0 x
P/ = S. P
y ' 0 s y y
y’ = y . Sy
Fixed point – The point that used to control the location of a scaled object
(4,4)
(2,2) Sx = 2, Sy = 2
(2,2)
(1,1)
2D Scaling
(4,4)
(2,2) Sx = 2, Sy = 2
(2,2)
(1,1)
x x t x
Translation: y t P=T + P
y y
x' s x 0 x
Scaling: y ' 0 s y y
P=S P
Matrix Representation and
Homogeneous Coordinates
Many graphics applications involve sequences of geometric
transformations. Example
In animation, an object to be translated and rotated at each
increment of the motion.
In design and picture construction applications, translations,
rotations, and scalings are used to fit the picture components
into their proper positions.
Rotation and Scaling matrix are 2 by 2 and point P is multiplied with
matrix R or S
Translation matrix is 2 by 1 and it is add with point P
The multiplicative and translational terms for two-dimensional
geometric transformations into a single Matrix representation by
expanding the 2 by 2 matrix representations to 3 by 3 matrices.
This allows us to express all transformation equations as matrix
multiplications
Homogeneous Coordinates
Any 2D transformation can be described uniquely by a 3x3 matrix, if
the Cartesian coordinates (x, y) is represented by the homogeneous
coordinate triple (xh, yh, h),
where xh yh
x , y
h h
h can be any real value ≠ 0,
for simplicity h=1 is used here
x 1 0 tx x
y 0 1 ty y
1 0 0 1 1
This translation operation can be written in the abbreviated form
P ' T (t x , t y ) P
T(tx, ty) is the 3 by 3 translation matrix
Homogeneous Matrix Representation
P T (t x 2 , t y 2 ).{T (t x1 , t y1 ).P}
P {T (t x 2 , t y 2 ).T (t x1 , t y1 )}.P
1 0 t x 2 1 0 t x1 1 0 t x1 t x 2
0 1 t .0 1 t 0 1 t t
y2 y1 y1 y2
0 0 1 0 0 1 0 0 1
Composite transformation matrix
Rotation
Two successive rotations applied to point P(x, y) produce
the transformed position
S ( s x 2 , s y 2 ).S ( s x1 , s y1 ) S ( s x1.s x 2 , s y1 , s y 2 )
General Two-Dimensional Pivot-Point
Rotation
we can generate a 2D rotation about any other pivot
point (xr, yr) by performing the following sequence of
translate-rotate-translate operations
1. Translate the object so that the pivot-point position is
moved to the coordinate origin.
2. Rotate the object about the coordinate origin.
3. Translate the object so that the pivot point is returned
to its original position.
General Two-Dimensional Pivot-Point
Rotation
T x f , y f S s x , s y T x f , y f S x f , y f , s x , s y
1 0 xf s x 0 0 1 0 xf s x 0 x f (1 s x )
0 1 yf 0 sy 0 0 1 yf 0 sy y f (1 s y )
0 0 1 0 0 1 0 0 1 0 0 1
General 2D Scaling Directions
x
s1
General 2D Scaling Directions
To accomplish the scaling without changing the orientation of the object.
1. We first perform a rotation so that the directions for s1 and s2
coincide with the x and y axes, respectively.
2. Then the scaling transformation S(s1,s2) is applied.
3. An opposite rotation to return points to their original orientations.
y y
(1/2,3/2 (2,2)
)
(0,1) (1,1)
(3/2,1/2
)
(0,0) (1,0) x (0,0) x
Scale
Reflection
A reflection is a transformation that produces a mirror
image of an object.
x-axis y-axis origin
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 x
2’ 3’ 3
1
1’ 2
Reflection
y 0 1 0
1 0 0
Reflection about the diagonal
y=x 0 0 1
x
4 3
2 Transformed
4 Original
Coordinate Transformation
Rotation
2
4
Transformed
Original
4 2
Affine Transformation
Translation, Scaling, Rotation, Shearing are all affine
transformation
Affine transformation – transformed point P’ (x’,y’) is
a linear combination of the original point P (x,y), i.e.
x’ axx axy bx x
y’ = ayx ayy by y
1 0 0 1 1
1 0 0 tx x
0 (x, y , z )
0 t y
y
1
0 0 1 tz z
T(tx, ty, tz)
0 0 0 1 1
(x, y, z)
X
Inverse Translation
1 0 0 tx x
0 y
1 0 ty Z
0 0 1 tz z
0 0 0 1 1
3D Scaling
sx 0 0 0 x
0 sy 0 0 y
SP = (sxx, syy, szz)
0 0 sz 0 z
0 0 0 1 1
Inversion
General scaling
Scaling with respect to a selected fixed position (xf, yf, zf)
can be represented with the following transformation
sequence:
P ' T 1 Rx ( ) T P
General Rotation
When an object is to be rotated about an axis that is not
parallel to one of the coordinate axes, we need to
perform some additional transformations.
y
y
x x