Lecture 8: Coordinate Frame Transformations
Transcript of Lecture 8: Coordinate Frame Transformations
Magnitude of a Vector
โข Magnitude of a
โ If a =(2, 5, 6)
โข Normalizing a vector
1
CITS3003 Graphics & Animation
Lecture 8:
Coordinate Frame
Transformations
Breakdown of Lectures
1. Introduction & Image Formation
2. Programming with OpenGL
3. OpenGL: Pipeline Architecture
4. OpenGL: An Example Program
5. Vertex and Fragment Shaders 1
6. Vertex and Fragment Shaders 2
7. Representation and Coordinate Systems
8. Coordinate Frame Transformations
9. Transformations and Homogeneous Coordinates
10. Input, Interaction and Callbacks
11. Mid-semester Test
12. More on Callbacks
13. 3D Hidden Surface Removal
13. Computer Viewing
- Study break
15. Programming Project Discussion
16. Shading
17. Shading Models
18. Shading in OpenGL
19. Texture Mapping
20. Texture Mapping in OpenGL
21. Hierarchical Modelling
22. 3D Modelling: Subdivision Surfaces
23. Animation Fundamentals and Quaternions
24. Skinning
3
Content
โข Learn how to define and change coordinate
frames
โข Derive homogeneous coordinate
transformation matrices
โข Introduce standard transformations
โ Rotation, Translation, Scaling, Shear
4
Coordinate Frame
โข Basis vectors alone cannot represent points
โข We can add a single point, the origin, to the
basis vectors to form a coordinate frame
P0v1
v2
v3
5
Representation in a Coordinate Frame
โข A coordinate system (or coordinate frame) is
determined by ๐0, ๐ฏ1, ๐ฏ2, ๐ฏ3โข Within this coordinate frame, every vector v
can be written as
v = ฮฑ1v1+ ฮฑ2v2 + ฮฑ3v3
Every point can be written as
P = P0 + ฮฒ1v1+ ฮฒ2v2 + ฮฒ3v3
for some ๐ผ1, ๐ผ2, ๐ผ3, and ๐ฝ1, ๐ฝ2, ๐ฝ3
6
Homogeneous Coordinates
โข Consider the point P and the vector v, where
P = P0 + ฮฒ1v1+ ฮฒ2v2 + ฮฒ3v3
v = ฮฑ1v1+ ฮฑ2v2 + ฮฑ3v3
โข They appear to have similar representations:
P = [ฮฒ1, ฮฒ2, ฮฒ3]T , v =[ฮฑ1, ฮฑ2, ฮฑ3]T which
confuses the point with the vector
A vector has no position v
P
v
Vector can be placed anywhere
point: fixed
7
A Single Representation
โข Assuming 0 โ ๐ = ๐ and 1 โ ๐ = ๐ , we can write
๐ฏ = ๐ผ1๐ฏ1 + ๐ผ2๐ฏ2 + ๐ผ3๐ฏ3 = ๐ผ1๐ฏ1 + ๐ผ2๐ฏ2 + ๐ผ3๐ฏ3 + 0 โ ๐0๐ = ๐ฝ1๐ฏ1 + ๐ฝ2๐ฏ2 + ๐ฝ3๐ฏ3 + ๐0 = ๐ฝ1๐ฏ1 + ๐ฝ2๐ฏ2 + ๐ฝ3๐ฏ3 + 1 โ ๐0
โข Thus, we obtain the four-dimensional homogeneous
coordinate representation
๐ฏ = ๐ผ1 ๐ผ2 ๐ผ3 0 ๐
๐ = ๐ฝ1 ๐ฝ2 ๐ฝ3 1 ๐
8
Homogeneous Coordinates
โข The homogeneous coordinate form for a three-dimensional point ๐ฅ ๐ฆ ๐ง T is given as
๐ฉ = ๐ฅ ๐ฆ ๐ง 1 T ๐ค๐ฅ ๐ค๐ฆ ๐ค๐ง ๐ค T = ๐ฅโฒ ๐ฆโฒ ๐งโฒ ๐ค T
โข We return to a three-dimensional point (for ๐ค โ 0) by๐ฅ โ ๐ฅโฒ/๐ค๐ฆ โ ๐ฆโฒ/๐ค๐ง โ ๐งโฒ/๐ค
โข If ๐ค = 0, the representation is that of a vector
โข Homogeneous coordinates replace points in three dimensions by lines through the origin in four dimensions
โข For ๐ค = 1, the representation of a point is ๐ฅ ๐ฆ ๐ง 1 T
9
โข Homogeneous coordinates are key to all
computer graphics systemsโ All standard transformations (rotation, translation, scaling)
can be implemented with matrix multiplications using 4 x 4
matrices
โ Hardware pipeline works with 4 dimensional representations
โ For orthographic viewing, we can maintain w = 0 for
vectors and w = 1 for points
โ For perspective we need a perspective division
10
Homogeneous Coordinates and Computer Graphics
Representing the Second Basis in
Terms of the First
โข How can we relate ๐ฎ with ๐ฏ?
โข Each of the basis vectors ๐ฎ1, ๐ฎ2, and ๐ฎ3 are vectors that
can be represented in terms of the first set of basis
vectors,
i.e.,
for some ๐พ11, โฆ , ๐พ33
๐ฐ๐ฎ1 = ๐พ11๐ฏ1 + ๐พ12๐ฏ2+๐พ13๐ฏ3๐ฎ2 = ๐พ21๐ฏ1 + ๐พ22๐ฏ2+๐พ23๐ฏ3๐ฎ3 = ๐พ31๐ฏ1 + ๐พ32๐ฏ2+๐พ33๐ฏ3
11
Representing the Second Basis in
Terms of the First (cont.)โข ๐ฎ1 = ๐พ11๐ฏ1 + ๐พ12๐ฏ2+๐พ13๐ฏ3 can be written as:
๐ฎ1 = ๐ฏ1 ๐ฏ2 ๐ฏ3
๐พ11๐พ12๐พ13
= ๐
๐พ11๐พ12๐พ13
โข Similarly, ๐ฎ2 = ๐พ21๐ฏ1 + ๐พ22๐ฏ2+๐พ23๐ฏ3 and ๐ฎ3 = ๐พ31๐ฏ1 + ๐พ32๐ฏ2+๐พ33๐ฏ3 can be written as:
๐ฎ2 = ๐
๐พ21๐พ22๐พ23
๐ฎ3 = ๐
๐พ31๐พ32๐พ33
12
Representing the Second Basis in
Terms of the First (cont.)
โข We can put the terms ๐พ11, โฆ , ๐พ33 into a 3 ร 3 matrix:
๐ =
๐พ11 ๐พ12 ๐พ13๐พ21 ๐พ22 ๐พ23๐พ31 ๐พ32 ๐พ33
then we have:๐ฎ1 ๐ฎ2 ๐ฎ3 = ๐๐T
That is,
๐ = ๐๐T
The superscript T denotes
matrix transpose
13
The same vector w represented in two
coordinate systemsโข We can write
๐ฐ = ๐ผ1๐ฏ1 + ๐ผ2๐ฏ2 + ๐ผ3๐ฏ3๐ฐ = ๐ฝ1๐ฎ1 + ๐ฝ2๐ฎ2 + ๐ฝ3๐ฎ3
as follows:
๐ฐ = ๐ฏ1 ๐ฏ2 ๐ฏ3
๐ผ1๐ผ2๐ผ3
= ๐ ๐
๐ฐ = ๐ฎ1 ๐ฎ2 ๐ฎ3
๐ฝ1๐ฝ2๐ฝ3
= ๐ ๐Each ๐ฏ๐ is a
column
vector of 3
components
Letโs call this
3 ร 3 matrix ๐
14
Representing the Second Basis in
Terms of the First (cont.)
โข In this example, we have ๐ฐ = ๐ ๐ and ๐ฐ = ๐ ๐.
โข So
๐ ๐ = ๐ ๐
โข With ๐ = ๐๐T, we have
๐ ๐ = ๐๐T๐โ ๐ = ๐T๐
โข Thus, ๐ and ๐ are related by ๐T
15
Representing the Second Basis in
Terms of the First (cont.)
โข In this example, we have ๐ฐ = ๐ ๐ and ๐ฐ = ๐ ๐.
โข So
๐ ๐ = ๐ ๐
โข With ๐ = ๐๐T, we have
๐ ๐ = ๐๐T๐โ ๐ = ๐T๐
โข Thus, ๐ and ๐ are related by ๐T
16Representation w.r.t first basis (V)
Representation w.r.t the second basis (U)
or
Change of Coordinate Frames
โข We can apply a similar process in homogeneous coordinates
to the representations of both points and vectors
โข Any point or vector can be represented in either coordinate frame.
โข We can represent (Q0, u1, u2, u3) in terms of (P0, v1, v2, v3)
Consider two coordinate
frames:
(P0, v1, v2, v3)
(Q0, u1, u2, u3)
P0 v1
v2
v3
Q0
u1u2
u3
17
Representing One Coordinate Frame in
Terms of the Other
โข We can extend what we did with the change of basis
vectors:
by replacing the 3 ร 3 matrix ๐ by a 4 ร 4 matrix as follows:
๐ฎ1 = ๐พ11๐ฏ1 + ๐พ12๐ฏ2+๐พ13๐ฏ3๐ฎ2 = ๐พ21๐ฏ1 + ๐พ22๐ฏ2+๐พ23๐ฏ3๐ฎ3 = ๐พ31๐ฏ1 + ๐พ32๐ฏ2+๐พ33๐ฏ3๐0 = ๐พ41๐ฏ1 + ๐พ42๐ฏ2+๐พ43๐ฏ3 + ๐0
๐ =
๐พ11 ๐พ12 ๐พ13๐พ21 ๐พ22 ๐พ23๐พ31 ๐พ32 ๐พ33
000
๐พ41 ๐พ42 ๐พ43 1
18
Working with Representations
โข Within the two coordinate frames any point or vector has a representation of the same form:
๐ = ๐ผ1 ๐ผ2 ๐ผ3 ๐ผ4 in the first frame
๐ = ๐ฝ1 ๐ฝ2 ๐ฝ3 ๐ฝ4 in the second frame
where a4 = b4 = 1 for points and a4 = b4 = 0 for vectors and
๐ = ๐T๐
โข The matrix ๐T is 4 ร 4 and specifies an affine transformation in homogeneous coordinates
19
or
Transformations in Graphics pipeline
1. Object (or model) coordinates
2. World coordinates
3. Eye (or camera) coordinates
4. Clip coordinates
5. Normalized device coordinates
6. Window (or screen) coordinates
The six frames are w.r.t. immediate-mode rendering
We had considered the following coordinate systems
Affine
transform
Can be
combined in
model-view
transform
Brings representations
in the eye-frame
Moving the Camera
๐ =
1 0 0 00 1 0 000
00
10
01
Camera and object frame in default positions
model-view matrix
Moving the Camera
๐ =
1 0 0 00 1 0 000
00
10
โ๐1
โข The application programmer works in the object/world coordinates (a.k.a. application frame)
Camera frame is fixed, we are placing object frame relative to
the camera frame.
Where did we get A
(model-view matrix) from?
Moving the Camera
๐ =
1 0 0 00 1 0 000
00
10
โ๐1
โข The application programmer works in the object/world coordinates (a.k.a. application frame)
Camera frame is fixed, we are placing object frame relative to
the camera frame.
Remember?
Moving the Camera
๐ =
1 0 0 00 1 0 000
00
10
โ๐1
โข The application programmer works in the object/world coordinates (a.k.a. application frame)
Camera frame is fixed, we are placing object frame relative to
the camera frame.
Remember?
Refer to
slide#18
Moving the Camera
๐ =
1 0 0 00 1 0 000
00
10
โ๐1
โข The application programmer works in the object/world coordinates (a.k.a. application frame)
Camera frame is fixed, we are placing object frame relative to
the camera frame.
Remember?
Representation
w.r.t camera
frame
Representation
w.r.t object
frame
Moving the Camera
๐ =
1 0 0 00 1 0 000
00
10
โ๐1
โข The application programmer works in the object/world coordinates (a.k.a. application frame)
Camera frame is fixed, we are placing object frame relative to
the camera frame.
Remember?
Representation
w.r.t camera
frame
Representation
w.r.t object
frame
Moving the Camera
๐ =
1 0 0 00 1 0 000
00
10
โ๐1
โข The application programmer works in the object/world coordinates (a.k.a. application frame)
Camera frame is fixed, we are placing object frame relative to
the camera frame.
Remember?
Representation
w.r.t camera
frame
Representation
w.r.t object
frame
Model View
matrix (A)
Moving the Camera
๐ =
1 0 0 00 1 0 000
00
10
โ๐1
โข The application programmer works in the object/world coordinates (a.k.a. application frame)
Camera frame is fixed, we are placing object frame relative to
the camera frame.
This matrix takes a point (0, 0, d) in the
object/world frame, whose representation is:
p =[0 0 ๐ 1]๐
to
pโ= [0 0 0 1]๐
i.e., the origin in the camera frame
Moving the Camera
๐ =
1 0 0 00 1 0 000
00
10
โ๐1
โข The application programmer works in the object/world coordinates (a.k.a. application frame)
Camera frame is fixed, we are placing object frame relative to
the camera frame.
This matrix takes a point (0, 0, d) in the
object/world frame, whose representation is:
p=[0 0 ๐ 1]๐
to
pโ= [0 0 0 1]๐
i.e., the origin in the camera frame
๐ฉโฒ = ๐๐ฉ
The World and Camera Coordinate
Framesโข When we work with representations, we work with
n-tuples or arrays of scalars
โข Changes in coordinate frame are then defined by 4 ร 4matrices
โข In OpenGL, the base frame that we start with is the world frame
โข Eventually we represent entities in the camera frame by changing the world representation using the model-view matrix
โข Initially these frames are the same (i.e., M=I)
30
An Example
We consider two reference frames that have basis vector relation
Let's say the reference point does not change, so
Our matrix MT would be:
Only accounting for
rotation
An Example
Now, we want our frames to have different reference pointโฆ.
Letโs say, to the point Q0 that has the following representation in
the original system.
The MT for such a setting will be:
Also accounting for
translation
A Few Common Transformations
โข Rigid transformation: The 4 ร 4 matrix has the form:
๐ ๐ญ๐T 1
where ๐ is a 3 ร 3 rotation matrix and ๐ญ โ โ๐๐ฑ๐ is a
translation vector. Rigid transformation preserves
everything (angle (this means the shape), length, area, etc.,)
โข Similarity transformation: The matrix has the form:
๐ ๐ ๐ญ๐T 1
or๐ ๐ญ๐T ๐ โฒ
where ๐ , ๐ โฒ โ 1. Similarity transformation preserves angle,
ratios of lengths and of areas.
Large (or small) ๐ values enlarge (or
diminish) the object
Small (or large) ๐ โฒvalues enlarge (or
diminish) the object
33
A Few Common Transformations (cont.)
โข Affine transformation: The 4 ร 4 matrix has the form:
๐ด ๐ญ๐T 1
where ๐ด can be any 3 ร 3 non-singular matrix and
๐ญ โ โ๐ is a translation vector. Affine transformation
preserves parallelism, ratios of lengths.
โข Perspective transformation: The matrix can be any non-
singular 4 ร 4 matrix. Perspective transformation matrix
preserves cross ratios (i.e., ratio of ratios of lengths).
34
โข Rigid transformation is equivalent to a change in
coordinate frames. It has 6 degrees of freedom (dof) i.e.,
3 rotations + 3 translations (along each of the three axes)
โข Similarity transformation has 7 dof (an additional scaling)
โข Affine transformation has 12 dofโ 3 rotations + 3 translations + 3 scaling + 3 shear
35
A Few Common Transformations (cont.)
General Transformations
โข A transformation maps points to other points
and/or vectors to other vectors
Q=T(P)
v = T(u)
36
Pipeline Implementation
v
transformation rasterizer
u
u
v
T
T(u)
T(v)
T(u)
T(v)
vertices(before transformation)
vertices(after transformation)
pixels
frame
buffer
(from application program)
T(u)
T(v)
37
Further Reading
โInteractive Computer Graphics โ A Top-Down Approach with Shader-Based OpenGLโ by Edward Angel and Dave Shreiner, 6th
Ed, 2012
โข Sec 3.7 to 3.9