Unformatted text preview:

Today Transformations Transformations are functions applied to points in space p f p Provide a mechanism for manipulating geometric models Transformations are essential pieces of graphics systems OpenGL and PostScript for instance use them extensively Why Do We Need Transformations Makes modeling more convenient for example often easier to generate models around origin gluSphere draws a sphere of radius r about the origin can then move them to final position with transformations Model viewing process via transformations projecting 3 D to 2 D will be done this way Animation transformations as a function of time creates motion 1 Linear Algebra in 30 Seconds We represent points as vectors p x y z vectors add according to parallelogram rule a linear combination of two vectors is p q p p q q set of vectors is linearly independent if none is a linear combination of the others a basis for a space is a linearly independent set of vectors whose linear combinations include all vectors in the space 1 0 standard basis for 2 D plane e1 e 2 0 1 but there are infinitely many possible bases Linear Affine Transformations We ll be specifically interested in linear transformations f p q f p f q transformation of shape determined by effect on vertices a crucial property that allows for efficient implementation And the related class of affine transformations f p q p f p f q p preserves affine combinations e g they map lines to lines another view a linear transformation a translation this is a more general class of functions 2 Translation Offset all points by constant amount x x x y y y Written as more concise vector equation x x x y y y or p p d Scaling Scale all points by constant amount x sx y ty And written as a vector equation x s 0 x y 0 t y or p Sp Squash stretch along x y axes 3 Rotation of Points About Origin x y First write points in polar coordinates x cos y sin x cos y sin x y And solve for the new positions x x cos y sin y x sin y cos Can write this as a vector equation as well x cos sin x y sin cos y or p Rp The Three Fundamental Transformations Translation Scaling Rotation p p d p Sp p Rp We can represent any affine transformation as a sequence of these 3 Translation is only one not represented as matrix multiplication because it s not a linear transformation wouldn t it be nice if we could come up with a matrix formulation 4 Homogeneous Coordinates Let s add an extra dimension to our vectors x a x a position y direction b y 1 b 0 this added dimension is the homogeneous coordinate in general we ll have coordinates x y w the resulting 3 D space is a projective space To convert back divide by w and drop the last coordinate all vectors x y w represent the same point if w 0 it represents a point at infinity So what does this do to our transformation equations Transforms in Homogeneous Coordinates Scaling x s 0 0 x y 0 t 0 y 1 0 0 1 1 or p Sp Rotation x cos sin y sin cos 1 0 0 or p Rp 0 x 0 y 1 1 Translation x 1 0 x x y 0 1 y y 1 0 0 1 1 or p Tp 5 Fundamental Homogeneous Transforms Translation p Tp Scaling Rotation p Sp p Rp Now we can write all three transforms as matrix multiplications In general we ll be using some sequence of transformations M1 M 2 L Mn v L Composing Transformations Matrix multiplication is associative but not commutative can collapse sequences of transformations into single matrix but must not reorder any of them A B C D v ABCDv ABCD v Can choose to multiply pairs at either end add new matrices at beginning pre multiply ABCD A B CD add new matrices at the end post multiply ABCD AB C D 6 Exercise Composing Transformations original R rotate 60 S scale 1 3 0 5 T trans 0 2 0 2 What order of R S T will produce this figure a TRSv b RSTv c TSRv d RTSv Exercise Composing Transformations a TRSv b RSTv c TSRv d RTSv 7 Writing Transformations in OpenGL OpenGL maintains a current transformation matrix M issue commands to post multiply matrices into M so commands are listed in reverse order of application glLoadIdentity set M to identity matrix M I glTranslatef x y z translation M MT glRotatef x y z rotate about given axis M MR glScalef r s t scale by given factors M MS Example to rotate about an arbitrary point p x y glTranslatef x y 0 3 move p back glRotatef theta 0 0 1 2 rotate around z axis glTranslatef x y 0 1 move p to origin DrawSomething An Alternative View of Transformations Can be thought of as mapping points to new locations this is the basis of the presentation from last time Can also be thought of as a change of coordinate system vectors as specified as a linear combination of basis vectors for instance in 2 D p p1e1 p2 e 2 transformed vector is similar combination of transformed basis p p1e 1 p2 e 2 e 2 e2 e 1 This is frequently a useful approach to understanding transformations e1 8 Matrix Stacks Instead of a current matrix we have a matrix stack current matrix is just the top of the stack Stack operations PUSH duplicate matrix on top POP remove matrix on top glPushMatrix glPopMatrix When nesting transformations PUSH when beginning a scope multiply transformation into current matrix draw some stuff POP when done A Push A A Mult B AB A Pop A Implementing Transformation Scopes Be careful about transformation order usually want to scale before rotation usually want to rotate before translation Simple 2 D Case glPushMatrix glTranslatef dx dy Further translation glTranslatef cx cy Back to center glRotatef angle 0 0 1 glScalef s t glTranslatef cx cy Center to origin draw some stuff glPopMatrix 9 A Word of Caution on Notation We ve consistently written points as column vectors virtually everyone does this x a b x y c d y typically represent matrices in row major order a b c d Some in graphics have traditionally used row vectors convert by transposing everything x y x ABv ABv T vT BT AT note that order is reversed as well typically represent matrices in column major order a c b d OpenGL actually does it this way but you ll probably never notice a c y b d 10


View Full Document

U of I CS 418 - Transforms

Loading Unlocking...
Login

Join to view Transforms and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Transforms and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?