Transformations General Transformations Affine
Total Page:16
File Type:pdf, Size:1020Kb
Transformations General Transformations Objectives A transformation maps points to other points and/or vectors to other vectors • Introduce standard transformations - Rotation v=T(u) -Translation -Scaling - Shear • Derive homogeneous coordinate Q=T(P) transformation matrices • Learn to build arbitrary transformation matrices from simple transformations Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 2 Affine Transformations Pipeline Implementation • Line preserving • Characteristic of many physically T (from application program) important transformations frame - Rigid body transformations: rotation, translation u T(u) buffer - Scaling, shear transformation rasterizer v T(v) T(v) • Importance in graphics is that we need T(v) only transform endpoints of line segments v T(u) and let implementation draw line segment u T(u) between the transformed endpoints vertices vertices pixels Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 3 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 4 1 Notation Translation We will be working with both coordinate-free • Move (translate, displace) a point to a representations of transformations and new location representations within a particular frame P’ P,Q, R: points in an affine space u, v, w: vectors in an affine space d α, β, γ: scalars P p, q, r: representations of points -array of 4 scalars in homogeneous coordinates • Displacement determined by a vector d u, v, w: representations of points - Three degrees of freedom -array of 4 scalars in homogeneous coordinates -P’=P+d Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 5 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 6 Translation Using How many ways? Representations Although we can move a point to a new location Using the homogeneous coordinate in infinite ways, when we move many points representation in some frame there is usually only one way p=[ x y z 1]T p’=[x’ y’ z’ 1]T d=[dx dy dz 0]T Hence p’ = p + d or x’=x+dx note that this expression is in y’=y+d four dimensions and expresses y point = vector + point object translation: every point displaced z’=z+d by same vector z Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 7 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 8 2 Translation Matrix Rotation (2D) We can also express translation using a Consider rotation about the origin by θ degrees 4 x 4 matrix T in homogeneous coordinates - radius stays the same, angle increases by θ p’=Tp where x’ = r cos (φ + θ) ⎡1 0 0 d ⎤ x y’ = r sin (φ + θ) ⎢0 1 0 d ⎥ ⎢ y ⎥ T = T(dx, dy, dz) = ⎢0 0 1 dz ⎥ x’= x cos θ – y sin θ ⎢ ⎥ y’ = x sin θ + y cos θ ⎣0 0 0 1 ⎦ This form is better for implementation because all affine transformations can be expressed this way and x = r cos φ multiple transformations can be concatenated together y = r sin φ Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 9 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 10 Rotation about the z axis Rotation Matrix • Rotation about z axis in three dimensions leaves all points with the same z - Equivalent to rotation in two dimensions in ⎡cos θ − sin θ 0 0⎤ planes of constant z ⎢ ⎥ R = R (θ) = sin θ cos θ 0 0 x’=x cos θ –y sin θ z ⎢ ⎥ y’ = x sin θ + y cos θ ⎢ 0 0 1 0⎥ z’ =z ⎢ ⎥ ⎣ 0 0 0 1⎦ - or in homogeneous coordinates p’=Rz(θ)p Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 11 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 12 3 Rotation about x and y axes Scaling • Same argument as for rotation about z axis Expand or contract along each axis (fixed point of origin) - For rotation about x axis, x is unchanged x’=sxx - For rotation about y axis, y is unchanged y’=syx ⎡1 0 0 0⎤ z’=szx ⎢0 cos θ - sin θ 0⎥ ⎢ ⎥ p’=Sp R = Rx(θ) = ⎢0 sin θ cos θ 0⎥ ⎢ ⎥ ⎣0 0 0 1⎦ ⎡sx 0 0 0⎤ ⎢ ⎥ ⎡ cos θ 0 sin θ 0⎤ 0 sy 0 0 S = S(sx, sy, sz) = ⎢ ⎥ ⎢ 0 1 0 0⎥ R = R (θ) = ⎢ ⎥ ⎢ 0 0 sz 0⎥ y ⎢ ⎥ ⎢- sin θ 0 cos θ 0⎥ 0 0 0 1 ⎢ ⎥ ⎣ ⎦ ⎣ 0 0 0 1⎦ Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 13 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 14 Reflection Inverses Corresponds to negative scale factors • Although we could compute inverse matrices by general formulas, we can use simple geometric observations s = -1 s = 1 original -1 x y - Translation: T (dx, dy, dz) = T(-dx, -dy, -dz) - Rotation: R -1(θ) = R(-θ) • Holds for any rotation matrix • Note that since cos(-θ) = cos(θ) and sin(-θ)=-sin(θ) R -1(θ) = R T(θ) sx = -1 sy = -1 sx = 1 sy = -1 -1 - Scaling: S (sx, sy, sz) = S(1/sx, 1/sy, 1/sz) Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 15 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 16 4 Concatenation Order of Transformations • We can form arbitrary affine transformation • Note that matrix on the right is the first matrices by multiplying together rotation, applied translation, and scaling matrices • Mathematically, the following are • Because the same transformation is applied to equivalent many vertices, the cost of forming a matrix p’ = ABCp = A(B(Cp)) M=ABCD is not significant compared to the cost of computing Mp for many vertices p • Note many references use column matrices to represent points. In terms of • The difficult part is how to form a desired transformation from the specifications in the column matrices application p’T = pTCTBTAT Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 17 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 18 General Rotation About Rotation About a Fixed the Origin Point other than the Origin Move fixed point to origin A rotation by θ about an arbitrary axis can be decomposed into the concatenation Rotate of rotations about the x, y, and z axes Move fixed point back M = T(pf) R(θ) T(-pf) R(θ) = Rz(θz) Ry(θy) Rx(θx) y θ v θx θy θz are called the Euler angles Note that rotations do not commute x We can use rotations in another order but with different angles z Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 19 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 20 5 Instancing Shear • In modeling, we often start with a simple • Helpful to add one more basic transformation object centered at the origin, oriented with • Equivalent to pulling faces in opposite directions the axis, and at a standard size • We apply an instance transformation to its vertices to Scale Orient Locate Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 21 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 22 Shear Matrix Consider simple shear along x axis x’ = x + y cot θ y’ = y z’ = z ⎡1 cot θ 0 0⎤ ⎢0 1 0 0⎥ H(θ) = ⎢ ⎥ ⎢0 0 1 0⎥ -1 ⎢ ⎥ H (θ) = H(-θ) ⎣0 0 0 1⎦ Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 23 6.