Chapter 2 - Basic Mathematics for 3D Computer Graphics Three-Dimensional Geometric Transformations Affine Transformations and Homogeneous Coordinates Combining Transformations
Translation t + t Add a vector t Geometrical meaning: Shifting Inverse operation? + t 2 t 3 + t 2 + t 3 Neutral operation? y z x 2
Uniform Scaling s Multiply with a scalar s Geometrical meaning: Changing the size of an object s s s What happens when we scale objects which are not at the origin? y How can we fix that? x z 3
Non-Uniform Scaling s 0 0 s Multiply with three scalars One for each dimension Geometrical meaning? 0 s 2 0 0 0 s 3 s 2 s 3 y x z http://en.wikipedia.org/wiki/utah_teapot 4
Reflection Mirroring) Special case of scaling s s 2 s 3 < 0 s 0 0 0 s 2 0 0 0 s 3 s s 2 s 3 Example: s, s, s 2 3 y Discuss: What does this mean for surface normals? order of polygon edges? handedness? z x 5
Shearing along X Axis + m m 0 0 0 0 0 Only x coordinate values are modified Modification depends linearly on y coordinate value Areas in x/y and x/z plane, as well as volume remain the same Generalization to other axes and arbitrary axis: see later... z y x 6
Rotation about X Axis ) y x coordinate value remains constant Rotation takes place in y/z-plane 2D) α How to compute new x and z coordinates from old ones? y z x ϕ y old sinϕ z old r z old r sinϕ z r cosϕ y old r y old r cosϕ z old 7
Rotation about X Axis 2) y cosα +ϕ) y new r r ϕ y new r cosα +ϕ) r cosa cosϕ r sinα sinϕ α y new cosα y old sinα z old z z new y old r cosϕ z old r sinϕ sinα +ϕ) z new r z r sinα +ϕ) new r sina cosϕ + r cosα sinϕ sinα y old + cosα z old 8
Rotation about X Axis 3) 0 0 0 cosα sinα 0 sinα cosα cosα sinα sinα + cosα y Special cases, e.g. 90 degrees, 80 degrees? How to rotate about other axes? α z x 9
Elementary rotations Combine to express arbitrary rotation 0 0 0 cosα sinα 0 sinα cosα cosα sinα sinα + cosα This is not always intuitive Order matters a lot) cosβ 0 sinβ 0 0 sinβ 0 cosβ cosβ + sinβ cosβ sinβ Likely source of bugs cosγ sinγ 0 sinγ cosγ 0 0 0 cos χ sinγ sinγ + cosγ 0
Transformation of Coordinate Systems Applying a geometric transformation......to all points of a single object: Transforming the object within its own coordinate system....to all points of all objects of the world : effectively transforming the reference coordinate system in the opposite direction Geometric transformations can be used to modify an object...place an object within a reference coordinate system...switch to different reference coordinates
Transformation from 3D to 2D: Projection Many different projections exist see later) Projection onto x/y plane: Forget the z coordinate value Other projections? Other viewpoints? y y 0 0 0 0 p p 2 x x z 2
Chapter 2 - Basic Mathematics for 3D Computer Graphics Three-Dimensional Geometric Transformations Affine Transformations and Homogeneous Coordinates Combining Transformations 3
Affine Transformation Mathematically: A transformation preserving collinearity Points lying on a line before are on a line after transformation Ratios of distances are preserved e.g. midpoint of a line segment) Parallel lines remain parallel Angles and lengths are not preserved Basic transformations: translation, rotation, scaling and shearing All combinations of these are affine transformations again Combination is associative, but not commutative General form of computation: New coordinate values are defined by linear function of the old values p p 2 p 3 a a 2 a 3 a 2 a 22 a 23 a 3 a 32 a 33 + t t 2 t 3 Ap + t 4
Combining Multiple Transformations Rotation, scaling and shearing are expressed as matrices Associative, hence can all be combined into one matrix Many of these operations can also be combined into one matrix Translation is expressed by adding a vector Adding vectors is also associative Many translations can be combined into a single vector Combination of Translation with other operations? Series of matrix multiplications and vector additions, difficult to combine How about using a matrix multiplication to express translation?? 5
Homogeneous Coordinates Usage of a representation of coordinate-positions with an extra dimension Extra value is a scaling factor 3D position x, y, z) is represented by xh, yh, zh, h) such that x x h h, y y h h, z z h h Simple choice for scaling factor h is the value In special cases other values can be used 3D position x, y, z) is represented by x, y, z, ) 6
Translation Expressed in Homogeneous Coordinates p t + t p 2 p 3 + t 2 t 3 + t 2 + t 3 p 0 0 t + t p 2 p 3 0 0 t 2 0 0 t 3 p + t 2 2 p + t 3 3 0 0 0 7
Scaling Expressed in Homogeneous Coordinates p s 0 0 s p 2 p 3 0 s 2 0 0 0 s 3 s 2 s 3 p s 0 0 0 s p 2 p 3 0 s 2 0 0 0 0 s 3 0 s 2 s 3 0 0 0 8
Rotation Expressed in Homogeneous Coordinates p 0 0 p 2 p 3 0 cosα sinα 0 sinα cosα cosα sinα sinα + cosα p p 2 p 3 0 0 0 0 cosα sinα 0 0 sinα cosα 0 0 0 0 cosα p sinα 3 sinα p + cosα 3 9
Shearing Expressed in Homogeneous Coordinates p m 0 + m y p 2 p 3 0 0 0 0 z x p m 0 0 + m p 2 p 3 0 0 0 0 0 0 0 0 0 20
Shearing: General Case p m 2 m 3 0 p 2 p 3 m 2 m 23 0 m 3 m 32 0 0 0 0 + m 2 + m 3 p + m p + m 2 23 3 p + m p + m 3 32 2 2
Computational Complexity for 3D Transformations p p 2 p 3 a a 2 a 3 t a 2 a 22 a 23 t 2 a 3 a 32 a 33 t 3 0 0 0 a + a 2 + a 3 + t a 2 + a 22 + a 23 + t 2 a 3 + a 32 + a 33 + t 3 Operations needed: 9 multiplications 9 additions for an arbitrarily complex affine 3D transformation Runtime complexity improved by pre-calculation of composed transformation matrices Hardware implementations in graphics processors 22
Chapter 2 - Basic Mathematics for 3D Computer Graphics Three-Dimensional Geometric Transformations Affine Transformations and Homogeneous Coordinates Combining Transformations 23
Combining several transformations: Order matters A Rotation 90 around X axis i.e. Y becomes Z ;-) B Translation by 5 along Y axis ABp ABp) means: first translate, then rotate the result BAp BAp) means: first rotate, then translate the result 24
The same example in Three.js var p new THREE.Vector4, 0, 0, ); var m new THREE.Matrix4); // initialized by identity var a new THREE.Matrix4); var b new THREE.Matrix4); var gamma Math.PI/2; // equals 90 degrees a.makerotationx gamma ); // rotation by 90 degrees around X axis b.maketranslation 0, 5, 0 ); // translation by 5 along Y axis m.multiply a ); // Now m contains a m.multiply b ); // Now m contains ab p.applymatrix4 m ); // Now p contains abp 25