Lecture 8: Coordinate Frames CITS3003 Graphics & Animation E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 2012
Objectives Learn how to define and change coordinate frames Introduce standard transformations Rotation, Translation, Scaling, Shear Derive homogeneous coordinate transformation matrices Learn to build arbitrary transformation matrices from simple transformations 2
Coordinate Frame Basis vectors alone cannot represent a points We can add a single point, the origin, to the basis vectors to form a coordinate frame Recall the affine space v 2 P 0 v 1 v 3 3
Representation in a Coordinate Frame A coordinate system (or coordinate frame) is determined by P 0, v 1, v 2, v 3 Within this coordinate frame, every vector v can be written as v = α 1 v 1 + α 2 v 2 + α 3 v 3 Every point can be written as P = P 0 + β 1 v 1 + β 2 v 2 + β 3 v 3 for some α 1, α 2, α 3, and β 1, β 2, β 3 4
Homogeneous Coordinates Consider the point P and the vector v, where P = P 0 + β 1 v 1 + β 2 v 2 + β 3 v 3 v = α 1 v 1 + α 2 v 2 + α 3 v 3 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 v p Vector can be placed anywhere point: fixed 5
A Single Representation Since 0 P = 0 and 1 P = P then we can write v = α 1 v 1 + α 2 v 2 + α 3 v 3 = α 1 v 1 + α 2 v 2 + α 3 v 3 + 0 P 0 P = β 1 v 1 + β 2 v 2 + β 3 v 3 + P 0 = β 1 v 1 + β 2 v 2 + β 3 v 3 + 1 P 0 Thus we obtain the four-dimensional homogeneous coordinate representation v = α 1 α 2 α 3 0 T v = 0 P = β 1 β 2 β 3 1 T v 6
Homogeneous Coordinates The homogeneous coordinate form for a three dimensional point x y z T is given as p = x y z 1 T = wx wy wz w T = x y z w T We return to a three dimensional point (for w 0) by x x /w y y /w z z /w If w = 0, the representation is that of a vector Note that homogeneous coordinates replace points in three dimensions by lines through the origin in four dimensions For w = 1, the representation of a point is x y z 1 T 7
Homogeneous Coordinates and Computer Graphics 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 8
Representing the Second Basis in Terms of the First How can we relate a with b? Each of the basis vectors u 1, u 2, and u 3 are vectors that can be represented in terms of the first set of basis vectors, i.e., u 1 = γ 11 v 1 + γ 12 v 2 +γ 13 v 3 u 2 = γ 21 v 1 + γ 22 v 2 +γ 23 v 3 u 3 = γ 31 v 1 + γ 32 v 2 +γ 33 v 3 v for some γ 11,, γ 33 9
Representing the Second Basis in Terms of the First (cont.) u 1 = γ 11 v 1 + γ 12 v 2 +γ 13 v 3 can be written as: γ 11 γ 11 u 1 = v 1 v 2 v 3 γ 12 = V γ 12 γ 13 γ 13 Similarly, u 2 = γ 21 v 1 + γ 22 v 2 +γ 23 v 3 and u 3 = γ 31 v 1 + γ 32 v 2 +γ 33 v 3 can be written as: u 2 = V u 3 = V γ 21 γ 22 γ 23 γ 31 γ 32 γ 33 10
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 M = γ 21 γ 22 γ 23 γ 31 γ 32 γ 33 then we have: u 1 u 2 u 3 = V M T That is, U = V M T The superscript T denotes matrix transpose 11
The same vector w represented in two coordinate systems We can write w = α 1 v 1 + α 2 v 2 + α 3 v 3 w = β 1 u 1 + β 2 u 2 + β 3 u 3 Each v i is a column vector of 3 components as follows: w = v 1 v 2 v 3 w = u 1 u 2 u 3 α 1 α 2 α 3 β 1 β 2 β 3 = V a = U b Let s call this 3 3 matrix V 12
Representing the Second Basis in Terms of the First (cont.) In this example, we have w = V a and w = U b. So V a = U b With U = V M T, we have V a = V M T b a = M T b Thus, a and b are related by M T 13
Change of Coordinate Frames We can apply a similar process in homogeneous coordinates to the representations of both points and vectors Consider two coordinate frames: (P 0, v 1, v 2, v 3 ) (Q 0, u 1, u 2, u 3 ) v 3 P 0 v 1 Any point or vector can be represented in either coordinate frame. We can represent (Q 0, u 1, u 2, u 3 ) in terms of (P 0, v 1, v 2, v 3 ) v 2 u 1 u 2 Q 0 u 3 14
Representing One Coordinate Frame in Terms of the Other We can extend what we did with the change of basis vectors: u 1 = γ 11 v 1 + γ 12 v 2 +γ 13 v 3 u 2 = γ 21 v 1 + γ 22 v 2 +γ 23 v 3 u 3 = γ 31 v 1 + γ 32 v 2 +γ 33 v 3 Q 0 = γ 41 v 1 + γ 42 v 2 +γ 43 v 3 + P 0 by replacing the 3 3 matrix M by a 4 4 matrix as follows: M = γ 11 γ 12 γ 13 0 γ 21 γ 22 γ 23 0 γ 31 γ 32 γ 33 0 γ 41 γ 42 γ 43 1 15
Working with Representations Within the two coordinate frames any point or vector has a representation of the same form: a = α 1 α 2 α 3 α 4 in the first frame b = β 1 β 2 β 3 β 4 in the second frame where a 4 = b 4 = 1 for points and a 4 = b 4 = 0 for vectors and a = M T b The matrix M T is 4 4 and specifies an affine transformation in homogeneous coordinates 16
A Few Common Transformations Rigid transformation: The 4 4 matrix has the form: R t 0 T 1 where R is a 3 3 rotation matrix and t R 3 is a translation vector. Rigid transformation preserves everything (angle (this means the shape), length, area, etc) Similarity transformation: The matrix has the form: sr t 0 T 1 or R t 0 T s Large (or small) s values enlarge (or diminish) the object Small (or large) s values enlarge (or diminish) the object where s, s 1. Similarity transformation preserves angle, ratios of lengths and of areas. 17
A Few Common Transformations (cont.) Affine transformation: The 4 4 matrix has the form: A 0 T 1 where A can be any 3 3 non-singular matrix and t R 3 is a translation vector. Affine transformation preserves parallelism, ratios of lengths. Perspective transformation: The matrix can be any nonsingular 4 4 matrix. Perspective transformation matrix preserves cross ratios (i.e., ratio of ratios of lengths). t 18
A Few Common Transformations (cont.) 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 because the 4 elements on the last row of the matrix are fixed 3 rotations + 3 translations + 3 scaling + 3 shear 19
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 4 matrices 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 modelview matrix Initially these frames are the same (i.e, M=I) 20
Moving the Camera If objects are on both sides of z = 0, we must move the camera coordinate frame, e.g., M = 1 0 0 0 0 1 0 0 0 0 0 0 1 0 d 1 21
General Transformations A transformation maps points to other points and/or vectors to other vectors v = T(u) Q=T(P) 22
Affine Transformations Preserving parallel lines Characteristic of many physically important transformations Rigid body transformations: rotation, translation Scaling, shear Importance in graphics is that we need only transform endpoints of line segments and let implementation draw line segment between the transformed endpoints 23
Pipeline Implementation T (from application program) u v transformation T(u) T(v) rasterizer frame buffer v T(v) T(v) u vertices (before transformation) T(u) vertices (after transformation) T(u) pixels 24
Notation We will be working with both coordinate-free representations of transformations and representations within a particular frame P, Q, R: points in an affine space p, q, r: representations of points - array of 4 scalars in homogeneous coordinates u, v, w: representations of vectors in an affine space - array of 4 scalars in homogeneous coordinates α, β, γ: scalars 25
Translation Move (translate, displace) a point to a new location P P Displacement determined by a vector d Three degrees of freedom d P = P + d 26
How many ways? Although we can move a point to a new location in an infinite number of ways, when we move many points (of a rigid object) there is usually only one way object translation: every point displaced by same vector 27
Translation using Representations Using the homogeneous coordinate representation in some frame p = [x y z 1] T p = [x y z 1] T d = [d x d y d z 0] T Hence p = p + d or x = x + d x y = y + d y z = z + d z note that this expression is in four dimensions and expresses point = vector + point 28
Translation Matrix We can also express translation using a 4 4 matrix T in homogeneous coordinates p = Tp where 1 0 0 d x 0 1 0 d T = T(d x, d y, d z ) = y 0 0 1 d z 0 0 0 1 This form is better for implementation because all affine transformations can be expressed this way and multiple transformations can be concatenated together 29
Further Reading Interactive Computer Graphics A Top-Down Approach with Shader-Based OpenGL by Edward Angel and Dave Shreiner, 6 th Ed, 2012 Sec 3.7 to 3.9