Computer Graphics Lecture Notes

3y ago
73 Views
4 Downloads
2.70 MB
63 Pages
Last View : 17d ago
Last Download : 2m ago
Upload by : Laura Ramon
Transcription

Computer GraphicsLecture NotesDEPARTMENT OF COMPUTER SCIENCE & ENGINEERINGSHRI VISHNU ENGINEERING COLLEGE FOR WOMEN(Approved by AICTE, Accredited by NBA, Affiliated to JNTU Kakinada)BHIMAVARAM – 534 202

UNIT- 1Overview of Computer Graphics1.1 Application of Computer GraphicsComputer-Aided Design for engineering and architectural systems etc.Objects maybe displayed in a wireframe outline form. Multi-window environment is alsofavored for producing various zooming scales and views.Animations are useful for testing performance.Presentation GraphicsTo produce illustrations which summarize various kinds of data. Except 2D, 3D graphicsare good tools for reporting more complex data.Computer ArtPainting packages are available. With cordless, pressure-sensitive stylus, artists canproduce electronic paintings which simulate different brush strokes, brush widths, andcolors. Photorealistic techniques, morphing and animations are very useful in commercialart. For films, 24 frames per second are required. For video monitor, 30 frames per secondare required.EntertainmentMotion pictures, Music videos, and TV shows, Computer gamesEducation and TrainingTraining with computer-generated models of specialized systems such as the training ofship captains and aircraft pilots.VisualizationFor analyzing scientific, engineering, medical and business data or behavior. Convertingdata to visual form can help to understand mass volume of data very efficiently.Image ProcessingImage processing is to apply techniques to modify or interpret existing pictures. It iswidely used in medical applications.Graphical User InterfaceMultiple window, icons, menus allow a computer setup to be utilized more efficiently.1.2 Video Display devices1.2.1Cathode-Ray Tubes (CRT) - still the most common video display device presently

Electrostatic deflection of the electron beam in a CRTAn electron gun emits a beam of electrons, which passes through focusing and deflectionsystems and hits on the phosphor-coated screen. The number of points displayed on a CRT isreferred to as resolutions (eg. 1024x768). Different phosphors emit small light spots ofdifferent colors, which can combine to form a range of colors. A common methodology forcolor CRT display is the Shadow-mask meth

Illustration of a shadow-mask CRTThe light emitted by phosphor fades very rapidly, so it needs to redraw the picture repeatedly.There are 2 kinds of redrawing mechanisms: Raster-Scan and Random-Scan1.2.2 Raster-ScanThe electron beam is swept across the screen one row at a time from top to bottom. As itmoves across each row, the beam intensity is turned on and off to create a pattern ofilluminated spots. This scanning process is called refreshing. Each complete scanning of ascreen is normally called a frame.The refreshing rate, called the frame rate, is normally 60 to 80 frames per second, ordescribed as 60 Hz to 80 Hz.Picture definition is stored in a memory area called the frame buffer. This frame bufferstores the intensity values for all the screen points. Each screen point is called a pixel (pictureelement).On black and white systems, the frame buffer storing the values of the pixels is called abitmap. Each entry in the bitmap is a 1-bit data which determine the on (1) and off (0) of theintensity of the pixel.On color systems, the frame buffer storing the values of the pixels is called a pixmap(Though nowadays many graphics libraries name it as bitmap too). Each entry in the pixmapoccupies a number of bits to represent the color of the pixel. For a true color display, thenumber of bits for each entry is 24 (8 bits per red/green/blue channel, each channel 28 256levels of intensity value, ie. 256 voltage settings for each of the red/green/blue electron guns).

1.2.3 Random-Scan (Vector Display)The CRT's electron beam is directed only to the parts of the screen where a picture is to bedrawn. The picture definition is stored as a set of line-drawing commands in a refresh displayfile or a refresh buffer in memory.Random-scan generally have higher resolution than raster systems and can produce smoothline drawings, however it cannot display realistic shaded scenes.Display ControllerFor a raster display device reads the frame buffer and generates the control signals for thescreen, ie. the signals for horizontal scanning and vertical scanning. Most display controllersinclude a color map (or video look-up table). The major function of a color map is to providea mapping between the input pixel value to the output color.Anti-AliasingOn dealing with integer pixel positions, jagged or stair step appearances happen veryusually. This distortion of information due to under sampling is called aliasing. A numberof ant aliasing methods have been developed to compensate this problem.One way is to display objects at higher resolution. However there is a limit to how big wecan make the frame buffer and still maintaining acceptable refresh rate.Drawing a Line in Raster Devices1.3 DDA AlgorithmIn computer graphics, a hardware or software implementation of a digital differential analyzer(DDA) is used for linear interpolation of variables over an interval between start and end point.DDAs are used for rasterization of lines, triangles and polygons. In its simplest implementationthe DDA Line drawing algorithm interpolates values in interval [(xstart, ystart), (xend, yend)] bycomputing for each xi the equations xi xi 1 1/m, yi yi 1 m, where Δx xend xstart andΔy yend ystart and m Δy/Δx.The dda is a scan conversion line algorithm based on calculating either dy or dx. A line issampled at unit intervals in one coordinate and corresponding integer values nearest the line path

are determined for other coordinates.Considering a line with positive slope, if the slope is less than or equal to 1, we sample at unit xintervals (dx 1) and compute successive y values asSubscript k takes integer values starting from 0, for the 1st point and increases by until endpointis reached. y value is rounded off to nearest integer to correspond to a screen pixel.For lines with slope greater than 1, we reverse the role of x and y i.e. we sample at dy 1 andcalculate consecutive x values asSimilar calculations are carried out to determine pixel positions along a line with negative slope.Thus, if the absolute value of the slope is less than 1, we set dx 1 if i.e. the starting extremepoint is at the left.The basic concept is:-A line can be specified in the form:y mx c-Let m be between 0 to 1, then the slope of the line is between 0 and 45 degrees.-For the x-coordinate of the left end point of the line, compute the corresponding y valueaccording to the line equation. Thus we get the left end point as (x1,y1), where y1 maynot be an integer.-Calculate the distance of (x1,y1) from the center of the pixel immediately above it and call itD1-Calculate the distance of (x1,y1) from the center of the pixel immediately below it and call itD2-If D1 is smaller than D2, it means that the line is closer to the upper pixel than the lowerpixel, then, we set the upper pixel to on; otherwise we set the lower pixel to on.-Then increatement x by 1 and repeat the same process until x reaches the right end pointof the line.-This method assumes the width of the line to be zero1.4 Bresenham's Line AlgorithmThis algorithm is very efficient since it use only incremental integer calculations. Instead ofcalculating the non-integral values of D1 and D2 for decision of pixel location, it computes avalue, p, which is defined as:p (D2-D1)* horizontal length of the lineif p 0, it means D1 is smaller than D2, and we can determine the pixel location accordinglyHowever, the computation of p is very easy:The initial value of p is 2 * vertical height of the line - horizontal length of the line.

At succeeding x locations, if p has been smaller than 0, then, we increment p by 2 * verticalheight of the line, otherwise we increment p by 2 * (vertical height of the line - horizontallength of the line)All the computations are on integers. The incremental method is applied tovoid BresenhamLine(int x1, int y1, int x2, int y2){ int x, y, p, const1, const2; /* initializevariables */ p 2*(y2-y1)-(x2-x1);const1 2*(y2-y1); const2 2*((y2y1)-(x2-x1));x x1;y y1;SetPixel(x,y);while (x xend) {x ;if (p 0){ p p const1;}else{ y ;p p const2;}SetPixel(x,y);}}Bitmap-A graphics pattern such as an icon or a character may be needed frequently, or mayneed to be re-used.-Generating the pattern every time when needed may waste a lot of processing time.-A bitmap can be used to store a pattern and duplicate it to many places on the imageor on the screen with simple copying operations.

1.5 Mid Point circle AlgorithmHowever, unsurprisingly this is not a brilliant solution!Firstly, the resulting circle has large gaps where the slope approaches the verticalSecondly, the calculations are not very efficientThe square (multiply) operationsThe square root operation – try really hard to avoid these!We need a more efficient, more accurate solution.The first thing we can notice to make our circle drawing algorithm more efficient is that circlescentred at (0, 0) have eight-way symmetrySimilarly to the case with lines, there is an incremental algorithm for drawing circles – the midpoint circle algorithmIn the mid-point circle algorithm we use eight-way symmetry so only ever calculate the pointsfor the top right eighth of a circle, and then use symmetry to get the rest of the pointsAssume that we havejust plotted point (xk, yk)The next point is achoice between (xk 1, yk)and (xk 1, yk-1)

We would like to choosethe point that is nearest tothe actual circleSo how do we make this choice?Let’s re-jig the equation of the circle slightly to give us:The equation evaluates as follows:f circ ( x, y )x2y2r20,f circ ( x, y )0,0, 0 if ( x, y) is outside the circle boundary 0 if ( x, y) is on the circle boundary 0 if ( x, y) is inside the circle boundaryBy evaluating this function at the midpoint between the candidate pixels we can make ourdecisionAssuming we have just plotted the pixel at (xk,yk) so we need to choose between (xk 1,yk) and(xk 1,yk-1)Our decision variable can be defined as:pk1 )221 ) r22f circ ( xk 1, yk( xk 1) 2 ( ykIf pk 0 the midpoint is inside the circle and and the pixel at yk is closer to the circleOtherwise the midpoint is outside and yk-1 is closer

To ensure things are as efficient as possible we can do all of our calculations incrementallyFirst consider:pkf circ xk11, yk1[( xk 1) 1]2pkpk1yk1111221) ( yk22( xk21r2yk2 ) ( yk1yk ) 1where yk 1 is either yk or yk-1 depending on the sign of pkThe first decision variable is given as:p01 )21 )2 r 22f circ (1, r1 (r54rThen if pk 0 then the next decision variable is given as:pk1pk2 xk11If pk 0 then the decision variable is:pk1pk2 xk11 2 yk 1Input radius r and circle centre (xc, yc), then set the coordinates for the first point on thecircumference of a circle centred on the origin as:( x0 , y0 ) (0, r ) Calculate the initial value of the decision parameter as:p0 5r4Starting with k 0 at each position xk, perform the following test. If pk 0, the next pointalong the circle centred on (0, 0) is (xk 1, yk) and:pk1pk2 xk11Otherwise the next point along the circle is (xk 1, yk-1) and:pkp k 2 xk 1 1 2 y k 1Determine symmetry points in the other seven octantsMove each calculated pixel position (x, y) onto the circular path centred at (xc, yc) to plot thecoordinate values:1

xx xc y y ycRepeat steps 3 to 5 until x yTo see the mid-point circle algorithm in action lets use it to draw a circle centred at (0,0) withradius 10

UNIT -22.1 Scan-Line Polygon Fill Algorithm-Basic idea: For each scan line crossing a polygon, this algorithm locates the intersectionpoints of the scan line with the polygon edges. These intersection points are shorted fromleft to right. Then, we fill the pixels between each intersection pair.-Some scan-line intersection at polygon vertices require special handling. A scan linepassing through a vertex as intersecting the polygon twice. In this case we may or maynot add 2 points to the list of intersections, instead of adding 1 points. This decisiondepends on whether the 2 edges at both sides of the vertex are both above, both below, orone is above and one is below the scan line. Only for the case if both are above or bothare below the scan line, then we will add 2 points.2.2 Inside-Outside Tests:-The above algorithm only works for standard polygon shapes. However, for the caseswhich the edge of the polygon intersects, we need to identify whether a point is an interioror exterior point. Students may find interesting descriptions of 2 methods to solve thisproblem in many text books: odd-even rule and nonzero winding number rule.

2.3 Boundary-Fill Algorithm-This algorithm starts at a point inside a region and paint the interior outward towards theboundary.This is a simple method but not efficient: 1. It is recursive method which may occupy alarge stack size in the main memory.void BoundaryFill(int x, int y, COLOR fill, COLOR boundary){ COLOR current;current GetPixel(x,y);if (current boundary) and (current fill) thenSetPixel(x,y,fill);BoundaryFill(x y);BoundaryFill(x,y ;}}-{More efficient methods fill horizontal pixel spands across scan lines, instead ofproceeding to neighboring points.

2.4 Flood-Fill Algorithm-Flood-Fill is similar to Boundary-Fill. The difference is that Flood-Fill is to fill an areawhich I not defined by a single boundary color.void BoundaryFill(int x, int y, COLOR fill, COLOR old color){ if (GetPixel(x,y) old color) {SetPixel(x,y,fill);BoundaryFill(x y);BoundaryFill(x,y ;}

UNIT 3Two Dimensional TransformationsIn many applications, changes in orientations, size, and shape are accomplished withgeometric transformations that alter the coordinate descriptions of objects.Basic geometric transformations are:TranslationRotationScalingOther transformations:ReflectionShear3.1 Basic TransformationsTranslationWe translate a 2D point by adding translation distances, tx and ty, to the original coordinateposition (x,y):x' x tx, y' y tyAlternatively, translation can also be specified by the following transformation matrix:0t x1 t10y0 01Then we can rewrite the formula as:x' y'10 tx01t0 011yxy1For example, to translate a triangle with vertices at original coordinates (10,20), (10,10),(20,10) by tx 5, ty 10, we compute as followings:Translation of vertex (10,20):x'1 0y' 0115101020 0 *100 0111*10 0 * 20 5 *11* 2010 *115 300 *10 0 * 20 1*111*10 0 *10 5 *115Translation of vertex(10,10):x'1 0 5y' 0 110 0 1101010 0 *10 1*10110 *10 *10 0 *10 1*1 201

Translation of vertex (20,10):x'y'1 00 5 201* 20 0 *10 5 *1251 10 10 0 * 20 1*10 10 *1 200 01110 * 20 0 *10 1*11The resultant coordinates of the triangle vertices are (15,30), (15,20), and (25,20) respectively.Exercise: translate a triangle with vertices at original coordinates (10,25), (5,10), (20,10)by tx 15, ty 5. Roughly plot the original and resultant triangles.3.1.2 Rotation About the OriginTo rotate an object about the origin (0,0), we specify the rotation angle ?. Positive andnegative values for the rotation angle define counterclockwise and clockwise rotationsrespectively. The followings is the computation of this rotation for a point:x' x cos ? - y sin ?y' x sin ? y cos ?Alternatively, this rotation can also be specified by the following transformation matrix:cossin00cossin00cossincos1Then we can rewrite the formula as:x'y' sin0100x0y11For example, to rotate a triange about the origin with vertices at original coordinates (10,20),(10,10), (20,10) by 30 degrees, we compute as followings:cossin0cossin00cos 30 0sin 3010sin 300cos 300010.866 0.500.500.866001Rotation of vertex (10,20):x'0.8660.50.5 0.866y' 10001000.866 *10 ( 0.5) * 20 0 *11.3420 0.5 *10 0.866 * 20 0 *1 22.32110 *100 * 20 1*112

Rotation of vertex (10,10):x'y' 10.8660.5 0 100.866 *10 ( 0.5) *10 0 *13.6613.660.5 0.866 010 0.5 *10 0.866 *10 0 *1 001 10 *10 0 *10 1*11Rotation of vertex (20,10):x'0.8660.50.5 0.866y' 1000200.866 * 20 ( 0.5) *10 0 *112.3210 0.5 * 20 0.866 *10 0 *1 18.660110 * 200 *10 1*11The resultant coordinates of the triangle vertices are (-1.34,22.32), (3.6,13.66), and(12.32,18.66) respectively.Exercise: Rotate a triange with vertices at original coordinates (10,20), (5,10),(20,10) by 45 degrees. Roughly plot the original and resultant triangles.3.2 Scaling With Respect to the OriginWe scale a 2D object with respect to the origin by setting the scaling factors sx and sy,which are multiplied to the original vertex coordinate positions (x,y):x' x * sx, y' y * syAlternatively, this scaling can also be specified by the following transformation matrix:sx00s0010y0Then we can rewrite the formula as:sxx'y' 0010sy0001xy1For example, to scale a triange with respect to the origin, with vertices at originalcoordinates (10,20), (10,10), (20,10) by sx 2, sy 1.5, we compute as followings:Scaling of vertex (10,20):x'00y' 0 1.5 0120 01102 *100 * 20 0 *120 0 *101.5 * 2010 *10 0 * 20 1*1200 *1 3013

Scaling of vertex (10,10):x'2 0y' 0 1.510102 *1010 000 0 10 *10*10 1.5 *100 *1200 *1 1510 *10 0 *10 1*11202 * 20 0 *10 0 *140Scaling of vertex(20,10):x'2 0y' 01001.5 00110 0 * 2011.5 *100 *1 150 * 20 0 *10 1*11The resultant coordinates of the triangle vertices are (20,30), (20,15), and (40,15) respectively.Exercise: Scale a triange with vertices at original coordinates (10,25), (5,10), (20,10) bysx 1.5, sy 2, with respect to the origin. Roughly plot the original and resultanttriangles.3.3 Concatenation Properties of Composite MatrixI. Matrix multiplication is associative:A·B·C (A·B) ·C A·(B·C)Therefore, we can evaluate matrix products using these associative grouping.For example, we have a triangle, we want to rotate it with the matrix B, then we translateit with matrix A.Then, for a vertex of that triangle represented as C, we compute its transformation as:C' A·(B·C)But we can also change the computation method as:C' (A·B)·CThe advantage of computing it using C' (A·B)·C instead of C' A·(B·C) is that, forcomputing the 3 vertices of the triangle, C1, C2, C 3, the computation time is shortened:Using C' A·(B·C):1. compute B · C1 and put the result into I12. compute A · I1 and put the result into C1'3. compute B · C2 and put the result into I24. compute A · I2 and put the result into C2'5. compute B · C3 and put the result into I36. compute A · I3 and put the result into C3'Using C' (A·B)·C:- compute A · B and put the result into M- compute M · C1 and put the result into C1''- compute M · C2 and put the result into C2'- compute M · C3 and put the result into C34

Example: Rotate a triangle with vertices (10,20), (10,10), (20,10) about the origin by 30degrees and then translate it by tx 5, ty 10,We compute the rotation matrix:cos 30B sin 30sin 30cos 3000100.8660.5 00.866 00 0.500 1And we compute the translation matrix:150A 01 100 01Then, we compute M A·B1M 00 5 0.8660.51 10 · 0.50.8660 101* 0.866M 0 * 0.8660000 10 * 0.5 5 * 0 1* 0.5 0 * 0.866 5 * 0 1* 0 0 * 0 5 *11* 0.5 10 * 0 0 * 0.5 1* 0.866 10 * 0 0 * 0 1* 0 10 *10 * 0.8660.866M 0.500 * 0.5 1* 0 0 * 0.50.5 50.866 1000 * 0.866 1* 0 0 * 00 * 0 1*11Then, we compute the transformations of the 3 vertices:Transformation of vertex (10,20):x'0.866y' 0.5100.5 50.866 10101100.866 *10 ( 0.5) * 20 5 *13.6620 0.5 *10 0.866 * 20 10 *1 32.320 *100 * 20 1*11Transformation of vertex(10,10):x'0.866y' 0.5100.5 5 100.866 *10 ( 0.5) *10 5 *18.660.866 10 10 0.5 *10 0.866 *10 10 *1 23.660110 *100 *10 1*115

Transformation of vertex (20,10):x'y' 0.8660.510.5 50.866 100012010 10.866 * 20 ( 0.5) *10 5 *117.320.5 * 20 0.866 *10 10 *1 28.

Overview of Computer Graphics 1.1 Application of Computer Graphics Computer-Aided Design for engineering and architectural systems etc. Objects maybe displayed in a wireframe outline form. Multi-window environment is also favored for producing various zooming scales and views. Animations are useful for testing performance. Presentation Graphics

Related Documents:

Introduction of Chemical Reaction Engineering Introduction about Chemical Engineering 0:31:15 0:31:09. Lecture 14 Lecture 15 Lecture 16 Lecture 17 Lecture 18 Lecture 19 Lecture 20 Lecture 21 Lecture 22 Lecture 23 Lecture 24 Lecture 25 Lecture 26 Lecture 27 Lecture 28 Lecture

GEOMETRY NOTES Lecture 1 Notes GEO001-01 GEO001-02 . 2 Lecture 2 Notes GEO002-01 GEO002-02 GEO002-03 GEO002-04 . 3 Lecture 3 Notes GEO003-01 GEO003-02 GEO003-03 GEO003-04 . 4 Lecture 4 Notes GEO004-01 GEO004-02 GEO004-03 GEO004-04 . 5 Lecture 4 Notes, Continued GEO004-05 . 6

Computer Graphics & Image Processing 2003 Neil A. Dodgson 2 7 Course books Computer Graphics: Principles & Practice Foley, van Dam, Feiner & Hughes,Addison-Wesley, 1990 zOlder version: Fundamentals of Interactive Computer Graphics Foley & van Dam, Addison-Wesley, 1982 Computer Graphics &

Lecture 1: A Beginner's Guide Lecture 2: Introduction to Programming Lecture 3: Introduction to C, structure of C programming Lecture 4: Elements of C Lecture 5: Variables, Statements, Expressions Lecture 6: Input-Output in C Lecture 7: Formatted Input-Output Lecture 8: Operators Lecture 9: Operators continued

Introduction to Computer Graphics COMPSCI 464 Image credits: Pixar, Dreamworks, Ravi Ramamoorthi, . –Game design and development It is about –Learning the fundamentals of computer graphics –Implementing algorithms that are at the core of computer graphics . Fundamentals of Computer Graphics

What is computer Graphics? Computer graphics is an art of drawing pictures, lines, charts, etc. using computers with the help of programming. Computer graphics image is made up of number of pixels. Pixel is the smallest addressable graphical unit represented on the computer screen. Introduction Computer is information processing machine.

Graphics API and Graphics Pipeline Efficient Rendering and Data transfer Event Driven Programming Graphics Hardware: Goal Very fast frame rate on scenes with lots of interesting visual complexity Pioneered by Silicon Graphics, picked up by graphics chips companies (Nvidia, 3dfx, S3, ATI,.). OpenGL library was designed for this .

A separate practical record for Botany and Zoology is to be maintained. Use only pencils for drawing and writing the notes in the interleaves of the record. Below the diagram, they should write the caption for the diagram in bold letters. While labeling different parts of the diagram, draw horizontal indicator lines with the help of a scale. SAFETY IN THE LABORATORY: The following precaution .