Computer Graphics
Dr.S.Sivakumar,Principal
C.P.A College, Bodinayakanur
*
1
Transformations
In graphics, once we have an object described, transformations are used to move that object, scale it and rotate it
2
Translation
Simply moves an object from one position to another
xnew = xold + dx ynew = yold + dy
Note: House shifts position relative to origin
y
x
0
1
1
2
2
3
4
5
6
7
8
9
10
3
4
5
6
3
Rotation
Rotates all coordinates by a specified angle
Points are always rotated about the origin
y
x
0
1
1
2
2
3
4
5
6
7
8
9
10
3
4
5
6
4
2-D Rotation
θ
(x, y)
(x’, y’)
x’ = x cos(θ) - y sin(θ)
y’ = x sin(θ) + y cos(θ)
5
2-D Rotation
x = r cos (φ)
y = r sin (φ)
x’ = r cos (φ + θ)
y’ = r sin (φ + θ)
Trig Identity…
x’ = r cos(φ) cos(θ) – r sin(φ) sin(θ)
y’ = r sin(φ) sin(θ) + r cos(φ) cos(θ)
Substitute…
x’ = x cos(θ) - y sin(θ)
y’ = x sin(θ) + y cos(θ)
θ
(x, y)
(x’, y’)
φ
6
2-D Rotation
This is easy to capture in matrix form:
Even though sin(θ) and cos(θ) are nonlinear functions of θ,
7
Scaling
Scalar multiplies all coordinates
WATCH OUT: Objects grow and move!
xnew = Sx × xold ynew = Sy × yold
Note: House shifts position relative to origin
y
x
0
1
1
2
2
3
4
5
6
7
8
9
10
3
4
5
6
8
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
9
Scaling
Non-uniform scaling: different scalars per component:
How can we represent this in matrix form?
X × 2,�Y × 0.5
10
Scaling
Scaling operation:
Or, in matrix form:
scaling matrix
11
Matrix Representation
Represent 2D transformation by a matrix��
Multiply matrix by column vector� ⇔ apply transformation to point
12
Matrix Representation
Transformations combined by multiplication
Matrices are a convenient and efficient way
to represent a sequence of transformations!
13
2x2 Matrices
Transformations can be represented with a 2x2 matrix?
2D Identity?
2D Scale around (0,0)?
2D Rotate around (0,0)?
2D Shear?
14
2x2 Matrices
Transformations can be represented with a 2x2 matrix?
2D Mirror about Y axis?
2D Mirror over (0,0)?
2D Translation?
NO!
Only linear 2D transformations
can be represented with a 2x2 matrix
15
Basic 2D Transformations
16
Homogeneous Coordinates
Homogeneous coordinates
Homogeneous coordinates seem unintuitive, but they make graphics operations much easier
17
Homogeneous Coordinates?
Mathematicians commonly use homogeneous coordinates as they allow scaling factors to be removed from equations
The transformations we discussed previously can be represented as 3*3 matrices
Using homogeneous coordinates allows us use matrix multiplication to calculate transformations – extremely efficient!
18
Homogeneous Coordinates
19
Homogeneous Coordinates
Convenient coordinate system to represent many useful transformations
1
2
1
2
(2,1,1)
or (4,2,2)
or (6,3,3)
x
y
20
Homogeneous Coordinates
Represent translation as a 3x3 matrix?
Using the rightmost column:
21
Translation
Example of Translation
tx = 2�ty = 1
Homogeneous Coordinates
22
Basic 2D Transformations
Basic 2D transformations as 3x3 homogeneous matrices
Translate
Rotate
Shear
Scale
23
Remember Matrix Multiplication
Recall how matrix multiplication takes place:
24
Homogeneous Translation
The translation of a point by (dx, dy) can be written in matrix form as:
Representing the point as a homogeneous column vector we perform the calculation as:
25
Homogenous Transformations
To make operations easier, 2-D points are written as homogenous coordinate column vectors
Translation:
Scaling:
Rotation:
26
Inverse Transformations
Transformations can easily be reversed using inverse transformations
27
Combining Transformations
A number of transformations can be combined into one matrix to make things easy
Rotating a polygon around a point other than the origin
28
Combining Transformations (cont.)
1
2
3
4
29
Combining Transformations (cont.)
The three transformation matrices are combined as follows
Remember: Matrix multiplication is not commutative
so order matters
30
Matrix Composition
Transformations can be combined by �matrix multiplication
p’ = T(tx,ty) R(Θ) S(sx,sy) p
31
Matrix Composition
p’ = (T * (R * (S*p) ) )
p’ = (T*R*S) * p
32
Matrix Composition
33