
COMPUTER GRAPHICS COURSE Transformations Georgios Papaioannou – 2016 ABOUT TRANSFORMATIONS Transformations • They are operators on vectors and points of a corresponding vector or affine space • They alter the coordinates of shape vertices • They are basic building blocks of geometric design: – Help us manipulate shapes to produce new ones – Help us express relations between coordinate systems in a virtual world Affine Transformations • An affine transformation Φ on an affine space is a transformation that preserve affine combinations 푛 푛 퐩 = 푎퐩 ⟹ Φ 퐩 = 푎Φ(퐩) =0 =0 • For shapes in 피2 and 피3 this is an important property: • To transform a shape we only need to transform its defining vertices Affine Transformations on Vertices • Example: Φ Φ(퐩1) 퐩1 퐩0 Φ Φ(퐩0) • The midpoint of the transformed endpoints is the transformed midpoint – Similarly, all transformed points on the line segment can be linearly interpolated form the transformed endpoints Affine Transformations in 2D and 3D • Mappings of the form Φ 퐩 = 퐀 ∙ 퐩 + 퐭 are affine transformations in 피2 and 피3 • 2D: – 퐀 is a 2X2 matrix and 푇 – 퐭 is an offset vector in matric column form: 퐭 = 푡푥 푡푦 • 3D: – 퐀 is a 3X3 matrix and 푇 – 퐭 is an offset vector in matric column form: 퐭 = 푡푥 푡푦 푡푧 Linear Transformations • Linear transformations are affine transformations with the following properties: – Preserve additivity: Φ 퐩 + 퐪 = Φ 퐩 + Φ 퐪 – Preserve scalar multiplication: Φ 푐퐩 = cΦ 퐩 • Important: – The affine transformation Φ 퐩 = 퐀 ∙ 퐩 + 퐭 is not linear (why?) – But the transformation Φ 퐩 = 퐀 ∙ 퐩 is! 2D TRANSFORMATIONS Geometric Transformations in 2D • The 4 common transformations that are used in computer graphics are: – Translation T(p ) Ip t – Rotation R(p ) R p – Scaling S(p ) Ssx, sy p – Shearing Sh(p ) Shsx, sy p • All of the above transformations are invertible, i.e. given Φ 퐩 , there always exists the inverse transformation Φ−1 퐩 : 퐩′ = Φ 퐩 ⟺ 퐩 = Φ−1 퐩′ 2D Translation • Moves a point on the plane 퐩′ = 퐈퐩 + 퐭Ԧ = 퐩 + 퐭Ԧ Y (푝푥 + 푡푥, 푝푦 + 푡푦) 푡푦 (푝푥, 푝푦) X 푡푥 2D Scaling ′ 푠푥 0 퐩 = 퐒푠푥,푠푦퐩 퐒푠 ,푠 = 푥 푦 0 푠푦 • When 푠푥 = 푠푦, then the scaling is isotropic (preserves angles) Y Y (3, 7) (2, 5) (4, 5) (6, 3.5) (4, 2.5) (8, 2.5) (2, 2) (4, 1) (4, 2) (8, 1) X X 2D Rotation • Rotates a point around the origin by angle θ x lcos l cos cos sin sin x cos y sin y lsin l cos sin sin cos x sin y cos Y p xy , ′ 퐩 = 퐑휃퐩 l p xy, cos 휃 − sin 휃 퐑휃 = l sin 휃 cos 휃 θ φ X 2D Rotation - Examples Rotations are always relative to the coordinate system origin! 2D Shearing • Skews the shape by translating a point in one axis proportionally to its coordinate on the other axis ′ 퐩 = 퐒퐡푦,푏퐩 ′ 퐩 = 퐒퐡푥,푎퐩 1 0 1 푎 퐒퐡푦,푏 = 퐒퐡 = 푏 1 푥,푎 0 1 Y (4, 12) Y Y (2, 8) (4, 10) b=2 α=2 (2, 4) (4, 4) (10, 4) (12, 4) (2, 6) (6, 2) (2, 2) (4, 2) (8, 2) X X X Composite Transformations • Useful transformations in computer graphics and visualization rarely consist of a single basic affine transformation • Transformation composition is the stacking of operators (function composition): Φ ∘ Γ 퐩 = Φ(Γ 퐩 ) • We can efficiently compute composite linear transformations Composite Linear Transformations (1) • A useful property of linear transformations is that a composite transformation can be expressed as matrix multiplication: Φ ∘ Γ 퐩 = 횽 ∙ 횪 ∙ 퐩 • In graphics, it allows the efficient computation of multiple composite transformations Composite Linear Transformations (2) • Example: 푅45o 푆1,2 퐩 = 퐑45o퐒1,2퐩 Composite Linear Transformations (3) • Transformations are not commutative in general! 퐑45o퐒1,2퐩 ≠ 퐑45o퐒1,2퐩 Composite Linear Transformations (4) • Unfortunately, translation cannot be expressed as a linear transformation and is therefore impossible to express it as a matrix multiplication • We must convert the transformation to a linear one Homogeneous Coordinates (1) • With homogeneous coordinates, we augment the dimensionality of the space by one • So 푥, 푦 푇 coordinates become 푥, 푦, 푤 푇 • Similarly, all transformations are now expressed as 3X3 matrices – For w=1 we get the basic representation of a point: 푥, 푦, 1 푇 – All points which are multiples of each other are equivalent – Typically, we work with the basic representation of points Homogeneous Coordinates (2) • Therefore the 2D space becomes a plane (slice) embedded in 3D space at w=1 Homogeneous Coordinates (3) • Points on the homogeneous 2D plane define an affine space and not a vector space – Adding two vectors results in a vector outside the plane (remember we also add the w coordinates!) • The origin of our homogeneous coordinate system is typically (0,0,1) (or (0,0,w) in general) • Since addition is not defined in our space, how is translation expressed? Homogeneous Transformations (1) • Translation in our augmented, homogeneous space can be expressed as a linear transformation: – (it is actually a skew (shearing) transformation of x,y w.r.t. w in 3D) ′ 1 0 푡 푥 푥 푥 푤=1 ′ ′ ′ 푦 = 0 1 푡푦 푦 푥 , 푦 = 푥, 푦 + (푡푥, 푡푦) 푤 0 0 1 푤 푥, 푦 (푡푥, 푡푦) 푤 = 1 Homogeneous Transformations (2) • Now all geometric transformations can be performed by matrix multiplication alone! • We can arbitrarily combine transformations in a unified manner 푅휃1 훵퐯1 푅휃2 훵퐯2 푆푠1,푠2 … 퐩 … = 퐑휃1 횻퐯1퐑휃2 횻퐯2퐒푠1,푠2 …퐩 Homogeneous 2D Transformations • In matrix form (3X3) the homogeneous 2D transformations become: 1 0 푡푥 1 푎 0 퐒퐡 = 퐓푡푥,푡푦 = 0 1 푡푦 푥,푎 0 1 0 0 0 1 0 0 1 푠푥 0 0 1 0 0 0 푠 0 퐒푠푥,푠푦 = 푦 퐒퐡푦,푏 = 푏 1 0 0 0 1 0 0 1 cos 휃 − sin 휃 0 퐑휃 = sin 휃 cos 휃 0 0 0 1 Representing Shape Transformations • In the following, we will apply transformations to entire shapes • This is equivalent to applying the transformations on each defining vertex of the shape • Notation: 푥1 푥2 푥3 푥4 퐌1 ∙ 퐌2 ∙ 푅푒푐푡 = 퐌1 ∙ 퐌2 ∙ 퐯1 퐯2 퐯3 퐯4 = 퐌1 ∙ 퐌2 ∙ 푦1 푦2 푦3 푦4 1 1 1 1 shape shape vertices Categorizing the Transformations • Affine: preserve linear combinations • Linear: can be expressed by a concatenation of matrices, preserve parallel lines • Similitudes: preserve ratios of distances and angles • Rigid: preserve distances Inverse Transformations • The inverse of geometric transformation is the inverse matrix 퐌−1 of the original transformation 퐌 • The inverse of a concatenated transformation is the concatenation of the inverse matrices in reverse order: −1 −1 −1 −1 −1 퐌1퐌2퐌3 … 퐌푛 = 퐌푛 … 퐌3 퐌2 퐌1 • Inverse of standard transformations: −1 −1 −1 퐑 = 퐑 퐒푠 ,푠 = 퐒 1 1 퐓푡 ,푡 = 퐓−푡 ,−푡 휃 −휃 푥 푦 , 푥 푦 푥 푦 푠푥 푠푦 Shape Composition • We can use geometric transformations to create complex shapes from simple primitive ones – We use the transformations to modify instances of the original shapes and arrange them in their pose in the composite object Original primitives (object space coords) Composite object Colored object 2D Transformation Example (1) • Given the following primitives y y 1 A B 1 x 1 x 2 • Build this: y 1 1 3 1 1 0.5 x 4 2D Transformation Example (2) • First, let us try to decompose the target shape into primitives: Three shape groups: - Chassis ? - Wheels - Windshield • Observe that in 2D we can order primitives in different layers to hide parts of the geometry • Second, locate the origin of the resulting shape and compare it to the one of the primitives 2D Transformation Example (3) y • Chassis (3XB parts) C1 C2 C3 x • Looks like no scaling is required, just translations and rotations • Now observe where the pivot point should end in each one: y C1 C2 C3 B x 2D Transformation Example (4) • C1: Rotate +90 degrees • The transformation then (remember, it is a CCW is: system) C1 = 퐓(1.0,2.5)퐑휋B • Then translate by (1, 2.5) 2 2.5 Important! y y Rightmost transformations are C1 C1 applied first to the shapes B (vertices) x 1 x Here, we first rotate then translate 2D Transformation Example (5) Important! Order of transformation does matter (remember: transformations are 퐑휋퐓(1.0,2.5)B ≠ C1 relative to origin) 2 y y C1 C1 B x x 2D Transformation Example (6) • Now lets do C2: This only requires a translation y C1 C2 C3 C2 = 퐓(3.0,0.5)B B x 2D Transformation Example (7) • C3: Rotate 180 degrees, then translate y y C1 C2 C3 C1 C2 C3 B x x C3 = 퐓(2.0,1.5)퐑휋B 2D Transformation Example (8) • The windshield Wd is a single piece • Although it is not a rotated version of B, it has a slightly different scale in the X axis, giving it a more slanted slope y Wd y Wd C1 C2 C3 C1 C2 C3 B B x x Wd = 퐓(4.0,1.5)퐒1.5,1.0B 2D Transformation Example (9) Wrong! Important! Never, ever zero the scaling If you want to leave one factors! coordinate unchanged, use a This collapses the shape and the scaling factor of 1 operation is irreversible (try inverting the corresponding scaling matrix…) y y B B x x 퐒1.5,1.0B 퐒1.5,0.0B 2D Transformation Example (10) • The wheels are easy to add since they are identical and only require a uniform scaling and translation • Room for optimization: – Create a “wheel” object (by scaling once the original shape A) – Then only perform the translation: y y Wd C1 C2 C3 A x x Wheel W1 = 퐓(1.0,0.5)Wheel Wheel = 퐒0.5,0.5A W2 = 퐓(3.0,0.5)Wheel Let us Add Some Animation (1) • What if instead of the flat-colored wheels we had a more interesting shape that would look better if rotated? • What if the car could also move forward? y y x x Let us Add Some Animation (2) • Again, we need to decompose the problem and prioritize the motion: – Clearly, the wheels must be rotated around their axis – This must take place before moving them off the origin – The wheels should move in par with the rest of the car – Therefore, the translation of the car should happen after the composition of the entire vehicle y x Let us Add Some Animation (3) • To spin the wheels, we must apply a rotation to the “wheel” entity, before translation • Uniform scale and rotation can be safely interchanged • We rotate according to a user-defined angle θ(t) • So, the new Wheel is: Wheel = 퐑 퐒 A y y −휃(푡) 0.5,0.5 -θ(t) Note: Now the angle is negative, since this is a CW rotation x x Let us Add Some Animation (4) • Now to more efficiently apply the forward motion to the entire car, let’s: – First group all of its components – Then apply the translation to the “car” group Car 푀표푣푛퐶푎푟 = 퐓(푠(푡),0.0)Car y y 푠(푡) x x Let us Add Some Animation (5) • Congratulations! You have just made your first transformation hierarchy, i.e.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages81 Page
-
File Size-