CSE 167:
Introduction to Computer Graphics
Lecture #2: Coordinate Transformations
Jürgen P. Schulze, Ph.D.
University of California, San Diego
Fall Quarter 2011
Announcements
Homework #1 due Friday Sept 30, 1:30pm;
presentation in lab 260
Don’t save anything on the C: drive of the lab PCs in
Windows.You will lose it when you log out!
2
Overview
Linear Transformations
Homogeneous Coordinates
Affine Transformations
Concatenating Transformations
Change of Coordinates
Common Coordinate Systems
3
Linear Transformations
Scaling, shearing, rotation, reflection of vectors, and
combinations thereof
Implemented using matrix multiplications
4
Scaling
Uniform scaling matrix in 2D
Analogous in 3D
5
Scaling
Nonuniform scaling matrix in 2D
Analogous in 3D
6
Shearing
Shearing along x-axis in 2D
Analogous for y-axis, in 3D
7
Rotation in 2D
Convention: positive angle rotates counterclockwise
Rotation matrix
8
Rotation in 3D
Rotation around coordinate axes
9
Rotation in 3D
Concatenation of rotations around x, y, z axes
are called Euler angles
Result depends on matrix order!
10
Rotation in 3D
Around arbitrary axis
1 + (1 − cos(θ ))(ax2 − 1) −az sin(θ ) + (1 − cos(θ ))ax ay ay sin(θ ) + (1 − cos(θ ))ax az
R(a,θ ) = az sin(θ ) + (1 − cos(θ ))ay ax 1 + (1 − cos(θ ))(ay2 − 1) −ax sin(θ ) + (1 − cos(θ ))ay az
−ay sin(θ ) + (1 − cos(θ ))az ax ax sin(θ ) + (1 − cos(θ ))az ay 1 + (1 − cos(θ ))(az2 − 1)
Rotation axis a
a must be a unit vector: a =1
Right-hand rule applies for direction of rotation
Counterclockwise rotation
11
Overview
Linear Transformations
Homogeneous Coordinates
Affine Transformations
Concatenating Transformations
Change of Coordinates
Common Coordinate Systems
12
Homogeneous Coordinates
Generalization: homogeneous point
Homogeneous coordinate
Corresponding 3D point: divide by homogeneous
coordinate
13
Homogeneous coordinates
Usually for 3D points you choose
For 3D vectors
Benefit: same representation for vectors and points
14
Translation
Using homogeneous coordinates
15
Translation
Using homogeneous coordinates
Matrix notation
Translation matrix
16
Transformations
Add 4th row/column to 3 x 3 transformation matrices
Example: rotation
17
Transformations
Concatenation of transformations:
Arbitrary transformations (scale, shear, rotation,
translation)
Build “chains” of transformations
Result depends on order
18
Overview
Linear Transformations
Homogeneous Coordinates
Affine Transformations
Concatenating Transformations
Change of Coordinates
Common Coordinate Systems
19
Affine transformations
Generalization of linear transformations
Scale, shear, rotation, reflection (linear)
Translation
Preserve straight lines, parallel lines
Implementation using 4x4 matrices and homogeneous
coordinates
20
Translation
21
Translation
• Inverse translation
22
Scaling
• Origin does not change
23
Scaling
Inverse of scale:
24
Shear
Pure shear if only one parameter is non-zero
25
Rotation around coordinate axis
Origin does not change
26
Rotation around arbitrary axis
Origin does not change
Angle , unit axis a
27
Rotation matrices
Orthonormal
Rows, columns are unit length and orthogonal
Inverse of rotation matrix:
Its transpose
28
Overview
Linear Transformations
Homogeneous Coordinates
Affine Transformations
Concatenating Transformations
Change of Coordinates
Common Coordinate Systems
29
Rotating with pivot
Rotation around Rotation with
origin pivot
30
Rotating with pivot
1. Translation 2. Rotation 3. Translation
31
Concatenating transformations
Arbitrary sequence of transformations
Note: associativity
32
Overview
Linear Transformations
Homogeneous Coordinates
Affine Transformations
Concatenating Transformations
Change of Coordinates
Common Coordinate Systems
33
Change of coordinates
Point with homogeneous coordinates
Position in 3D given with respect to a coordinate system
34
Change of coordinates
New uvwq
coordinate system
Goal: Find coordinates of with respect to
new uvwq coordinate system
35
Change of coordinates
Coordinates of xyzo frame w.r.t. uvwq frame
36
Change of coordinates
Same point p in 3D, expressed in new uvwq frame
37
Change of coordinates
38
Change of coordinates
Inverse transformation
Given point w.r.t. frame
Coordinates w.r.t. frame
39
Overview
Linear Transformations
Homogeneous Coordinates
Affine Transformations
Concatenating Transformations
Change of Coordinates
Typical Coordinate Systems
40
Typical Coordinate Systems
Camera, world, object coordinates:
Camera
coordinates Object
coordinates
World coordinates
Object Coordinates
Coordinates the object is defined with
Often origin is in middle, base, or corner of object
No right answer, whatever was convenient for the creator
of the object
Camera
coordinates Object
coordinates
World coordinates
42
World Coordinates
“World space”
Common reference frame for all objects in the scene
Chosen for convenience, no right answer
If there is a ground plane, usually x/y is horizontal and z points
up (height)
In OpenGL x/y is screen plane, z comes out
Camera
coordinates Object
coordinates
World coordinates
43
World Coordinates
Transformation from object to world space is different
for each object
Defines placement of object in scene
Given by “model matrix” (model-to-world transform) M
Camera
coordinates Object
coordinates
World coordinates
44
Camera Coordinate System
“Camera space”
Origin defines center of projection of camera
x-y plane is parallel to image plane
z-axis is perpendicular to image plane
Camera
coordinates Object
coordinates
World coordinates
45
Camera Coordinate System
The Camera Matrix defines the transformation from
camera to world coordinates
Placement of camera in world
Transformation from object to camera coordinates
Camera
coordinates Object
coordinates
World coordinates
46
Camera Matrix
Construct from center of projection e, look at d, up-
vector up:
Camera
coordinates
World coordinates
47
Camera Matrix
Construct from center of projection e, look at d, up-
vector up:
Camera
coordinates
World coordinates
48
Camera Matrix
z-axis
x-axis
y-axis
49
Inverse of Camera Matrix
How to calculate the inverse of the camera matrix C-1?
Generic matrix inversion is complex and compute-
intensive
Observation:
camera matrix consists of rotation and translation: R x T
Inverse of rotation: R-1 = RT
Inverse of translation: T(t)-1 = T(-t)
Inverse of camera matrix: C-1 = T-1 x R-1
50
Objects in Camera Coordinates
We have things lined up the way we like them on screen
x to the right
y up
-z going into the screen
Objects to look at are in front of us, i.e. have negative z values
But objects are still in 3D
Next step: project scene into 2D
51
Next Lecture
Rendering Pipeline
Perspective Projection
52