Document Sample

5. Geometric Transformations Modelling Transforms Viewing + Projection 1 Example 1 Object parts defined in a local co-ordinate system: etc... Larger objects are then “assembled” by duplicating and transforming each of the constituent parts: Example 2 4 Example 3 5 steps of a “rotating cube” animation At each frame of the animation, the object is transformed, in this case by a rotation. It could also be transformed by changing its size (scaling), or its shape (deformation), or its location (translation). Further animation effects can be achieved by not changing the object, but the way it is viewed zooming and panning the viewing window 2D Object Transformations A 2D object transformation alters each point P into P = {Px, Py} a new point Q using certain rules It therefore alters the co-ordinates of P {Px, Py} ??? into new values which specify point Q {Qx,Qy} DO SOMETHING ??? This can be expressed using some function T, that Q = {Qx, Qy} maps co-ordinate pairs into new co-ordinate pairs: T ({Px,Py}) = {Qx,Qy} May simply be denoted as T(P) = Q P = {2, 2} e.g: P is the point {2, 2}, T is a transform that scales by a factor of 2. Then T(P) = T({2, 2}) = {4,4} Scale by 2 Q = {4, 4} Transformations Whole collections of points may be transformed by the same transformation T, e.g. lines or circles P1 {0, 2} P2 {2, 2} The image of a line, L, under T, is the set of all images of the individual points of L. P0 {0, 0} P3 {2, 0} For most mappings of interest, this image is still a connected curve of some shape For some mappings, the result of transforming a line may no longer be a line Q1 {0, 4} Q2 {4, 4} Affine Transformations, however, do preserve lines, and are the most commonly- used transformations in computer graphics Q3 {4, 0} Q0 {0, 0} Useful Properties of Affine Transformations Preservation of lines: Preservation of parallelism Preservation of proportional distances Why are they useful? They preserve lines, so the image of a straight line is another straight line. This vastly simplifies drawing transformed line segments. We need only compute the image of the two endpoints of the original line and then draw a straight line between them Preservation of co-linearity guarantees that polygons will transform into polygons Preservation of parallelism guarantees that parallelograms will transform into parallelograms Preservation of proportional distances means that mid-points of lines remain mid-points Elementary Transformations Affine transformations are usually combinations of four elementary transformations: 1: Translation 2: Scaling 3: Rotation 4: Shearing Translation A translation moves an object into a different position in a scene tx This is achieved by adding an offset/translation vector t ty In Vector notation: Qx Px t x Q P t y y y t Translate by t Original points Transformed points Scaling A scaling changes the size of an object with two scale factors, Sx and Sy (if Sx != Sy, then we have a non-uniform scale) Qx Px S x Q P S y y y Sx, Sy Scale by Sx, Sy Original points Transformed points Rotation Using the trigonometric relations, a point rotated by an angle q about the origin is given by the following equations: So Qx Px cos θ Py sin θ Q y Px sin θ Py cos θ Qx Px cosq Py sin q Q P sin q P cosq y x y q Rotate by q Original points Transformed points Rotation - derivation Q X Rcos(q ) [1] Q y Rsin(q ) [2] PX R cos ( ) [3] Py R sin ( ) [4] Q cos (q ) cos (q) cos () sin (q) sin () q sin (q ) sin (q) cos () cos (q) sin () PY P [1] Qx Rcos (q ) cos ( ) Rsin (q ) sin ( ) PX Substituting from [3] and [4]… R Qx Pxcos (q ) Py sin (q ) Similarly from [2]… Qy Pycos (q ) Px sin (q ) Background info Shearing A shearing affects an object in a particular direction (in 2D, it’s either in the x or in the y direction) A shear in the x direction would be as follows: Qx Px hPy Q Py y The quantity h specifies what fraction of the y-coordinate should be added to the x-coordinate, and may be positive or negative More generally: a simultaneous shear in both the x and y directions would be Qx Px hPy Q P gP y y x Shearing g =0, h=0.5 Shear by {g,h} Original points Transformed points g=0.5, h=0.5 Shear by {g,h} Original points Transformed points 18 Matrix Representation All affine transformations in 2D can be generically described in terms of a generic equation as follows: Qx a b Px t x Q P t i.e. y c d y y Q MP t Transformations Summary 1: Translation T Qx 1 0 Px t x Q y 0 1 Py t y T 2: Scaling Qx S x 0 Px 0 Q 0 S y Py 0 y 3: Rotation T Qx cosθ sin θ Px 0 Q y sin θ cosθ Py 0 T 4: Shearing Qx 1 h Px 0 Q y g 1 Py 0 20 Matrix Representation All affine transformations in 2D can be generically described in terms of a generic equation as follows: Qx a b Px t x Q P t i.e. y c d y y Q MP t Problem An affine transformation is composed of a linear combination followed by a translation Unfortunately, the translation portion is not a matrix multiplication but must instead be added as an extra term, or vector – this is inconvenient Homogeneous Coordinates The “trick” we use is to add an additional component 1 to both P and Q, and also a third row and column to M, consisting of zeros and a 1 i.e. Qx a b t x Px Q c d t P y y y 1 0 0 1 1 Translation by {tx, ty} 1 0 t x Rotate by q: cos q sin q 0 M 0 1 t y M sin q cos q 0 0 0 1 0 0 1 Scale by Sx, Sy S x 0 0 Shear by g, h: 1 h 0 M 0 Sy 0 M g 1 0 0 1 0 0 1 0 Multiple Transformations It is rare that we want to perform just one elementary transformation. Usually an application requires that we build a complex transformation out of several elementary ones e.g. translate an object, rotate it, and scale it, all in one move These individual transformations combine into one overall transformation This is called the composition of transformations. The composition of two or more affine transformations is also an affine transformation Rotation and Scaling The simple versions of rotation and scaling have been based around the origin. This means that when we rotate or scale, the object will also move, with respect to the origin Not only is the object rotated, but it also moves around the origin Pivotal points Often we wish to rotate or scale with respect to some pivotal point, not the origin Most significantly, we often wish to rotate or scale an object about its centre, or midpoint In this way, the object’s location does not change To do this, we relate the rotation or scaling about the pivotal point V, to an elementary rotation or scaling about the origin We first translate all points so that V coincides with the origin We then rotate or about the origin then all points are translated back, so that V is restored to its original location {x1,y1} {0,0} To rotate the square by angle: q about the point {x1, y1} • Translate all points through {-x1,-y1} • Rotate all points about the origin by q • Translate all points back through {x1y2} Rotation about a pivot point 1 0 x1 cosq sin q 0 1 0 x1 0 1 y1 sin q cosq 0 0 1 y1 0 0 1 0 0 1 0 0 1 cosq sin q x1 (1 cosq ) y1 sin q sin q cosq y1 (1 cosq ) x1 sin q 0 0 1 28 Why composition? One of the main reasons for composing transformations is computational efficiency Suppose you want to apply two affine transformations to the N vertices of a polygonal object a b t x a1 b1t x1 a2 b2 tx2 c d t c d1 t y1 c2 d2 t y2 It requires 18 multiplications* to compose the y 1 transformations, and 6 multiplications to apply a 0 0 1 0 0 1 0 0 1 transformation to a point Qx a b t x Px So, “compose-then-apply” requires 6N+18 and Q y c d t y Py multiplications 1 0 0 1 1 12N multiplications are required if each P ' x a1 b1 t x1 Px transformation is applied separately (and possibly P' c d1 t y1 Py y 1 1 0 0 1 1 For models with any significant number of vertices Qx a 2 b2 t x 2 P' x Q c t y 2 P' y {which will be most}, 6N+18 is much less than 12N y 2 d2 1 0 0 1 1 e.g. if N=10000, 6N+18 = 60018, 12N = 12000 i.e. about half the effort * : clever graphics systems will take into account that the bottom row doesn’t need to be multiplied out. But even in this case Compositions takes about half the time (9N+27 vs. 18N) Local vs. Global Co-ordinates In practice we find that it is cumbersome in most applications to have to recalculate the individual points that make up an object It is more common to define the object with reference to some local co-ordinate origin (or reference point) and axis. We then specify through a transformation matrix how this reference frame relates to the Global reference frame. 30 Modelling Scenes Modelling complex scenes made up many objects is a two step process of modelling individual objects and then placing these in the scene (using transforms) 31 Scene Graphs TRINITY Individual object geometries are first modelled. These are then linked using positional/orientational relationships (transforms) 32 A Scene Graph Body Hood Trunk Front Bumper Rear Bumper Left Door Left Door Glass Right Door Right Door Glass Left Front Wheel Right Front Wheel Left Rear Wheel Right Rear Wheel There can be multiple levels of transforms e.g. the “door glass” is linked to the “door” which is linked to the “body” 33 + + Usually we model individual objects based on a local coordinate system This of course shouldn’t = mean all objects need to share the same transformations 34 + + + + transform transform transform Obviously we want something more versatile = 35 Current Transformation Matrix One way to do this is by using a single object to represent the CURRENT TRANSFORMATION MATRIX {CTM} All transformation functions affect only the CTM When a draw procedure is finally called it draws based on the CTM The CTM might be seen as representing the “current coordinate frame” for drawing 36 Coordinate Transforms x v v’ {1,1} u u’ Object defined in Local Coordinate System y Object after transformation in Global Coordinate System 37 Identity x x v v’ {1,1} {1,1} u y u’ y 1 0 0 Q 0 1 0 P 0 0 1 38 Translation x v 1 0 tx x v’ Q 0 1 ty P {1,1} {1+tx,1+ty} 0 0 1 u y u’ y 1 0 tx 0 tx 1 0 tx 1 1 tx 1 0 tx 0 tx 0 1 ty 0 ty 0 1 ty 0 ty 0 1 ty 1 1 ty 0 0 1 1 1 0 0 1 1 1 0 0 1 1 1 origin v u {0, 1, 1} 39 Rotation x x v {1,1} u y y cosq sin q 0 cosq sin q Q sin q cosq 0 P v sin q u cosq 0 1 1 1 0 40 Scaling v x v x {sx*1,sy*1} {1,1} u y y u sx 0 0 0 sx 0 Q0 sy 0 P O 0 v0 u sy 0 0 1 1 1 1 41 Composite Transformations x x x1 (1 cosq ) y1 sin q u y (1 cosq ) y sin q O= 1 1 1 {1,1} cosq x1 (1 cosq ) y1 sin q u y sin q y (1 cosq ) y sin q y v= 1 1 1 cosq sin q x1 (1 cosq ) y1 sin q M sin q cosq y1 (1 cosq ) x1 sin q sin q x1 (1 cosq ) y1 sin q u= cosq y (1 cosq ) y sin q 0 0 1 1 1 1 42 Transforming Images Simply juggling array positions can achieve simple 90 degree rotations for (int x=0; x<width; x++) for (int y=0; y<height; y++) { set(x, y, get (y, x) ); } 43 Transformations on Pixels Alternatively we could apply a rotation transfrom for each pixel. This works in some cases but there are problems when the angle of rotation is not a multiple of 90 degrees There often isn’t a 1-to-1 correspondence between number of original and transformed pixels. In Addition, rounding to the nearest discrete block can create errors that lead to gaps in the transformed image. 44 45 Transforming Images The solution is to look at it from the ROTATE IMAGE by q : point of view of rasterizing a transformed polygon which is Find rotated “frame” of the image textured with the original image For each scanline (y) Using interpolation find startx and start_x end_x endx For every pixel x (between startx and endx) Find {u,v} corresponding to {x, y} This is done by rotating {x,y} by -q set ( {x,y}, get {u,v}) This ensures that every pixel in the rotated image is dealt with and no gaps are left N.B. In most cases there will be some distortion in the image. So rotating images by arbitrary angles can cause degradation. 46 3D Object Transformations scaling translation rotation 47 Scale all vectors are scaled from the origin: Original scale all axes scale Y axis offset from origin distance from origin also scales 48 Scale x s x x s x 0 0 x y s y 0 sy 0 y q Sp y z sz z 0 0 sz z Or in 3D homogeneous coordinates x s x x s x 0 0 0 x y s y 0 sy 0 0 y y z sz z 0 0 sz 0 z w w 0 0 0 1 w 49 Rotation Rotations are anti-clockwise about the origin: rotation of 45o about the Z axis offset from origin rotation 50 Rotation 2D rotation of q about origin: x cosq sin q x y sin q cosq y 3D homogeneous rotations: 1 0 0 0 cosq 0 sinq 0 cosq sinq 0 0 0 cosq sinq 0 0 sinq 0 0 1 0 0 R cosq Rx Ry z 0 1 0 0 sinq cosq 0 sinq 0 cosq 0 0 0 0 0 1 0 0 0 1 0 0 0 1 51 Translation Translation only applies to points, we never translate vectors. Remember: points have homogeneous co-ordinate w = 1 x x a x x a 1 0 0 a x y y b 0 1 0 b y y y b z z c z z c 0 0 1 c z 1 1 0 0 0 1 1 translate along y 52

DOCUMENT INFO

Shared By:

Categories:

Tags:
shading, image manipulation: Illumination models, shading models for polygons, shadows, transparency. What is an image? Filtering, image processing, geometric transformation of images, Three dimensional graphics concept, Matrix representation of 3-D Transformations, Composition of 3-D transformation.

Stats:

views: | 29 |

posted: | 1/26/2011 |

language: | English |

pages: | 49 |

Description:
computer graphics and its applicationa

SHARED BY

About
if any file u wil find copyright contact me it will be remove in 3 to 4 buisnees days.
add me on sanjaydudeja007@gmail.com
or visit
http://www.ohotech.com/

OTHER DOCS BY SanjuDudeja

How are you planning on using Docstoc?
BUSINESS
PERSONAL

By registering with docstoc.com you agree to our
privacy policy and
terms of service, and to receive content and offer notifications.

Docstoc is the premier online destination to start and grow small businesses. It hosts the best quality and widest selection of professional documents (over 20 million) and resources including expert videos, articles and productivity tools to make every small business better.

Search or Browse for any specific document or resource you need for your business. Or explore our curated resources for Starting a Business, Growing a Business or for Professional Development.

Feel free to Contact Us with any questions you might have.