Introduction to Computer GraphicsFarhana Bandukwala, PhDLecture 4: 2D Geometry and TransformationsOutline• Assignment 1 clarifications• Coordinate System• Geometric objects and operations(Angel,chapter 4)• Homogeneous coordinates • TransformationsAssignment 1• Title of window should include name• Required part: using OpenGL drawing primitives• Extra credit: Choose one of following1. Edge intersection & fill algorithm2. Midpoint line & flood fill– Assume 4 vertices in polygon, and 2 intersections per scan linescanConvertPoly(int width,int height, int verts[4][2]){unsigned char *img; // allocate to width & heightinitialize img[]=0for each rowtest each edge and find 2 x-values of intersection from first x value to second xvalueassign white (255) to pixel pointglRasterPos();glDrawPixels();glFlush();}Coordinate System• Image maps to screen coordinate system(glRasterPos())• Differs from world coordinate system• 2D transformations & clipping to switch between themyxy’x’Geometric Objects• Points: location in two dimensional space• Vectors: direction and magnitude• Scalars: real (and complex) numbers which act on points and vectors according to a set of rulesQAB = AC = (.5)BSimple operationsBDEVector addition:B+D = EAB = -AInverse vector:AQPoint-vector addition:P = Q + APPoint-Point subtraction:A= P-QVector magnitude:|A|2= A.A (distance from P to Q)ADot product (also measures distance):<A,C> = |A||C|cosTCTorthogonal vectors if <A,C>=0Transformations: translationAQTranslate 1 point:P = Q + APP = x’y’Q = xyA = dxdyDefine column vectors:x’y’= x’y’+ dxdyVector notation for translation:Translate objectconsisting ofmultiple pointsTransformations: scale (shear)BShear 1 vector:B= S .AShear objectAB = x’y’A = xyDefine column vectors:x’y’= sx00 sy. xyMatrix notation for scale:Scale equation:x’ = sxx , y’ = syyTransformations: rotationAQRotate vector about Q:B= R.AB = x’y’A = xyDefine column vectors:x’y’= cosT -sinTsinT cosT. xyVector notation for translation:Rotate object about originBTRotation by T about origin:x’ = xcosT - ysinT ,y’ = xsinT + ycosTHomogeneous coordinates• Goal: translation expressed in same form as rotation & scale (matrix multiplication)• Solution: represent points as homogeneous coordinates (three-tuples)• P=(x,y,W) is the same as Q=(x’,y’,W’) if differ by a multiple (2,3,6) & (4,6,12)• If W is non-zero (x/W,y/W,1) is same point as (x,y,W)• When W is zero -> point at infinityx’y’1= 1 0 dx0 1 dy0 0 1. xy1Matrix notation for translationusing homogeneous coordinatesHomogeneous coordinates (contd.)x’y’1= sx0 00 sy00 0 1. xy1Matrix notation for scalex’y’1= cosT -sinT 0sinT cosT 00 0 1. xy1Matrix notation for rotationRigid body transformation• Concatenation of rotation and translation matrices• Preserves angles and lengthsr11r12dxr21r22dy0 0 1General formRotation about arbitrary point (dx,dy)1 0 dx0 1 dy0 0 1. 1 0 -dx0 1 -dy0 0 1cosT –sinT 0sinT cosT 00 0 1. cosT -sinT dx(1-cosT)+dysinTsinT cosT dy(1-cosT)-dxsinT0 0 1=Affine Transformation• Product of arbitrary rotation,translation,scaling• Preserves parallel lines• Does NOT preserve angles and lengthssquare Rotation by 45 degrees Non-uniform
View Full Document