Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Graphics Inf4/MSc Computer Graphics Lecture 4 Line & Circle Drawing.

Similar presentations


Presentation on theme: "Computer Graphics Inf4/MSc Computer Graphics Lecture 4 Line & Circle Drawing."— Presentation transcript:

1 Computer Graphics Inf4/MSc Computer Graphics Lecture 4 Line & Circle Drawing

2 Computer Graphics Inf4/MSc 2/10/2007Lecture 42 Scan Conversion Also called rasterization. The 3D to 2D Projection gives us 2D vertices (points). We need to fill in the interior.

3 Computer Graphics Inf4/MSc 2/10/2007Lecture 43 Line Drawing Assuming: –Clipped (to fall within the window) –2D screen coordinates –Each pixel covers a square region where is its center? Rounding (X, Y) implies center at (0.0, 0.0). Truncating implies center at (0.5, 0.5).

4 Computer Graphics Inf4/MSc 2/10/2007Lecture 44 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

5 Computer Graphics Inf4/MSc 2/10/2007Lecture 45 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!!!

6 Computer Graphics Inf4/MSc 2/10/2007Lecture 46 Simple Line Based on slope-intercept algorithm from algebra: y = mx + b Simple approach: increment x, solve for y Floating point arithmetic required

7 Computer Graphics Inf4/MSc 2/10/2007Lecture 47 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.

8 Computer Graphics Inf4/MSc 2/10/2007Lecture 48 Modify algorithm per octant OR, increment along x-axis if dy<dx else increment along y-axis

9 Computer Graphics Inf4/MSc 2/10/2007Lecture 49 DDA algorithm DDA = Digital Differential Analyser –finite differences Treat line as parametric equation in t : Start point - End point - Y=mx+c

10 Computer Graphics Inf4/MSc 2/10/2007Lecture 410 DDA Algorithm DDA stands for digital differential analyzer. The differential equation for a line is: m = dy / dx

11 Computer Graphics Inf4/MSc 2/10/2007Lecture 411 Stepping in X direction

12 Computer Graphics Inf4/MSc 2/10/2007Lecture 412

13 If abs(dx) > abs(dy) Then increment in x by Unit compute y (dx=1) No of iteration=abs(x2-x1)/dx Else Increment in y by Unit compute x (dy=1) No of iteration=abs(y2-y1)/dy Y n+1 =y n +dy X n+1 =X n +dx

14 Computer Graphics Inf4/MSc 2/10/2007Lecture 414 Algo 1- Input the co-ordinate of Two end Points Calculate Constant DX & DY 3- determine the greater of abs of Dx & abs of DY 3- Start with first point and highlight it with rounding values of x & Y Calculate new x, new y again highlight continue until we reaches to second end point

15

16 Computer Graphics Inf4/MSc 2/10/2007Lecture 416 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

17 Computer Graphics Inf4/MSc 2/10/2007Lecture 417 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.

18 Computer Graphics Inf4/MSc 2/10/2007Lecture 418 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.


Download ppt "Computer Graphics Inf4/MSc Computer Graphics Lecture 4 Line & Circle Drawing."

Similar presentations


Ads by Google