0% found this document useful (0 votes)
8 views48 pages

(CG - Ver1) 3 - Spaces and Transforms

The document discusses various transformations in computer graphics, including scaling, rotation, and translation, with a focus on 2D and 3D transformations. It explains how these transformations can be represented using matrices and the importance of homogeneous coordinates. Additionally, it covers the concept of affine transforms and rigid motion, emphasizing the noncommutative nature of matrix multiplication in the context of transformations.

Uploaded by

www.shoonleimay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views48 pages

(CG - Ver1) 3 - Spaces and Transforms

The document discusses various transformations in computer graphics, including scaling, rotation, and translation, with a focus on 2D and 3D transformations. It explains how these transformations can be represented using matrices and the importance of homogeneous coordinates. Additionally, it covers the concept of affine transforms and rigid motion, emphasizing the noncommutative nature of matrix multiplication in the context of transformations.

Uploaded by

www.shoonleimay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 48

IIIXR LAB

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

uniform scaling non-uniform scaling

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

Let’s consider the 2D rotation of a vector.


▪ Vector p is rotated about the origin by θ to define p΄.
▪ When the length of p = r, its coordinates are defined as:

▪ Then, the coordinates of p΄ can be computed as follows:

▪ These can be combined into a matrix-vector multiplication form:

R(θ)
IIIXR LAB

Rotation Prof. H. Kang


p. 7

An example
IIIXR LAB

Rotation
Prof. H. Kang
p. 8

Counter-clockwise rotation and clockwise rotation


▪ By default, the rotation is counter-clockwise.

▪ The matrix for the clockwise rotation by θ is obtained by


inserting -θ into the 2D rotation matrix.

▪ Note that rotation by -θ is equivalent to rotation by 2π-θ: 360


– 90 = 270.
IIIXR LAB

Translation
Prof. H. Kang
p. 9

Unlike scaling and rotation, translation is represented as vector addition.


▪ Translation displaces a point at (x, y) to (x + dx, y + dy).
▪ We call (dx, dy) the translation vector.

𝑥 𝑑𝑥 𝑥 + 𝑑𝑥
𝑦 + 𝑑𝑦 = 𝑦 + 𝑑𝑦
▪ 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.

▪ We then take the first two components,


(X/w, Y/w), as the Cartesian coordinates. y
IIIXR LAB

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

1. Write the 3×3 matrices for scaling, translation and rotation.

2 2
1
1 1
scaling translation rotation

2 1
IIIXR LAB

Practice - Solution
Prof. H. Kang
p. 14

1. Write the 3×3 matrices for scaling, translation and rotation.

2 2
1
1 1
scaling translation rotation

2 1

0.5 0 0 1 0 −1 cos 45˚ −sin 45˚ 0


0 0.5 0 0 1 −1 sin 45˚ cos 45˚ 0
0 0 1 0 0 1 0 0 1
IIIXR LAB

Composition of 2D Transform
Prof. H. Kang
p. 15

An object may go through multiple transforms.


▪ Let’s rotate and translate the polygon.

▪ We denote the rotation by R(90˚) and the translation by T(7, 0):


IIIXR LAB

Composition of 2D Transform
Prof. H. Kang
p. 16

An object may go through multiple transforms.

▪ 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:

▪ The vertex originally located at (0, 4) is instantly transformed to (3, 0) by the


combined matrix.
IIIXR LAB

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

Rotation about an arbitrary point.


▪ The rotation we learned so far is “about the origin”.
▪ Now consider rotation about arbitrary point, which is not the origin.

Rotating a point at (x, y) about an arbitrary point, (a, b)


▪ Translating (x, y) by (-a, -b)
▪ Rotating the translated point about the origin
▪ Back-translating the rotated point by (a, b)
IIIXR LAB

Composition of 2D Transform
Prof. H. Kang
p. 20

Example: rotation (5, 2) about (3, 2)


▪ Translating (5, 2) by (-3, -2)
▪ Rotating the translated point about the origin
▪ Back-translating the rotated point by (3, 2)
IIIXR LAB

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).

Conceptual decomposition of [L|t]


▪ [L|t] transforms a point, p, is Lp+t.
▪ L is applied first.
▪ The linear-transformed object is translated by t.
IIIXR LAB

Affine transform
Prof. H. Kang
p. 25
IIIXR LAB

Rigid Motion Prof. H. Kang


p. 26

Consider a combination of rotations and translations only, e.g., no scaling is involved.


▪ When the combined affine matrix applies to an object, the pose (position +
orientation) of the object is changed but its shape is not.
▪ In this sense, the transform is named rigid-body motion or simply rigid
motion.

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.

Transforming an object by [R|t] is conceptually decomposed into two steps: R is


applied first and then the rotated object is translated by t , i.e., the way [R|t]
transforms a point, p, is Rp+t.
IIIXR LAB

Rigid Motion
Prof. H. Kang
p. 27
IIIXR LAB

Practice
Prof. H. Kang
p. 28

1. For matrix-vector multiplication, let us use row vectors (w = 1).


▪ Write the translation matrix that translates (x, y) by (dx, dy).
▪ Write the rotation matrix that rotates (x, y) by θ.
▪ Write the scaling matrix with scaling factors sx and sy.

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

1. For matrix-vector multiplication, let us use row vectors (w = 1).


▪ Write the translation matrix that translates (x, y) by (dx, dy).
1 0 0
𝑥 𝑦 1 0 1 0
𝑑𝑥 𝑑𝑦 1
▪ Write the rotation matrix that rotates (x, y) by θ.
cos(θ) sin(θ) 0
𝑥 𝑦 1 −sin(θ) cos(θ) 0
0 0 1
▪ Write the scaling matrix with scaling factors sx and sy.
𝑠𝑥 0 0
𝑥 𝑦 1 0 𝑠𝑦 0
0 0 1
IIIXR LAB

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

3D scaling with the scaling factors, sx ,sy and sz.

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

3D Rotation Prof. H. Kang


p. 32

Unlike 2D rotation which requires a center of rotation, 3D rotation requires an axis


of rotation.
▪ Let’s consider 3D rotations about x-axis (Rx), y-axis (Ry), and z-axis (Rz)
▪ Following example shows a rotation about Rz.
(x',y',z')

𝜃 = 90°
(x,y,z)

z
IIIXR LAB

3D Rotation
Prof. H. Kang
p. 33

CCW vs. CW rotations


▪ If the rotation is CCW with respect to the axis pointing toward you, the rotation
angle is positive.
▪ If the rotation is CW, its matrix is defined with the negated rotation angle.
▪ Note that rotation by -θ is equivalent to rotation by 2π-θ.

CCW rotation by 90° CW rotation by 90°


𝑅𝑦 (90°) 𝑅𝑦 (−90°)
IIIXR LAB

3D Translation
Prof. H. Kang
p. 34

Recall that, translation is represented as vector addition.


▪ To represent translation as matrix multiplication, homogeneous coordinates is
exploited.

The 3×3 matrices developed for 3D scaling and rotation are extended to 4×4
matrices. See the scaling example.
IIIXR LAB

Application: World Transform


Prof. H. Kang
p. 35

Object space vs. world space


▪ The coordinate system used for creating an object is named object space.
▪ The object space for a model typically has no relationship to that of another
model.
▪ The world transform ‘assembles’ all models into a single coordinate system
called world space. a sphere in its object space a teapot in its object space

(0,2,3)
(0,1,0)

(0,2,0)

scaling (10,2,0)
rotation followed by
translation

world space
IIIXR LAB

Application: World Transform Prof. H. Kang


p. 36

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

3D Affine Transforms Prof. H. Kang


p. 37

The discussions we had on 2D affine transforms apply to 3D affine transforms.


▪ Recall that the matrix multiplication is not commutative.
rotation translation
𝑅𝑦 (90°) 𝑇(7,0,0)
(0,2, (3,2,
3) 0
0
0
1
1
0
0
0
0) 1 0 0 7 (10,2,0)
0 1 0 0
−1 0 0 0
0 0 1 0
0 0 0 1
0 0 0 1

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

3D Affine Transforms Prof. H. Kang


p. 38

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

Practice - Solution Prof. H. Kang


p. 40

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

1 0 0 10 cos 45° −sin 45° 0 0 5 0 0 0


(4) Composition: 0 1 0 20 sin 45° cos 45° 0 0 0 5 0 0
0 0 1 5 0 0 5 0 0 0 5 0
0 0 0 1 0 0 0 1 0 0 0 1
IIIXR LAB

Rotation and Object-space Basis


Prof. H. Kang
p. 41

Basis of the world space and object space


▪ {e1, e2, e3} represents the standard basis of the world space.
▪ {u, v, n} represents the orthonormal basis of the object space.
▪ In the following figure, world space basis and object space basis are identical.

y(e2=v)

z(e3=n) x(e1=u)
IIIXR LAB

Rotation and Object-space Basis


Prof. H. Kang
p. 42

Rotating Object-space basis


▪ A rotation applied to an object changes its orientation, which can be described
by the ‘rotated’ basis of the object space.
▪ Let R denote the rotation.

y(e2=v) e2, v

𝑅 u

z(e3=n) x(e1=u) e3 e1, n


IIIXR LAB

Rotation and Object-space Basis


Prof. H. Kang
p. 43

R relates e1 and u, which was initially identical to e1.

Similarly, R transforms e2 and e3 into v and n, respectively:

The above three are combined:

e1e2 e3 = I u v n

R’s columns are equal to u, v, and n.


Therefore, given the ‘rotated’ object-space basis of {u, v, n}, the rotation matrix is
immediately determined, and vice versa.
IIIXR LAB

Rotation and Object-space Basis


Prof. H. Kang
p. 44

The observation we have made holds in general.

y(e2=v) e2
rotation axis u
𝑢𝑥 𝑣𝑥 𝑛𝑥
𝑅 = 𝑢𝑦 𝑣𝑦 𝑛𝑦 v
𝑢𝑧 𝑣𝑧 𝑛𝑧

z(e3=n) x(e1=u) e3 e1
n
IIIXR LAB

Inverses of Translation and Scaling


Prof. H. Kang
p. 45

Inverse translation
(dx, dy, dz) (x+dx, y+dy, z+dz)

(x, y, z)
(-dx, -dy, -dz)

Inverse transform in inverse matrix

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

A 4 × 4 rotation matrix of (𝑅𝑦 (90°))−1 can be obtained by:

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

cos −90˚ 0 sin −90˚ 0 0 0 −1 0 0 0 −1 0


0 1 0 0 0 1 0 0 0 1 0 0
𝑅𝑦 (−90°) = = transpose(𝑅𝑦 (90°)) =
−sin −90˚ 0 cos −90˚ 0 1 0 0 0 1 0 0 0
0 0 0 1 0 0 0 1 0 0 0 1

You might also like