Jorg s Graphics Lecture Notes Coordinate Spaces Coordinate Spaces Computer Graphics: Objects are rendered in the Euclidean Plane. However, the computational space is better viewed as one of Affine Space Projective Space Grassmann space Tensor Algebra Clifford space Euclidian Space Rules of the Space With the inner product ( ) and cross product ( ), we have angles ( v w ), lengths ( v v ), area ( v w ) and volume ( (u v) w ). Working with Multiple Vectors v w Projection of the vector v onto the vector w: Perpendicular component of v to w: ṽ := v v w Reflection of v across w: v 2ṽ w w w w w w w Point Transformations The linear map that maps four points p 0, p, p 2, p 3 to four points p 0, p, p 2, p 3 can be computed as follows: () set v i := p i p 0, v i := p i p 0. (2) Then v 3 = M M v 3, M := [v,v 2,v v 2 R 3 3. Exercise: Parameterize a rotation about a line in 3-space.
Jorg s Graphics Lecture Notes Coordinate Spaces 2 Affine Space Affine Space has two kinds of elements: points (location) p and vectors (direction) v. i λ iv i is a vector; i λ ip i is an allowable operation only if i λ i =. Affine coordinates in R 3 : append a 0 or as 4th coordinate [ p := [ p p 2 p 3 T ; [ v 0 := [ ṽ ṽ 2 ṽ 3 0 T. Translation 0 0 t x x x + t x 0 0 t y y 0 0 t z z = y + t y z + t z. 0 0 0 Rotation: with s := sin(θ), c := cos(θ) c s 0 0 x cx sy s c 0 0 y 0 0 0 z = sx + cy z. 0 0 0 Rigid transformations = translation, rotation and reflection. Orthographic projection 0 0 0 0 0 0 0 0 0 0 0 0 0 Plane with normal n, all (x, y, z) such that [ x n x n y n z n c y z = 0 Conic, all (x, y) such that [ x y Q Q 2 L Q 2 Q 22 L 2 x y = 0 L L 2 C 0 Quadric, all (x, y, z) s.t. [ x y z Q Q 2 Q 3 L x Q 2 Q 22 Q 23 L 2 y Q 3 Q 23 Q 23 L 3 z = 0 L L 2 L 3 C 0
Jorg s Graphics Lecture Notes Coordinate Spaces 3 The Bernstein-Bézier form is well-defined since i b i(u) = for b i (u) := ( d ) i ( u) d i u i. Shortcomings of Affine Space for Graphics: While vectors can be added to vectors and points, points can only be added under extra constraints. Therefore there are two disjoint copies of Euclidean space. P P i wipibi(u) i wibi(u) The rational Bernstein-Bézier form be represented because generally w i {0, }. Perspective projection cannot be represented i [ wipi w i b i (u) cannot Projector Object Object COP Projection plane vs DOP Projector Projection plane
Jorg s Graphics Lecture Notes Coordinate Spaces 4 Projective Space, Homogenous Coordinates Projective Space has two kinds of elements: Affine Points and Points at Infinity. The points can be modeled by embedding in a space of one more dimension, as homogenous coordinates. Homogenous Representation Of an affine point is [ x x 2... x n x n+ T for xn+ 0; Of a point at infinity is [ x x 2... x n 0 T ; Completes the geometry of Affine Space: A pair of lines always intersects in a point, possibly at infinity. (advanced) More generally, Bezout s Theorem holds in complex projective space: for polynomials p(x,y) and q(x,y) that have no common factor and are of degree m and n repectively, the curves p(x,y) = 0 and q(x, y) = 0 have mn intersections. Perspective Scaling 0 0 0 x 0 0 0 y 0 0 0 z = 0 0 0 /k x y z /k = kx ky kz. Frustum, Clipping (Projection into 3D double unit box) with x := x x = (xmax-xmin) etc. 2 x 0 0 x+x x glfrustum(xmin,xmax,ymin,ymax,near,far) 2 0 y 0 ȳ+y y 2 0 0 z z+z z 0 0 0 Maps a viewing frustum (rectangular box) to [, 3. Example: (A point between x and x is mapped to the interval [, ) x = 4, x = 0, x = 4, x+x x =, 2 x = /2. Then [ 3 is mapped to [ /2. Duality theorems hold: points and planes (represented by normals) behave (almost) identically. (advanced) Pascal s and Brianchon s Theorems hold: Pascal: inscribe a hexagon in a conic; then opposite edges intersect in three points that are collinear. Brianchon: circumscribe a hexagon about a conic; then the diagonals are concurrent.
Jorg s Graphics Lecture Notes Coordinate Spaces 5 Shortcomings of Projective Space for Graphics A point on a projective line does not split the line into two parts: a person looking in one unobstructed direction sees his on back. Construction of curves is unintutive. There is no notion of length. It is not a vector space. Addition of homogeneous coordinates (here n = 2) does not work: 2 = 2 4, 3 2 = 9 6, but 2 + 3 2 = 4 4 0 = 2 4 + 9 6. 3 6 3 3 4 9 6 3 Therefore i [ pi w i b i (u) does not make sense. To complete the algebra (to make sense of the addition of 4-vectors) we will need a Grassmann space.
Jorg s Graphics Lecture Notes Coordinate Spaces 6 Grassmann space A (n + dimensional) linear vector space where points are of the form [ wp w. Then addition of these weighted mass points is according to (Archimedes law of the lever): [ wp w + [ w2p2 w 2 = [ wp+w2p2 w +w 2 = (w + w 2 )[ wp +w 2p 2 w +w 2 In particular, the Euclidean component is w p + w 2 p 2 w + w 2.. [ wp+w2p2 w +w 2 [ w2p2 w 2 affine points [ wp w [ p [ p2 affine vectors [ w p +w 2 p 2 w +w 2 [ 0 0
Jorg s Graphics Lecture Notes Coordinate Spaces 7 Perspective Projection Let ˆn be the projection plane (ˆn := [ n d ; n is the normal and d the distance to the 0 R 3 ) and ê the eye position. The perspective projection matrix P in Grassmann coordinates is Then the projection is P := outerprod(ê, ˆn) diag(ê ˆn). p + := P ˆp = ê(ˆn ˆp) (ê ˆn)ˆp. To verify, intersect the line through the points ˆp := [ wp w and ê with the plane ˆnˆx = 0. and check that ˆn p + = 0. Example: (vertical z direction, horizontal x direction, no y) ê ˆx : ˆx ˆn = 0 p + (perspective projection) ˆn depth(p) p For example, in homogenous coordinates [ x z w (i.e. we drop the y dimension and the projection plane is a projection line), let ê := [ 4 4 ˆp, ˆp := [ 2 2 and ˆn := [ 0, i.e. the projection plane is the line {(x, z, ) : z = } (since [ x z [ 0 = 0 is the equation of the plane). Then p + := 3[ 4 4 3[ 2 2 = [ 6 6 [. 6 Tensor Algebra Transformation of normal: by inverse of vertex transformation matrix: ˆn T ˆx = 0 (ˆnM )(Mˆx). ˆx (points, tangents) are contra-variant. ˆn (normals) are co-variant. M (transformation) contra-variant 2-tensor. Q (conic section) co-variant 2-tensor.
Jorg s Graphics Lecture Notes Coordinate Spaces 8 3D interfaces Trackball Goal: convert a 2D (integer) change of mouse position to a rotation in 3D. Sample Code 4track.c Description Associate each mouse position = (i, j) with the point on a unit hemisphere: () For w=width, scale the x component to (2i w)/w and the y component to (2j w)/w. (2) set z := x 2 y 2. centered, but mouse starts at 0 Two consecutive points P and P 2 on the hemisphere define a normal direction n = P P 2. Rotate about n.
Jorg s Graphics Lecture Notes Coordinate Spaces 9 3D interfaces Problems with Euler angles Rotate about x, y, z axis Anisotropy, Coordinate system dependence: The ordering and orientation of the coordinate axes is important. (The parameters lack a simple, local geometric interpretation.) Finding the Euler angles for a given orientation is difficult. (although getmatrix() helps) Gimbal Lock: a degree of freedom can vanish. However, easy to implement and widely used. Gimbal lock: Mechanical problem that arises in the support of gyroscopes by three nested rotating frames. After a y-rotation by π/2 (rotates x-axis onto z-axis) an x-rotation by α equals z-rotation by α. Objects seem to stick. Some orientations are difficult to obtain from the wrong direction. interpolation through singularity behaves unpredictable. The effect is simple to see algebraically. If α y = π/2 (and c y = cos(α y ) etc.) then c y 0 s y 0 0 0 0 R y = 0 0 0 s y 0 c y 0 = 0 0 0 0 0 0 0 0 0 0 0 0 and 0 0 0 0 0 0 c z s z 0 0 R x R y R z = 0 c x s x 0 0 0 0 s z c z 0 0 0 s x c x 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 = s c 0 0 c s 0 0 0 0 0 where c = cos(α x α z ) and s = sin(α x α z ) : only one degree of freedom!
Jorg s Graphics Lecture Notes Coordinate Spaces 0 3D interfaces Quaternions Motivating Analogy: 2D rotation of the point x = (x, x 2 ) by the angle α can be expressed as multiplication with a matrix of the form [ c s c := cos(α),, s c s := sin(α). or, alternatively, expressing x as the complex number x +ix 2 where i :=, as multiplication in the complex field by e iα = cos(α) + i sin(α). The appropriate field for expressing rotations in 3D are the (normalized) quaternions ˆq := q 0 + iq + jq 2 + kq 3 = (q 0, q, q 2, q 3 ) =: (q 0,q), where q := (q, q 2, q 3 ) is a vector in R 3. Quaternions have the multiplication table i j k i k j j k i k j i The product of two quaternions ˆp and ˆq is again a quaternion: ˆp ˆq = (p 0 q 0 (p q + p 2 q 2 + p 3 q 3 ), p 0 q + q 0 p + p q). We define ˆq 2 = q 2 0 + q q. This implies (check that ˆq ˆq is real) Construction and Use ˆq = (q 0, q)/ ˆq 2 Quaternion for rotation about x R 3 by α: ˆq = (cos(α/2), sin(α/2) x x ) Rotation of the point v := (v, v 2, v 3 ): ˆq (0,v) ˆq. Note: ˆq and ˆq represent the same rotation and rotation by 0 and 360 degrees coincide.
Jorg s Graphics Lecture Notes Coordinate Spaces Interpolating Quaternions for Animation Spherical linear interpolation of rotations (for animation) where φ = acos(ˆp, ˆq) is the angle between ˆp and ˆq viewed as vectors in R 4 : slerp(ˆp, ˆq, t) = ˆp(ˆp ˆq) t = ˆp tˆq t = sin( t)φ ˆp + sin(tφ) sin φ sin φ ˆq. To move from ˆp to ˆq vary t from 0 to. If ˆp or ˆq are not of the same size then angular speed will vary. Hence use only unit quaternions (slerp moves on sphere in 4D along a great arc). Better: quaternion splines Sample Code 4quaternion.c Use the arrows to see motion along a B- spline Quaternions: (advanced) Derivation: The trace of any rotation matrix with angle α is + 2 cos(α). *Therefore* q 0 = cos(α/2) and for some scalar k q 0 = cos(α/2), q = kx. To normalize the quaternion choose k = sin(α/2)/ ˆq since = ˆq = cos(α/2) 2 + k 2 x x. Any rotation matrix can be expressed in terms of a quaternion as 2q2 2 2q2 3 2(q q 2 + q 0 q 3 ) 2(q q 3 q 0 q 2 ) 2(q q 2 q 0 q 3 ) 2q 2 2q3 2 2(q 2 q 3 + q 0 q ) 2(q q 3 + q 0 q 2 ) 2(q 2 q 3 q 0 q ) 2q 2 2q2 2 (more symmetric than Euler) Rotation about x-axis by α: ˆq = (c, s, 0, 0) where c = cos(α/2) and 0 0 0 2s 2 2sc, sin(α) = 2sc, cos(α) = 2s 2. 0 2sc 2s 2 One can also convert from rotation matrix to quaternion.
Jorg s Graphics Lecture Notes Coordinate Spaces 2 Camera Position A change of the model-view (multiplication by model-view matrix) can be interpreted either as (a) changing subsequent camera position or (b) applying the inverse motion to the world (and the camera always looks down negative z axis). In matrix notation, object O, camera C, transformation matrices M i M 3 M 2 M O and C is the same as M O and M 2 M 3 C Specification of the camera requires six scalars 3 for the position (View Reference Point) and 3 for the orientation (2 for the (normalized) view-plane normal and (angle) for the up-direction.) Instead of the normal to the view-plane, an unnormalized 3-vector at can be chosen. Instead of the up-direction v to the view-plane, an unnormalized 3-vector up can be chosen; the projection into the view plane v := up up at at at at defines the up direction in the view plane. (Check n v = 0.) glulookat(eyex, eyey, eyez, atx,aty,atz, upx,upy,upz) (at x, at y, at z ) y (up x, up y, up z ) x (eye x, eye y, eye z ) z
Jorg s Graphics Lecture Notes Coordinate Spaces 3 Relative Coordinates and Angle-based Coordinates y y y x x x z z Roll Pitch Yaw z n Elevation Azimuth