0% found this document useful (0 votes)
6 views49 pages

3-Basic Transformations

This document discusses basic transformations in mathematics, focusing on how to represent transformations using matrices and matrix-vector multiplications. It covers various types of transformations, including affine transformations, rotations, and the use of homogeneous coordinates, while emphasizing the importance of order in combining transformations. Additionally, it explores hierarchical scene graphs and their applications in modeling and animation.

Uploaded by

21130596
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)
6 views49 pages

3-Basic Transformations

This document discusses basic transformations in mathematics, focusing on how to represent transformations using matrices and matrix-vector multiplications. It covers various types of transformations, including affine transformations, rotations, and the use of homogeneous coordinates, while emphasizing the importance of order in combining transformations. Additionally, it explores hierarchical scene graphs and their applications in modeling and animation.

Uploaded by

21130596
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/ 49

Basic Transformations

10/14/2013 1
Goals
• This unit is about the math for
these transformations
– Represent transformations using
matrices and matrix-vector multiplications.
• General Idea
– Object in model coordinates
– Transform into world coordinates
– Represent points on object as vectors
– Multiply by matrices
Simple Transformations
• Can be combined

10/14/2013 3
What is a Transformation?
• Maps points (x, y) in to
points (x', y')
• Just functions acting on
points
(x’, y’, z’) = F(x, y, z)
P’ = F(P)

10/14/2013 4
Transformations are used
• Modeling
– Position objects in a scene
– Change the shape of objects
– Create multiple copies of objects
– Efficiently represent hierarchical scenes
• Viewing
– World coordinates to camera coordinates
– Parallel / perspective projections from 3D to 2D
• Animations

10/14/2013 5
Cube Man (Instancing Hierarchy)

6
How are Transforms Represented?
x′ = ax + by + c

y′ = dx + ey + f

• Biểu diễn dưới dạng ma trận

𝑥′ 𝑎 𝑏 𝑥 𝑐
= 𝑦 + 𝑓
𝑦′ 𝑑 𝑒
P' = M P + T

10/14/2013 7
Affine Transformations

10/14/2013 8
Affine Transformations
• Want transformations which preserve geometry
– lines, polygons, quadrics
• Affine = line preserving
– Rotation, translation, scaling
– Projection
– Concatenation (composition)

10/14/2013 9
Scale

𝑥 ′ = 𝑆𝑥 𝑥
൝ ′
𝑦 = 𝑆𝑦 𝑦
𝑥′ 𝑆𝑥 0 𝑥
= 0 𝑆𝑦 𝑦
𝑦′
10/14/2013 10
Shear

1 𝑎
ShearX =
0 1
𝑥′ 1 𝑎 𝑥
= 𝑦
𝑦′ 0 1
Rotations
• 2D simple, 3D complicated. [Derivation?
Examples?]
• 2D?
𝑥′ cos 𝜃 − sin 𝜃 𝑥
′ =
𝑦 sin 𝜃 cos 𝜃 𝑦

• Linear (Tuyến tính): R(X+Y) = R(X)+R(Y)


• Commutative (Giao hoán)

10/14/2013 12
Composing Transforms
• Often want to combine transforms
– E.g. first scale by 2, then rotate by 45 degrees
• Advantage of matrix formulation:
– All still a matrix

• Not commutative!! Order matters


– X2 = SX1
– X3 = RX2
– X3 = R(SX1) = (RS)X1
– X3  (SR)X1
10/14/2013 13
Inverting Composite Transforms
• Say I want to invert a combination of 3 transforms
• Option 1: Find composite matrix, invert
• Option 2: Invert each transform and swap order
– Obvious from properties of matrices
𝑀 = 𝑀1 𝑀2 𝑀3
𝑀−1 = 𝑀3−1 𝑀2−1 𝑀1−1
𝑀−1 𝑀 = 𝑀3−1 𝑀2−1 𝑀1−1 𝑀1 𝑀2 𝑀3 = 𝐼

10/14/2013 14
Rotations in 3D
• Rotations about coordinate axes simple
cos 𝜃 − sin 𝜃 0
• 𝑅𝑧 = sin 𝜃 cos 𝜃 0
0 0 1
1 0 0
• 𝑅𝑥 = 0 cos 𝜃 − sin 𝜃
0 sin 𝜃 cos 𝜃
cos 𝜃 0 sin 𝜃
• 𝑅𝑦 = 0 1 0
− sin 𝜃 0 cos 𝜃

• Always linear, orthogonal


10/14/2013 15
3D Rotation Around Arbitrary Axis
• Construct orthonormal frame
transformation F with p, u, v, w,
where p and w match the rotation
axis

• Apply the transform (F Rz(θ) F-1)


Interpretations (both valid):
– Move to Z axis, rotate, then move back
– Cast w-axis rotation in new coordinate frame

16
Rodrigues’ Rotation Formula
• Rodrigues’ Rotation Formula
Rotation by angle α around axis n

• How to prove this magic formula?


– Matrix N computes a cross-product: Nx = n × x
– Assume orthonormal system e1, e2, n
R(n, ) = n
R(e1, ) = cos e1 + sin e2
R(e2, ) = -sin e1 + cos e2

17
Axis-Angle: Putting it together
(𝑏\𝑎)𝑅𝑂𝑇 = (𝐼3×3 cos 𝛼 − 𝑎𝑎𝑇 cos 𝛼)𝑏 + (𝐴∗ sin 𝛼)𝑏
(𝑏 → 𝑎)𝑅𝑂𝑇 = (𝑎𝑎𝑇 )𝑏
𝑅(𝑎, 𝛼) = 𝐼3×3 cos 𝛼 + 𝑎𝑎𝑇 (1 − cos 𝛼) + 𝐴∗ sin 𝛼

1 0 0
𝑅 𝑎, 𝛼 = cos 𝛼 0 1 0 +
0 0 1
𝑥 2 𝑥𝑦 𝑥𝑧 0 −𝑧 𝑦
(1 − cos 𝛼) 𝑥𝑦 𝑦 2 𝑦𝑧 + sin 𝛼 𝑧 0 −𝑥
𝑥𝑧 𝑦𝑧 𝑧2 −𝑦 𝑥 0

(x y z) are cartesian components of a


Homogeneous Coordinates

10/14/2013 19
Translation
• E.g. move x by + 5 units, leave y, z unchanged
• We need appropriate matrix. What is it?

𝑥′ 𝑥 𝑥+5
𝑦′ = ? 𝑦 = 𝑦
𝑧′ 𝑧 𝑧

10/14/2013 20
Homogeneous Coordinates
• Add a fourth homogeneous coordinate (w=1)
• 4x4 matrices very common in graphics, hardware
• Last row always 0 0 0 1 (until next lecture)

𝑥′ 1 0 0 5 𝑥 𝑥+5
𝑦′ 0 1 0 0 𝑦 𝑦
= =
𝑧′ 0 0 1 0 𝑧 𝑧
1 0 0 0 1 1 1

10/14/2013 21
Representation of Points (4-Vectors)
• Homogeneous coordinates 𝑥 𝑥/𝑤
– Divide by 4th coord (w) to get 𝑦 𝑦/𝑤
𝑃= =
(inhomogeneous) point 𝑧 𝑧/𝑤
𝑤 1
– Multiplication by w > 0, no effect

– Assume w ≥ 0.
For w > 0, normal finite point.
For w = 0, point at infinity (used for vectors to stop
translation)

10/14/2013 22
Advantages of Homogeneous Coords
• Unified framework for translation, viewing, rot…
• Can concatenate any set of transforms to 4x4 matrix
• No division (as for perspective viewing) till end
• Simpler formulas, no special cases
• Standard in graphics software, hardware

10/14/2013 23
General Translation Matrix
1 0 0 𝑇𝑥
0 1 0 𝑇𝑦 𝐼 𝑇
• 𝑇= = 3
0 0 1 𝑇𝑧 0 1
0 0 0 1

1 0 0 𝑇𝑥 𝑥 𝑥 + 𝑇𝑥
0 1 0 𝑇𝑦 𝑦 𝑦 + 𝑇𝑦
• 𝑃′ = 𝑇𝑃 = = =𝑃+𝑇
0 0 1 𝑇𝑧 𝑧 𝑧 + 𝑇𝑧
0 0 0 1 1 1

10/14/2013 24
Combining Translations, Rotations
• Order matters!! TR is not the same as RT
• General form for rigid body transforms
• We show rotation first, then translation (commonly
used to position objects) on next slide. Slide after
that works it out the other way

10/14/2013 25
Combining Translations, Rotations
• 𝑃′ = (𝑇𝑅)𝑃 = 𝑀𝑃 = 𝑅𝑃 + 𝑇

1 0 0 𝑇𝑥 𝑅11 𝑅12 𝑅13 0


0 1 0 𝑇𝑦 𝑅21 𝑅22 𝑅23 0
• 𝑀=
0 0 1 𝑇𝑧 𝑅31 𝑅32 𝑅33 0
0 0 0 1 0 0 0 1
𝑅11 𝑅12 𝑅13 𝑇𝑥
𝑅21 𝑅22 𝑅23 𝑇𝑦 𝑅 𝑇
= =
𝑅31 𝑅32 𝑅33 𝑇𝑧 0 1
0 0 0 1

10/14/2013 26
Combining Transforms: Scene
Graphs

27
Hierarchical Scene Graph
Example Scene-Graphs
Drawing a Scene Graph
• Draw scene with pre-and-post-order traversal
– Apply node, draw children, undo node if applicable
• Nodes can carry out any function
– Geometry, transforms, groups, color, …
• Requires stack to “undo” post children
– Transform stacks in OpenGL
• Caching and instancing possible
• Instances make it a DAG, not strictly a tree
Skeleton - Linear Representation
head
torso
right upper arm
right lower arm
right hand
left upper arm
left lower arm
left hand
right upper leg
right lower leg
right foot
left upper leg
left lower leg
left foot

31
Linear Representation
• Each shape associated with its own transform
A single edit can require updating many transforms
• E.g. raising arm requires updating transforms for
all arm parts

32
Skeleton – Hierarchical Representation
body
torso
head
right arm
upper arm
lower arm
hand
left arm
upper arm
lower arm
hand
right leg
upper leg
lower leg
foot
left leg
upper leg
lower leg
foot
33
Hierarchical Representation
Grouped representation (tree)
• Each group contains subgroups and/or shapes
• Each group is associated with a transform relative to
parent group
• Transform on leaf-node shape is concatenation of all
transforms on path from root node to leaf
• Changing a group’s transform affects all parts
– Allows high level editing by changing only one node
– E.g. raising left arm requires changing only one
transform for that group
34
Skeleton - Hierarchical Representation

35
36
Coordinate System Transform

37
Coordinate System Transform

38
Coordinate System Transform
• A new coordinate frame is defined by a point (origin)
and two vectors (axes)

39
Coordinate System Transform
• Frame-to-world transform
– Reference frame defines matrix columns

40
Transform Object or Camera?

41
Case Study: Derive gluLookAt
• Defines camera, fundamental to how we view
images
gluLookAt(eyex, eyey, eyez, centerx,
centery, centerz, upx, upy, upz)
– Camera is at eye, looking at center, with the up
direction being up
Up vector

Eye

Center
Constructing a coordinate frame?

• We want to associate w with a, and v with b


• But a and b are neither orthogonal nor unit norm
• And we also need to find u
𝑎 Up vector
𝑤= b
𝑎
𝑏×𝑤
𝑢= Eye
𝑏×𝑤
a
𝑣 =𝑤×𝑢
Center
Constructing a coordinate frame
𝑎 𝑏×𝑤
𝑤= 𝑢= 𝑣 =𝑤×𝑢
𝑎 𝑏×𝑤
• We want to position Up vector
camera at origin, looking b
down–Z dir
• Hence, vector a is given Eye
by eye – center a
• The vector b is simply the
up vector Center
Geometric Interpretation 3D Rotations
• Rows of matrix are 3 unit vectors of new coord
frame
• Can construct rotation matrix from 3 orthonormal
vectors
𝑥𝑢 𝑦𝑢 𝑧𝑢
𝑅𝑢𝑣𝑤 = 𝑥𝑣 𝑦𝑣 𝑧𝑣 𝑢 = 𝑥𝑢 𝑋 + 𝑦𝑢 𝑌 + 𝑧𝑢 𝑍
𝑥𝑤 𝑦𝑤 𝑧𝑤
Steps
• gluLookAt(eyex, eyey, eyez, centerx,
centery, centerz, upx, upy, upz)
– Camera is at eye, looking at center, with the up
direction being up

• First, create a coordinate frame for the camera


• Define a rotation matrix
• Apply appropriate translation for camera (eye)
location
Translation
• gluLookAt(eyex, eyey, eyez, centerx,
centery, centerz, upx, upy, upz)
– Camera is at eye, looking at center, with the up
direction being up

• Cannot apply translation after rotation


• The translation must come first (to bring camera to
origin) before the rotation is applied
Combining Translations, Rotations
𝑃′ = (𝑅𝑇)𝑃 = 𝑀𝑃 = 𝑅(𝑃 + 𝑇) = 𝑅𝑃 + 𝑅𝑇

𝑅11 𝑅12 𝑅13 0 1 0 0 𝑇𝑥


𝑅 𝑅22 𝑅23 0 0 1 0 𝑇𝑦
Với: 𝑀 = 21
𝑅31 𝑅32 𝑅33 0 0 0 1 𝑇𝑧
0 0 0 1 0 0 0
𝑅3×3 𝑅3×3 𝑇3×1
=
01×3 1
gluLookAt final form
𝑥𝑢 𝑦𝑢 𝑧𝑢 0 1 0 0 −𝑒𝑥
𝑥𝑣 𝑦𝑣 𝑧𝑣 0 0 1 0 −𝑒𝑦
𝑥𝑤 𝑦𝑤 𝑧𝑤 0 0 0 1 −𝑒𝑧
0 0 0 1 0 0 0 1

𝑥𝑢 𝑦𝑢 𝑧𝑢 −𝑥𝑢 𝑒𝑥 − 𝑦𝑢 𝑒𝑦 − 𝑧𝑢 𝑒𝑧
𝑥𝑣 𝑦𝑣 𝑧𝑣 −𝑥𝑣 𝑒𝑥 − 𝑦𝑣 𝑒𝑦 − 𝑧𝑣 𝑒𝑧
= 𝑥 𝑦𝑤 𝑧𝑤 −𝑥𝑤 𝑒𝑥 − 𝑦𝑤 𝑒𝑦 − 𝑧𝑤 𝑒𝑧
𝑤
0 0 0 1

You might also like