Computer Graphics MSIT 3rd Miniterm, Nov-Dec 2004 Instructor: Kiran Varanasi kiran@students.iiit.

net Lecture Slides: Prof P.J. Narayanan IIIT - Hyderabad

Week 1 2D Transformations3D Transformations Graphics Pipeline

Coordinates A point is represented by a pair of realnumbers (x, y) There are two axes which serve as a reference for measuring distance of each point from the origin Conventionally the X and Y axes are perpendicular to each other. But need notbe. The coordinates give the length ofprojections of the point onto the two axes

but also y when there is a change in the origin/axes O x X P .Coordinate Geometry The coordinates of the point depend upon thelocation of the origin andYthe direction of the axes Coordinates change not only when the point movesto a new position.

it can be either the point or the reference (origin + axes) .Types of Transformation Translation Rotation Scaling Shearing In each case.

Translation of a point Translate the pointby (a. p' = p + t X P x P' x' a a b . b) Y (x + a. y +b) arethe y' coordinates of the b new point in the old y (same) coordinate system.

Y' New coordinates are (x + a. -b). y+ b).Translation of Axes Translate the axes by Y (-a. x b X' x' a p' = p + t . y + b) are the y' P coordinates of the same point in new coordinate system. y (x + a.

Transformations in reverse Translating the axes by (a.. is the same as rotating each point by thereverse angle -. . b) is the same as translating each point by (-a. -b) Similarly scaling the axes (zooming in) is the same as zooming out of each point Rotating the axes by an angle .

scale. and translate back. translate to origin.Coordinates under Scaling x' = s x. p' = s p X . s is the scale factor.y' = s y. Y Point undergoes shift whenscaling with respect to theorigin! To scale shapes in place .

Rotation of a point about Origin Y x= rcos a. y = r sin a y' x' =r cos (a+ q) = cos q.r sin a sin y y'=rsin (a+ q) = r sin a cos q+ r cos a sin X x q P' x' P a r cos a q q r .

Rotation: Matrix Notation Y R(q ) y' x' cos q -sin q x = y' sin q cos q y y X xx NewCoords = Matrix * OldCoord p' = M p q P' ' P a .

r cos a sin q + r sin a cos q ' y' x' q Xy y'P P a Y R(-q ) X x x' cos q sin q x = y' -sin q cos q y .Rotation of Coordinate Axes x' = r cos (a -q )= ' Y r cos a cos q + r sin a sin q = r sin (a -q ) = .

Opposite Rotation of Axes Y Y' y' q P x' = r cos a X xy a cos q -r sin a sin q y' = r cos a sin q + r sin a cos q R(q ) X' x' x x' cos q -sin q = y' sin q cos q y .

Equivalent Matrices X' Y' y' x' q P X Y x y a cos q -sin q cos qsin q x y x' y' = X Y q P' y' x' P a x y .

= R(p + t) Rotation followed by translation of a point p. = t + Rp They are not identical Rotation followed by translation followed by scaling p.Multiple Transformations Translation followed by rotation of a point p. = s(t + Rp) Cumbersome jumble of additions andmultiplications !! .

The last number w is sort of a scaling constant. Multiplying x. Multiple representations for each point.Homogeneous Coordinates Represent 2D coordinates using 3-vectors. and w by a non-zero k doesn t change the point. x x/w y y/w p = = 1 w . y.

Transformations: Uniform Form x y w 1 0 0 x/w y/w 1 cos q sin q 0 0 0 1 a b 1 s 0 0 0 0 1 .

Shearing Transformation Add partof X to Y and vice versa! Squares turn into parallelograms! May be applied in one direction only. 1 shx 0 shy 1 0 0 01 .

Transformations: Uniform Form x x/w cos q -sin q 0 y y/w R(q ) = sin q cos q p = = 0 1 w 0 01 1 shx 0 10a s00 Sh = shy1 0 T = 0 1b S = 0 s0 001 001 001 p' = M1 M2 M3 p .

3 Equivalent Viewpoints p' = M p Point p gets transformed by M and stays in the same coordinate frame as p' Coordinate frame changes by M-1 giving a stationary point p new coordinates as p' Coordinate frame changes by M giving astationary point p' new coordinates as p !! .

One fixed to the ground.Why do we want to transform a coordinate frame ?? Sometimes we want to think in terms of a reference frame which is natural to the problem For example. consider a wheel which isrolling on the ground There can be 3 coordinate frames. . the third fixed tothe spokes of the wheel and rotating. the second fixed to the wheel but not rotating.

Rolling Wheel q X Y X' Y' P l m X'' Y'' l P'' = (-k. q = w t m . 0) P' = (k cos q . m .k sin q ) L = R q . -k sin q ) P = (l + k cos q .

0) m We have to think of P in the X''-Y'' frame only. .m)P' = T(l.If P starts to move q X Y X' Y' P l m X'' Y'' l P' = R(180 -q ) P'' P = T(l.m)R(180 -q )P'' P'' = (-k .vt.

Old axes are forgotten! . Take Care: Once M1 is applied.Composite Operations P' = M1M2M3M4 P Can think of transforming the coordinateframe by M1 followed by M2. the definition of X and Y axes are modified. Point P is transformed by M4 followed by M3 and comes into the above coord frame.

rotated andmoved back.Example 1 Rotation by q about a point (a. Y -b) Object brought toorigin. b) T(a. X a b . b) R(q ) T(-a.

b) T(a. XYabX Y a b . rotated about new origin and moved to(-a. b).Example 1b Rotation by q about a point (a. -b) Coordinate frame moved to (a. -b) of the newframe. b) R(q ) T(-a.

Example 1c XYabX Y a b .

Example 2 In place scaling and rotation : T(v) R(q ) S(sx.sy) T(v) .

Rotations: Another View Y cos q -sin q Y sin q cos q X are unit vectors to which X and Y axes move q X cos q sin q cos q -sin q 0 -sin q cos q R(q ) = sin q cos q 0 are unit vectors which 0 01 move to X and Y axes .

Making Rotation Matrices Columns give the vectors to which the axes will move after rotation. Rows give the vectors (beforerotation) that will sit on the axesafter rotation. . This is alternate way to arrive at the rotation matrix from what is known.

They form the rows! (a.Example 3 Given a triangle (0. how to align the side with the Yaxis? [a' b']T should sit on Y axis. (a. b) (c. d). and (c. 0). Orthogonaldirection is [-b' a']T. d) 0 0 a' b' 0 1 -b'a' 0 . b).

transforming the coordinate frame.Summary Rotations. (Doing it in reverse) Understand well. Very important in 3D ! . shearingrepresented using a 3x3 matrix. Transforming a point Vs. scaling. Composite transformations obtained bymultiplying matrices together. translation.