(CG - Ver1) 3 - Spaces and Transforms
(CG - Ver1) 3 - Spaces and Transforms
Prof. H. Kang
p. 1
H Kang’s
Computer Graphics
Lecture 3.
Spaces and Transforms
IIIXR LAB
Scaling
Prof. H. Kang
p. 2
What is a scaling?
▪ The scaling is a process of altering the size of objects.
▪ Scaling operation can be achieved by multiplying each vertex coordinate by
scaling factor, S.
• 2D scaling example: (x, y) × (sx, sy)
• 3D scaling example: (x, y, z) × (sx, sy, sz)
▪ If the scaling factor is less than 1, the size of the object will be reduced.
▪ If the scaling factor is greater than 1, the size of the object will be increased.
S<1 S>1
IIIXR LAB
Scaling
Prof. H. Kang
p. 3
2D scaling
▪ 2D scaling, denoted as S, is represented by a 2 × 2 matrix.
𝑠𝑥 0
S=
0 𝑠𝑦
▪ Sx and Sy are the scaling factors along the x-axis and y-axis, respectively.
▪ A 2D vector, (x, y) is scaled through matrix-vector multiplication.
𝑠𝑥 0 𝑥 𝑠𝑥𝑥
𝑦 = 𝑠𝑦𝑦
0 𝑠𝑦
IIIXR LAB
Scaling
Prof. H. Kang
p. 4
2D scaling examples: every vertex of a polygon is multiplied by the same scaling matrix
IIIXR LAB
Rotation
Prof. H. Kang
p. 5
What is a rotation?
▪ Rotation is the process of rotating an object around an axis of rotation.
▪ There are two types of rotations depending on the direction of the movement:
• Clockwise rotation
• Counterclockwise (anti-clockwise) rotation
▪ Mostly, the positive value of the rotation angle rotates an object in the
counterclockwise direction.
counterclockwise rotation
Θ clockwise rotation
Θ
IIIXR LAB
Rotation
Prof. H. Kang
p. 6
R(θ)
IIIXR LAB
An example
IIIXR LAB
Rotation
Prof. H. Kang
p. 8
Translation
Prof. H. Kang
p. 9
𝑥 𝑑𝑥 𝑥 + 𝑑𝑥
𝑦 + 𝑑𝑦 = 𝑦 + 𝑑𝑦
▪ Given the 2D Cartesian coordinates (x, y) of a point, we can take the 3D vector
(x, y, 1) as its homogeneous coordinates.
▪ Then, we can describe translation as matrix multiplication.
1 0 𝑑𝑥 𝑥 𝑥 + 𝑑𝑥
0 1 𝑑𝑦 𝑦 = 𝑦 + 𝑑𝑦
0 0 1 1 1
IIIXR LAB
Homogeneous coordinates
Prof. H. Kang
p. 10
Homogeneous coordinates
▪ Given a 2D point, (x, y), its homogeneous coordinates are not necessarily (x, y,
1) but (wx, wy, w) with non-zero w.
w
▪ For example, the Cartesian coordinates (2, 1) can
be converted into homogeneous coordinates of (4, 2, 2)
(2, 1, 1), (4, 2, 2), (6, 3, 3), etc.
(2, 1, 1)
x
y
IIIXR LAB
Homogeneous coordinates
Prof. H. Kang
p. 11
Homogeneous coordinates
▪ Suppose that we are given the w
homogeneous coordinates, (X, Y, w).
(4, 2, 2)
w=2
▪ By dividing every coordinate by w, we
obtain (X/w, Y/w, 1).
Cartesian Space (2, 1, 1)
▪ This corresponds to projecting a point on
w=1 x
the line onto the plane, w = 1.
Homogeneous coordinates
Prof. H. Kang
p. 12
Homogeneous coordinates
▪ For handling the homogeneous coordinates, the 3×3 matrices for scaling and
rotation need to be altered.
IIIXR LAB
Practice
Prof. H. Kang
p. 13
2 2
1
1 1
scaling translation rotation
2 1
IIIXR LAB
Practice - Solution
Prof. H. Kang
p. 14
2 2
1
1 1
scaling translation rotation
2 1
Composition of 2D Transform
Prof. H. Kang
p. 15
Composition of 2D Transform
Prof. H. Kang
p. 16
▪ The vertex located at (0, 4) is rotated to (-4, 0) by R(90˚). Then, the vertex at (-4, 0)
is translated to (3, 0) by T(7, 0).
IIIXR LAB
Composition of 2D Transform
Prof. H. Kang
p. 17
Combine matrices
▪ As both R(90˚) and T(7, 0) are represented in 3 × 3 matrices, they can be
concatenated to make a 3 × 3 matrix:
Composition of 2D Transform
Prof. H. Kang
p. 18
Noncommutative
▪ Matrix multiplication is noncommutative, which means “order matters”.
▪ Rotation (R) followed by translation (T) vs. T followed by R
IIIXR LAB
Composition of 2D Transform
Prof. H. Kang
p. 19
Composition of 2D Transform
Prof. H. Kang
p. 20
Affine transform
Prof. H. Kang
p. 21
Affine transform
▪ Linear transform L (Scaling S, Rotation R, etc.)
▪ Translation T - Translation does not fall into the linear transform class
No matter how many affine matrices are given, they can be combined into a matrix.
IIIXR LAB
Affine transform
Prof. H. Kang
p. 22
Ignoring the third row, we often denote the remaining 2×3 elements [L|t], where L is
a 2×2 matrix and t is a 2D column vector.
▪ L represents the ‘combined’ linear transform.
▪ In contrast, t represents a ‘combined’ translation, which may contain the input
linear-transform terms.
IIIXR LAB
Affine transform
Prof. H. Kang
p. 23
Revisit T(7,0)R(90o).
[L|t]
IIIXR LAB
Affine transform
Prof. H. Kang
p. 24
Revisit R(90o)T(7,0).
Affine transform
Prof. H. Kang
p. 25
IIIXR LAB
No matter how many rotations and translations are combined, the resulting matrix
retains the structure, [R|t].
▪ R represents the ‘combined’ rotation = does not include any translation terms.
▪ t represents the ‘combined’ translation = does not include any rotation terms.
Rigid Motion
Prof. H. Kang
p. 27
IIIXR LAB
Practice
Prof. H. Kang
p. 28
2. Write a 3 × 3 transform matrix that rotates (x, y)T by 60˚, and translates by (2, -1).
3. Write a 3 × 3 transform matrix that rotates (x, y) by 60˚, and translates by (2, -1)
IIIXR LAB
Practice - Solution
Prof. H. Kang
p. 29
Practice - Solution
Prof. H. Kang
p. 30
2. Write a 3 × 3 transform matrix that rotates (x, y)T by 60˚, and translates by (2, -1).
1 3
− 2 𝑥
2 2
3 1 𝑦
−1
2 2 1
0 0 1
3. Write a 3 × 3 transform matrix that rotates (x, y) by 60˚, and translates by (2, -1).
1 3
0
2 2
𝑥 𝑦 1 3 1
− 0
2 2
2 −1 1
IIIXR LAB
3D Scaling
Prof. H. Kang
p. 31
If all of the scaling factors are identical, the scaling is called uniform. Otherwise, it is
a non-uniform scaling.
(𝑆𝑥 ,𝑆𝑦 , 𝑆𝑧 ) = (1.5, 1.5, 1.5) (𝑆𝑥 ,𝑆𝑦 , 𝑆𝑧 ) = (1, 0.5, 1)
IIIXR LAB
𝜃 = 90°
(x,y,z)
z
IIIXR LAB
3D Rotation
Prof. H. Kang
p. 33
3D Translation
Prof. H. Kang
p. 34
The 3×3 matrices developed for 3D scaling and rotation are extended to 4×4
matrices. See the scaling example.
IIIXR LAB
(0,2,3)
(0,1,0)
(0,2,0)
scaling (10,2,0)
rotation followed by
translation
world space
IIIXR LAB
rotation translation
𝑅𝑦 (90°) 𝑇(7,0,0)
(0,2,3) (3,2,0)
0 0 1 0 1 0 0 7
0 1 0 0 0 1 0 0 (10,2,0)
−1 0 0 0 0 0 1 0
0 0 0 1 0 0 0 1
IIIXR LAB
translation rotation
𝑇(7,0,0) 𝑅𝑦 (90°)
(3,2,-7)
(0,2,
1 0 0 7 0 0 1 0
3) 0 1 0 0
(7,2, 0 1 0 0
0 0 1 0 −1 0 0 0
0 0 0 1 3) 0 0 0 1
IIIXR LAB
Concatenating matrices
▪ When 3D scaling, rotation, and translation matrices are concatenated to make a
4×4 matrix, the fourth row is always (0 0 0 1).
▪ Ignoring the fourth row of an affine matrix, we often denote the remaining 3×4
elements by [L|t], where L is a 3×3 matrix that represents a ‘combined’ linear
transform, and t is a 3D column vector that represents a ‘combined’ translation.
▪ [L|t] is conceptually decomposed into two steps: L is applied first and then the
linear-transformed object is translated by t.
translation rotation
𝑇(7,0,0) 𝑅𝑦 (90°)
(3,2,-7)
(0,2,3)
1 0 0 7 0 0 1 0
0 1 0 0
0
0
1
0
0
1
0
0
(7,2,3) −1 0 0 0
0 0 0 1 0 0 0 1
[L|t]
IIIXR LAB
Prof. H. Kang
Practice p. 39
Q. A drone delivery company is conducting a pilot test in a scaled-down model of the city to fine-tune
its delivery routes.
The test environment is rotated 45 degrees clockwise around the z-axis relative to the real city layout
and is scaled down by a factor of 0.2 in all directions. Additionally, the center of the test city is (0, 0, 0)
while the center of the real city is (10, 20, 5).
For a seamless transition to the actual city map, the company must ensure that the drone coordinates
match the real locations precisely by taking into account these scaling, rotation, and translation
adjustments. Obtain an [L|t] requiring for seamless transition.
IIIXR LAB
5 0 0 0
(1) Scaling Transformation: 0 5 0 0
0 0 5 0
0 0 0 1
cos 45° −sin 45° 0 0
(2) Rotation Transformation (45 ccw around z-axis): sin 45° cos 45° 0 0
0 0 5 0
0 0 0 1
1 0 0 10
(3) Translation Transformation: 0 1 0 20
0 0 1 5
0 0 0 1
y(e2=v)
z(e3=n) x(e1=u)
IIIXR LAB
y(e2=v) e2, v
𝑅 u
e1e2 e3 = I u v n
y(e2=v) e2
rotation axis u
𝑢𝑥 𝑣𝑥 𝑛𝑥
𝑅 = 𝑢𝑦 𝑣𝑦 𝑛𝑦 v
𝑢𝑧 𝑣𝑧 𝑛𝑧
z(e3=n) x(e1=u) e3 e1
n
IIIXR LAB
Inverse translation
(dx, dy, dz) (x+dx, y+dy, z+dz)
(x, y, z)
(-dx, -dy, -dz)
Inverse scaling
IIIXR LAB
Inverse Rotation
Prof. H. Kang
p. 46
Given a rotation matrix R, its columns (u, v, and n) make up an orthonormal basis,
i.e., u·u = v·v = n·n = 1 and u·v = v·n = n·u = 0.
▪ Let’s multiply R’s transpose (RT) with R:
▪ This says that R-1=RT, i.e., the inverse of a rotation matrix is its transpose.
▪ Because u, v, and n form the columns of R, they form the rows of R-1.
IIIXR LAB
Inverse Rotation
Prof. H. Kang
p. 47
Recall that u, v, and n form the columns of R. As R-1=RT, u, v, and n form the rows of R-1.
0 0 0 0 0 1
𝑅𝑦 (90°) = 𝑢 𝑣 𝑛 = 0 1 0
0 0 0 −1 0 0
0 𝑢 0 0 0 −1
𝑅𝑦−1 (90°) = 𝑢 𝑣 𝑛 = 0 1 0
0 𝑛 0 1 0 0
𝑢𝑥 𝑣𝑥 𝑛𝑥
𝑅 = 𝑢𝑦 𝑣𝑦 𝑛𝑦
𝑢𝑧 𝑣𝑧 𝑛𝑧
𝑢𝑥 𝑢𝑦 𝑢𝑧
𝑅 −1
= 𝑣𝑥 𝑣𝑦 𝑣𝑧
𝑛𝑥 𝑛𝑦 𝑛𝑧
IIIXR LAB
Example
Prof. H. Kang
p. 48
rotation rotation
𝑅𝑦 (90°) (2,3,-7) (𝑅𝑦 (90°))−1
(7,3, 0
0
0
1
1
0
0
0 (7,3,
2) −1 0 0 0 2)
0 0 0 1