GEOMETRIC OBJECTS AND TRANSFORMATIONS Introduction In computer graphics many applications need to alter or manipulate a picture, for example, by changing its size, position or orientation. This can be done by applying a geometric transformation to the coordinate points defining the picture. Geometric Objects Points: fundamental geometric object is a point. In a three-dimensional geometric system, a point is a location in space. The only property that a point possesses is that point’s location; a mathematical point has neither a size nor a shape. Vectors In computer graphics, we often connect points with directed line segments, A directed line segment has both magnitude—its length—and direction—its orientation—and thus is a vector. Coordinates free geometry Points exist in space regardless of any reference or coordinate system. Thus, we do not need a coordinate system to specify a point or a vector. Coordinates free geometry con.. Definition: Geometry The branch of mathematics concerned with the properties of and relationships between points, lines, planes, and figures. 2D Transformations What is transformations? The geometrical changes of an object from a current state to modified state. A rule for moving every point in a plane figure to a new location. Affine transformation In geometry, an affine transformation is a transformation which preserves straight lines (all points lying on a line initially still lie on a line after transformation) and ratios of distances between points lying on a straight line. It does not necessarily preserve angles or lengths, but does have the property that sets of parallel lines will remain parallel to each other after an affine transformation. Affine transformation con.. Examples of affine transformations include translation, geometric contraction, expansion, reflection, rotation An affine transformation is equivalent to a linear transformation followed by a translation Types of Transformation Translation Rotation Scaling Translation A translation moves all points in an object along the same straight-line path to new positions. The path is represented by a vector, called the translation or shift vector. ? We can write the components: p'x = px + tx ty=4 p'y = py + ty or in matrix form: P' = P + T tx x’ x y’ = y + ty (2, 2) tx= 6 Translation con… In a translation a figure slides up or down, or left or right. No change in shape or size. The location changes. In graphing translation, all x and y coordinates of a translated figure change by adding or subtracting. Rotation A rotation repositions all points in an object along a circular path in the plane centered at the pivot point. First, we’ll assume the pivot is at the origin. P’ P Rotation • Review Trigonometry => cos = x/r , sin = y/r • x = r. cos , y = r.sin P’(x’, y’) => cos (+ ) = x’/r •x’ = r. cos (+ ) •x’ = r.coscos -r.sinsin •x’ = x.cos – y.sin =>sin (+ ) = y’/r y’ = r. sin (+ ) •y’ = r.cossin + r.sincos •y’ = x.sin + y.cos r y’ x’ P(x,y) r y x Identity of Trigonometry Rotation • We can write the components: p'x = px cos – py sin p'y = px sin + py cos P’(x’, y’) • or in matrix form: P' = R • P • Rotation matrix cos R sin sin cos y’ x’ P(x,y) r x y Rotation Example Find the transformed point, P’, caused by rotating P= (5, 1) about the origin through an angle of 90. cos sin sin x x cos y sin cos y x sin y cos 5 cos 90 1 sin 90 5 sin 90 1 cos 90 5 0 11 5 1 1 0 1 5 Scaling • Scaling changes the size of an object and involves two scale factors, Sx and Sy for the xand y- coordinates respectively. • Scales are about the origin. • We can write the components: p'x = sx • px p'y = sy • py or in matrix form: P' = S • P Scale matrix as: sx S 0 0 s y P’ P Scaling • If the scale factors are in between 0 and 1 the points will be moved closer to the origin the object will be smaller. • Example : •P(2, 5), Sx = 0.5, Sy = 0.5 •Find P’ ? P(2, 5) P’ Scaling • If the scale factors are in between 0 and 1 the points will be moved closer to the origin the object will be smaller. • Example : •P(2, 5), Sx = 0.5, Sy = 0.5 •Find P’ ? •If the scale factors are larger than 1 the points will be moved away from the origin the object will be larger. • Example : •P(2, 5), Sx = 2, Sy = 2 •Find P’ ? P’ P(2, 5) P’ Scaling • If the scale factors are the same, Sx = Sy uniform scaling • Only change in size (as previous example) •If Sx Sy differential scaling. •Change in size and shape •Example : square rectangle •P(1, 3), Sx = 2, Sy = 5 , P’ ? P’ P(1, 2) Matrix Math Why do we use matrix? More convenient organization of data. More efficient processing Enable the combination of various concatenations Matrix addition and subtraction a b c d = a c b d Matrix Math Type of matrix a b Row-vector a b Column-vector Matrix Math We’ll use the column-vector representation for a point. Which implies that we use pre-multiplication of the transformation – it appears before the point to be transformed in the equation. A B x Ax By C D y Cx Dy What if we needed to switch to the other convention? Matrix Representation of Transformations Point in column-vector: x y 1 Our point now has three coordinates. So our matrix is needs to be 3x3. Translation x 1 0 t x x y 0 1 t y y 1 0 0 1 1 Matrix Representation Rotation x cos y sin 1 0 sin cos 0 0 x 0 y 1 1 Scaling x s x y 0 z 0 0 sy 0 0 x 0 y Sz z Composite Transformation We can represent any sequence of transformations as a single matrix. No special cases when transforming a point – matrix • vector. Composite transformations – matrix • matrix. Composite transformations: Rotate about an arbitrary point – translate, rotate, translate Scale about an arbitrary point – translate, scale, translate Order of operations Example: 1. 2. Translate Rotate 1. 2. Rotate Translate Homogenous Coordinates y y w x x Let’s move our problem into 3D. Let point (x, y) in 2D be represented by point (x, y, 1) in the new space. Scaling our new point by any value a puts us somewhere along a particular line: (ax, ay, a). A point in 2D can be represented in many ways in the new space. (2, 4) ---------- (8, 16, 4) or (6, 12, 3) or (2, 4, 1) or etc. Homogenous Coordinates • We can always map back to the original 2D point by dividing by the last coordinate • (15, 6, 3) --- (5, 2). • (60, 40, 10) - ?. • Why do we use 1 for the last coordinate? • The fact that all the points along each line can be mapped back to the same point in 2D gives this coordinate system its name – homogeneous coordinates. Frames In OpenGl OpenGL is based on a pipeline model, the first part of which is a sequence of operations on vertices, many of which are geometric. We can characterize such operations by a sequence of transformations or as a sequence of changes of frames for the objects specified by an application program. OpenGl Pipeline 1.Object (or model) coordinates 2. World coordinates 3. Eye (or camera) coordinates 4. Clip coordinates 5. Normalized device coordinates 6. Window (or screen) coordinates Data Structure for object representation