Computer Graphics
Dr.S.Sivakumar,Principal
C.P.A College, Bodinayakanur
*
1
Two-Dimensional Geometric Transformations�
Two-Dimensional Geometric Transformations
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
4
Translation
x
y
p
P’
T
x
y
T
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
6
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’)
φ
7
2-D Rotation
θ
(x, y)
(x’, y’)
x’ = x cos(θ) - y sin(θ)
y’ = x sin(θ) + y cos(θ)
8
2-D Rotation
This is easy to capture in matrix form:
Even though sin(θ) and cos(θ) are nonlinear functions of θ,
9
Rotation
x
y
P(x,y)
P’ (x’,y’)
r
θ Φ
x’=rcos(Φ+θ)= rcos Φ cos θ -rsin Φ sin θ
y’=rsin(Φ+θ)= rcos Φ sin θ+rsin Φ cos θ
x=rcos Φ y=rsin Φ
x’=x cos θ -ysin θ
y’=xsin θ +ycos θ
P’= R· P
Rotation
x
y
P(x,y)
P’ (x’,y’)
r
(xr,yr)
x’=xr+(x- xr)cos θ -(y- yr)sin θ
y’=yr+(x- xr)sin θ +(y- yr)cos θ
θ Φ
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
12
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
13
Scaling
Non-uniform scaling: different scalars per component:
How can we represent this in matrix form?
X × 2,�Y × 0.5
14
Scaling
Scaling operation:
Or, in matrix form:
scaling matrix
15
Scaling
x
y
x
y
Scaling
Homogeneous Coordinates
Homogeneous coordinates
Homogeneous coordinates seem unintuitive, but they make graphics operations much easier
18
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!
19
Homogeneous Coordinates
20
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
21
Homogeneous Coordinates
Represent translation as a 3x3 matrix?
Using the rightmost column:
22
Translation
Example of Translation
tx = 2�ty = 1
Homogeneous Coordinates
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
Matrix Representations and Homogeneous Coordinates
Matrix Representations
Composite Transformations
Composite Transformations
Composite Transformations
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
32
Combining Transformations (cont.)
1
2
3
4
33
Combining Transformations (cont.)
The three transformation matrices are combined as follows
Remember: Matrix multiplication is not commutative
so order matters
34
Matrix Composition
Transformations can be combined by �matrix multiplication
p’ = T(tx,ty) R(Θ) S(sx,sy) p
35
Matrix Composition
p’ = (T * (R * (S*p) ) )
p’ = (T*R*S) * p
36
Matrix Composition
37
General Pivot-Point Rotation
General Pivot-Point Rotation
General Fixed-Point Scaling
Scaling with respect to a selected fixed position (xf,yf)
General Fixed-Point Scaling
General Scaling Directions
General Scaling Directions
Concatenation Properties
A·B ·C = (A·B )·C = A·(B ·C)
Concatenation Properties
General Composite Transformations and Computer Efficiency
Rigid-Body Transformation
Rigid-Body Transformation
Construct the desired transformation by assigning the elements of u’ to the first row of the rotation matrix and the elements of v’ to the second row.
Computational Efficiency
Reflection
Reflection
Reflection
Reflection
Reflection
Reflection
Shear
If shx = 2:
Shear
If shx = ½ yref = -1:
1
1/2
3/2
Shear
If shy = ½ xref = -1:
1
1/2
3/2
Transformations between Coordinate Systems
x
y
y’
x’
x0
y0
θ
x
y
y’
x’
θ
Transformations between Coordinate Systems
Method 1:
Method 2:
Affine Transformations
x’=axxx+axyy+bx, y’=ayxx+ayyy+by