1.74k likes | 1.92k Views
Modeling Transformations. CSE 409. Md. Tanvir Al Amin* Lecturer, Dept. of CSE, BUET tanviralamin@gmail.com. *Special Thanks to Tanvir Parvez , Fredo Durand, James O Brien, Tomas Lozano-Perez, Jovan Popovic. Modeling Transformation - Class 1. Transformation Background.
E N D
Modeling Transformations CSE 409 Md. Tanvir Al Amin* Lecturer, Dept. of CSE, BUET tanviralamin@gmail.com *Special Thanks to TanvirParvez, Fredo Durand, James O Brien, Tomas Lozano-Perez, Jovan Popovic
Transformation Background What is Transformation ?
What is a Transformation • Transformation: • An operation that changes one configuration into another • For images, shapes, etc. • A geometric transformation maps positions that define the object to other positions • Linear transformation means the transformation is defined by a linear function... which is what matrices are good for.
What is a Transformation? • A function that maps points x to points x': Applications: animation, deformation, viewing, projection, real-time shadows, …
Simple Transformations • Can be combined • Are these operations invertible? Yes, except scale = 0
Rigid-Body / Euclidean Transforms • Preserves distances • Preserves angles Rigid / Euclidean Identity Translation Rotation
Similitudes / Similarity Transforms • Preserves angles Similitudes Rigid / Euclidean Identity Translation Isotropic Scaling Rotation
Linear Transformations Similitudes Linear Rigid / Euclidean Scaling Identity Translation Isotropic Scaling Reflection Rotation Shear
Linear Transformations • L(p + q) = L(p) + L(q) • L(ap) = a L(p) Similitudes Linear Rigid / Euclidean Scaling Identity Translation Isotropic Scaling Reflection Rotation Shear Translation is not linear because ap+t ≠ a(p+t)
Affine Transformations • preserves parallel lines Affine Similitudes Linear Rigid / Euclidean Scaling Identity Translation Isotropic Scaling Reflection Rotation Shear
Projective Transformations • preserves lines Projective Affine Similitudes Linear Rigid / Euclidean Scaling Identity Translation Isotropic Scaling Reflection Rotation Shear 6.837 Fall 06 – Durand Perspective
Groups • Properties of a group (element, operation): • There exists a neutral element • There exists an inverse for each member • The elements are "closed under composition" • The composition operation is associative • Example: integers under addition 0 is the neutral element -x is the inverse of x x+y is an integer (x+y)+z=x+(y+z)
Groups and Transformations • Properties of a group: • There exists an identity mapping • There exists an inverse mapping for each function • The functions are "closed under composition" • The composition operation is associative • These properties might seem trivial at first glance, but they are actually very important, because when these conditions are shown for any class of functions and their two-argument composition operation, then they form an algebraic group. • One of the consequences is that any series of translations can be composed to a single translation. • Another consequence is that the inverse is unique.
How are Transforms Represented? x' = ax + by + c y' = dx + ey + f x y c f x' y' a b d e + = p' = M p + t
Translation in homogenous coordinates x' = ax + by + c y' = dx + ey + f Affine formulation Homogeneous formulation c f 1 x y 1 x' y‘ 1 a b d e 0 0 = x y c f x' y' a b d e + = p' = M p + t p' = M p
Homogeneous Co-ordinates • Translation, scaling and rotation are expressed (non-homogeneously) as: • translation: P = P + T • Scale: P = S · P • Rotate: P = R · P • Composition is difficult to express, since translation not expressed as a matrix multiplication • Homogeneous coordinates allow all three to be expressed homogeneously, using multiplication by 3 ´ 3 matrices • W is 1 for affine transformations in graphics
Homogeneous Coordinates • Add an extra dimension • in 2D, we use 3 x 3 matrices • In 3D, we use 4 x 4 matrices • Each point has an extra value, w a e i m b f j n c g k o d h l p x y z w x' y' z' w' = p' = M p
Homogeneous Coordinates • Most of the time w = 1, and we can ignore it • If we multiply a homogeneous coordinate by an affine matrix, w is unchanged a e i 0 b f j 0 c g k 0 d h l 1 x y z 1 x' y' z' 1 =
w Ph(x,y,w) w=1 P2d(x,y,1) y x Homogeneous Co-ordinates • P2d is a projection of Ph onto the w = 1 plane • So an infinite number of points correspond to : they constitute the whole line (tx, ty, tw)
Mechanics of Rigid Transformations Translate Rotate Scale
x’ = x + dx y’ = y + dy Translation – 2D
Scaling – 2D • Types of Scaling: • Differential ( sx != sy ) • Uniform ( sx = sy )
Original scale Y axis scale all axes Scaling – 3D
rotated original Rotation – 2D
Rotation – 3D For 3D-Rotation 2 parameters are needed • Angle of rotation • Axis of rotation Rotation about z-axis:
Rotation about Y-axis & X-axis About y-axis About x-axis
Rotation about Z axis ZRotate(θ) y p' • About z axis θ p x z cos θ sin θ 0 0 -sin θ cos θ 0 0 0 0 1 0 0 0 0 1 x y z 1 x' y' z' 1 =
Rotation • How to rotate around (kx, ky, kz), a unit vector on an arbitrary axis … • Example : Rotate 30 degree around vector 2i+1j+3k • For now, solution is Rodrigues Formula • Can it be found from some rotation around x axis, then some rotation around y axis, then z axis ? • We will munch it later ….
Rotation Rotate(k, θ) y θ • About (kx, ky, kz), a unit vector on an arbitrary axis(Rodrigues Formula) k x z kxkx(1-c)+c kykx(1-c)+kzs kzkx(1-c)-kys 0 kykx(1-c)-kzs kyky(1-c)+c kzky(1-c)+kxs 0 kxkz(1-c)+kys kykz(1-c)-kxs kzkz(1-c)+c 0 0 0 0 1 x y z 1 x' y' z' 1 = where c = cos θ & s = sin θ We will return to this case of arbitrary rotation later …
Non Rigid Transforms • We just studied Translation, Scale, Rotate • All these are Rigid Transformations • Is Shear rigid ? • No • Shear is Linear Transform • However, Translate, Scale, Rotate, Shear, Reflect all are member of general class “Affine Transformation”
y x z Shear along Z-axis
0 0 0 0 0 0 1 1 1 How are transforms combined? Scale then Translate (5,3) (2,2) Scale(2,2) Translate(3,1) (1,1) (3,1) (0,0) (0,0) Use matrix multiplication: p' = T ( S p ) = TS p 0 1 0 2 0 2 1 0 3 1 2 0 0 0 2 0 3 1 TS = = Caution: matrix multiplication is NOT commutative!
Non-commutative Composition Scale then Translate: p' = T ( S p ) = TS p (5,3) (2,2) Scale(2,2) Translate(3,1) (1,1) (3,1) (0,0) (0,0) Translate then Scale: p' = S ( T p ) = ST p (8,4) (4,2) Translate(3,1) Scale(2,2) (6,2) (1,1) (3,1) (0,0)
0 0 0 0 0 0 1 1 1 Non-commutative Composition Scale then Translate: p' = T ( S p ) = TS p 0 1 0 0 2 0 0 2 0 1 0 0 3 1 1 2 0 0 0 0 1 2 0 0 3 1 1 TS = = Translate then Scale: p' = S ( T p ) = ST p 0 2 0 1 0 2 2 0 0 0 1 0 3 1 2 0 6 2 ST = =
Combining Translations, Rotations • Order matters!! TR is not the same as RT (demo) • General form for rigid body transforms • We show rotation first, then translation (commonly used to position objects) on next slide. Slide after that works it out the other way
Classification of Transformations Again • Rigid-body Transformation • Preserves parallelism of lines • Preserves angle and length • e.g. any sequence of R() and T(dx,dy) • Affine Transformation • Preserves parallelism of lines • Doesn’t preserve angle and length • e.g. any sequence of R(), S(sx,sy) and T(dx,dy)