Presentation is loading. Please wait.

Presentation is loading. Please wait.

30/9/2008Lecture 21 Computer Graphics Assistant Professor Dr. Sana’a Wafa Al-Sayegh 2 nd Semester 2008-2009 ITGD3107 University of Palestine.

Similar presentations


Presentation on theme: "30/9/2008Lecture 21 Computer Graphics Assistant Professor Dr. Sana’a Wafa Al-Sayegh 2 nd Semester 2008-2009 ITGD3107 University of Palestine."— Presentation transcript:

1 30/9/2008Lecture 21 Computer Graphics Assistant Professor Dr. Sana’a Wafa Al-Sayegh 2 nd Semester 2008-2009 ITGD3107 University of Palestine

2 30/9/2008Lecture 22 Chapter 3 Output Primitives line, circle, Ellipse algorithms and others ITGD3107 Computer Graphics

3 30/9/2008Lecture 23 Output Primitives What Kind of Math do We Need? Drawing Lines, Circles, Ellipses Filled Polygons and Characters Ideal Line, simple line Vector Generation DDA Algorithm Bresenham algorithm Circle Drawing algorithms Ellipse Drawing algorithms Representing Characters Drawing Filled Polygons

4 30/9/2008Lecture 24 What Kind of Math do We Need? Cartesian Coordinates Typically modeling space is floating point, screen space is integer screen coordinates are measured top to bottom, based on raster scan (0,0) x, y Cartesian grid Integer Grid

5 30/9/2008Lecture 25 Example 3D Primitives Polyhedron Sphere Polyline Patch

6 30/9/2008Lecture 26 Drawing Lines For horizontal, vertical and diagonal lines all pixels lie on ideal line: special case For lines at arbitrary angle, pick pixels closest to ideal line (Bresenham’s midpoint “scan conversion” algorithm) For thick lines, use multiple pixels in each column or fill a rotated rectangle Sampling continuous line on discrete grid introduces sampling errors: “jaggies”

7 30/9/2008Lecture 27 Towards the Ideal Line We can only do a discrete approximation Illuminate pixels as close to the true path as possible, consider bi-level display only –Pixels are either lit or not lit

8 30/9/2008Lecture 28 What is an ideal line Must appear straight and continuous –Only possible axis-aligned and 45 o lines Must interpolate both defining end points Must have uniform density and intensity –Consistent within a line and over all lines Must be efficient, drawn quickly –Lots of them are required!!!

9 30/9/2008Lecture 29 Simple Line Based on slope-intercept algorithm from algebra: y = mx + b Simple approach: increment x, solve for y Floating point arithmetic required

10 30/9/2008Lecture 210 Does it Work? It seems to work okay for lines with a slope of 1 or less, but doesn’t work well for lines with slope greater than 1 – lines become more discontinuous in appearance and we must add more than 1 pixel per column to make it work. Solution? - use symmetry.

11 30/9/2008Lecture 211 Modification OR, increment along x-axis if dy<dx else increment along y-axis

12 30/9/2008Lecture 212 Vector Generation There are two vector generation algorithm: DDA = Digital Differential Analyser –finite differences Bresenham’s Algorithm

13 30/9/2008Lecture 213 DDA algorithm DDA = Digital Differential Analyser –finite differences Treat line as parametric equation in t : Start point End point

14 30/9/2008Lecture 214 DDA Algorithm Start at t = 0 At each step, increment t by dt Choose appropriate value for dt Ensure no pixels are missed: –Implies: and Set dt to maximum of dx and dy

15 30/9/2008Lecture 215 DDA algorithm line(int x1, int y1, int x2, int y2) { float x,y; int dx = x2-x1, dy = y2-y1; int n = max(abs(dx),abs(dy)); float dt = n, dxdt = dx/dt, dydt = dy/dt; x = x1; y = y1; while( n-- ) { point(round(x),round(y)); x += dxdt; y += dydt; } n - range of t.

16 30/9/2008Lecture 216 DDA algorithm Still need a lot of floating point arithmetic. –2 ‘round’s and 2 adds per pixel. Is there a simpler way ? Can we use only integer arithmetic ? –Easier to implement in hardware.

17 30/9/2008Lecture 217 Bresenham (mid-point) algorithm Choose between 2 pixels at each step based upon the sign of a decision variable. Update the decision variable based upon which pixel is chosen. Start point is simply first endpoint (x 1, y 1 ). Need to calculate the initial value for d

18 30/9/2008Lecture 218 Bresenham algorithm m<1 void MidpointLine1(int x1,y1,x2,y2) { int dx=x2-x1; int dy=y2-y1; int d=2*dy-dx; int increE=2*dy; int incrNE=2*(dy-dx); x=x1; y=y1; WritePixel(x,y); while (x < x2) { if (d<= 0) { d+=incrE; x++ } else { d+=incrNE; x++; y++; } WritePixel(x,y); }

19 30/9/2008Lecture 219 Bresenham algorithm m>=1 void MidpointLine2(int x1,y1,x2,y2) { int dx=x2-x1; int dy=y2-y1; int d=2*dx-dy; int increE=2*dx; int incrNE=2*(dx-dy); x=x1; y=y1; WritePixel(x,y); while (y < y2) { if (d<= 0) { d+=incrE; y++; } else { d+=incrNE; x++; y++; } WritePixel(x,y); }

20 30/9/2008Lecture 220 Drawing Circles and Ellipses circle outline filled ellipse

21 30/9/2008Lecture 221 Circle drawing. Can also use Bresenham to draw circles. Use 8-fold symmetry Choices for Next pixel M E SE Previous Pixel Choices for Current pixel

22 30/9/2008Lecture 222 Circle drawing. First method is: Where x value steps from to

23 30/9/2008Lecture 223 Circle drawing. Second method is:

24 30/9/2008Lecture 224 Circle drawing.

25 30/9/2008Lecture 225 Example: Midpoint Circle algorithm:

26 30/9/2008Lecture 226 Ellipse Drawing

27 30/9/2008Lecture 227 Midpoint Ellipse Algorithm

28 30/9/2008Lecture 228 Example: Midpoint Ellipse Algorithm

29 30/9/2008Lecture 229 Example: Midpoint Ellipse Algorithm

30 30/9/2008Lecture 230 Drawing Characters For characters defined by small bitmap –selectively write pixels of refresh buffer corresponding to “true” bits of character bitmap –Outline fonts: defined in terms of (mathematical) drawing primitives (lines, arcs, etc).

31 30/9/2008Lecture 231 Representing Characters

32 30/9/2008Lecture 232 Drawing Filled Polygons 1.Find intersection of scan line with polygon edges 2.Sort intersections by increasing x 3.Fill the polygon between pairs of intersections (spans)


Download ppt "30/9/2008Lecture 21 Computer Graphics Assistant Professor Dr. Sana’a Wafa Al-Sayegh 2 nd Semester 2008-2009 ITGD3107 University of Palestine."

Similar presentations


Ads by Google