Scan Conversion Line(DDA Line and Bresenham Line)

Slides:



Advertisements
Similar presentations
Graphics Primitives: line
Advertisements

Computer Graphics 4: Bresenham Line Drawing Algorithm, Circle Drawing & Polygon Filling By:Kanwarjeet Singh.
CS 450: COMPUTER GRAPHICS REVIEW: DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE.
+ CPCS 391 Computer Graphics 1 Instructor: Dr. Sahar Shabanah Lecture 3.
Scan Conversion Algorithms
Scan conversion of Line , circle & ellipse
Line Drawing Algorithms. Rasterization-Process of determining which pixels give the best approximation to a desired line on the screen. Scan Conversion-Digitizing.
The lines of this object appear continuous However, they are made of pixels 2April 13, 2015.
Komputer Grafik 2 (AK045206) Scan Conversion 1/31 Scan Conversion.
Raster conversion algorithms for line and circle
CS5500 Computer Graphics © Chun-Fa Chang, Spring 2007 CS5500 Computer Graphics May 3, 2007.
University of Missouri at Columbia 2D Scan-line Conversion University of Missouri at Columbia.
Line Drawing by Algorithm. Line Drawing Algorithms Line drawn as pixels Graphics system –Projects the endpoints to their pixel locations in the frame.
CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Scan Conversion CS123 1 of 44Scan Conversion - 10/14/2014.
CS 450: COMPUTER GRAPHICS DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE.
Circle Drawing algo..
CGMB214: Introduction to Computer Graphics
1/1/20001 Topic >>>> Scan Conversion CSE Computer Graphics.
Dr. S.M. Malaek Assistant: M. Younesi
Graphics Primitives: line. Pixel Position
WHERE TO DRAW A LINE?? Line drawing is accomplished by calculating intermediate positions along the line path between specified end points. Precise definition.
Scan Conversion Line and Circle
Introduction Computer Graphics & Its application Types of computer graphics Graphic display : random Scan & Raster Scan display Frame buffer and video.
Graphics Output Primitives
CGMB214: Introduction to Computer Graphics
 A line segment in a scene is defined by the coordinate positions of the line end-points x y (2, 2) (7, 5)
Chapter 3 Scan Conversion Lecture-02. Bresenham’s Line Algorithm Bresenham’s line algorithm – is a highly efficient incremental method for scan- converting.
Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization.
MIDPOINT CIRCLE & ELLIPSE GENERARTING ALGORITHMS
Midpoint Circle Algorithm
CS 325 Introduction to Computer Graphics 02 / 03 / 2010 Instructor: Michael Eckmann.
GEOMETRY AND LINE GENERATION Geometry and Line Generation Chapter 2.
Scan Conversion.
Bresenham’s Line Algorithm
Lecture 2: 19/4/1435 Graphical algorithms Lecturer/ Kawther Abas CS- 375 Graphics and Human Computer Interaction.
Rasterization Overview Raster Display Device. Scan Conversion / Rasterization: converting vector graphics into raster graphics (determining pixels in.
Computer Graphics : Bresenham Line Drawing Algorithm, Circle Drawing
Computer Graphics CC416 Lecture 04: Bresenham Line Algorithm & Mid-point circle algorithm Dr. Manal Helal – Fall 2014.
Write Bresenham’s algorithm for generation of line also indicate which raster locations would be chosen by Bresenham’s algorithm when scan converting.
Computer Graphics Inf4/MSc Computer Graphics Lecture 4 Line & Circle Drawing.
10/10/2006TCSS458A Isabelle Bichindaritz1 Line and Circle Drawing Algorithms.
Computer Graphics Lecture 06 Circle Drawing Techniques Taqdees A. Siddiqi
Scan Conversion of Line Segments. What is Scan conversion? Final step of rasterization (the process of taking geometric shapes and converting them into.
Computer Graphics : output primitives.. 2 of 32 T1 – pp. 103–123, 137–145, 147–150, 164–171 Points and LinesPoints Line Drawing AlgorithmsLine Mid–Point.
Line Drawing Algorithms 1. A line in Computer graphics is a portion of straight line that extends indefinitely in opposite direction. 2. It is defined.
Objectives Understand Bresenhams line drawing algorithm. Apply the algorithm to plot a line with the end points specified.
Primitive graphic objects
Scan Conversion or Rasterization
Computer Graphics Drawing Line.
Raster Graphics.
MID-POINT CIRCLE ALGORITHM
Lecture 9 Line Drawing Algorithms (Bresenham’s Line Algorithm)
(c) 2002 University of Wisconsin, CS559
Scan Conversion or Rasterization
Computer Graphics Implementation I.
Lecture 05: Mid-point Ellipse algorithm Dr. Manal Helal – Fall 2014
Chapter Three Part I Output Primitives CS 380.
© University of Wisconsin, CS559 Fall 2004
Scan Conversion of Circles
2D Scan-line Conversion
Allah says Say, "Allah created cattle for you. In them you find warmth and benefit and from them you eat. In them there is beauty for you when you bring.
Edited from The Rasterization Problem: Idealized Primitives Map to Discrete Display Space Edited from.
Chapter 3 Graphics Output Primitives
Primitive Drawing Algorithm
Type to enter a caption. Computer Graphics Week 1 Lecture 2.
Primitive Drawing Algorithm
Where We Stand At this point we know how to: Next thing:
Line Drawing Algorithms
OUTPUT PRIMITIVES / DISPLAY TECHNIQUES
Presentation transcript:

Scan Conversion Line(DDA Line and Bresenham Line)

DDA Line: The Digital Differential Analyzer algorithm is an incremental scan-conversion method. Such an approach is characterized by performing calculations at each step using result from the preceding step. Suppose at step I we have calculated (xi,yi) to be a point on the line. Since the next point (Xi+1,yi+1) should satisfy m=dy/dx If |m|<=1 we start with x= x1 and y= y1 and set dx=1 (i.e unit increment in the x-direction). The y co-ordinate of each succesive point is calculated using yi+1=yi+m. if |m|>1 we start with x=x1 and y-y1 and set dy=1(i.e. unit increment in the y direction). The x-coordinate of each successive point on the line is calculated using xi+1=xi+1/m. This process continues until x reaches x2 (|m|<=1 case) or y reaches y2 (for |m|>1 case) and all points found are scan converted to pixel co-ordinates.

DDA Line Algo: 1) Input (x1,y1) and (x2,y2) 2) Compute dx=|x2-x1| and dy=|y2-y1| 3) Set x=x1 and y=y1 4) If dx>dy then Steps=dx Else Steps=dy 5) Compute incremental values of x and y xx=dx/steps and yy=dy/steps 6) Draw (x,y) 7) Compute next co-ordinates. x=x+xx and y=y+yy 8) If no of iteration >steps then Stop Goto step 6 9) stop.

Example Find the intermediate co-ordinates for the given points (1,1) (8,9) Sol: 1) set x=x1 and y=y1 2) calculate dx=|x2-x1|=|8-1|=7, dy =|y2-y1|=|9-1|=8 3) Check dx > dy i.e 7>8( false) then steps=dy i.e steps=8 4) Compute increment values of x and y (i.e the value to be added to get new x and y) xx=dx/steps= 7/8= 0.87 and yy= dy/steps=8/8=1 5) Compute next co-ordinate ( new x and y) x=x+xx= 1+0.87 and y =y+yy=1+1=2 When the value exceed 8 program will stop because Steps exceed m= 8/7=1.14 and 1/m=0.87 X y round 1 1.87 2 2.87 3 3.87 4 4.87 5 5.87 6 6.87 7 7.87 8

Find the intermediate point for the given points(1,2)(14,15) dy=15-2=13 dx=14-1=13 Dx>dy(false) therefor steps= dy(13) xx=dx/steps=13/13 and yy=dy/steps=13/13=1 x=x+xx=1+1=2 y=y+yy=2+1=3

Program: dx=abs(xb-xa); dy=abs(yb-ya); if(dx>=dy) { steps=dx; } else { steps=dy; } xincr=dx/steps; yincr=dy/steps; x=xa; y=ya; putpixel(x,y,RED); for(k=1;k<steps;k++) { x=xincr+x; y=yincr+y; putpixel(x,y,k); }

Bresenham Line algorithm: Bresenham’s line algorithm is a highly efficient incremental method for scan converting lines. It produces mathematically accurate results using only integer addition, subtraction and multiplication. We start with pixel p1(x1,y1), then select subsequent pixels as we work our way to the right one pixel position at a time in the horizontal direction towardsp2(x2,y2). Once a pixel is chosen at any step, the next pixel is either the one to its right or the one to its right and up due to limit on m. The line is best approximated by those pixels that fall the least distance from its true path between p1 and p2.

Working: The co-ordinates of the last chosen pixel upon entering step I are(xi,yi). Our task is to choose the next one between the bottom pixel S and the top pixel T. If S is chosen we have xi+1=xi+1 and yi+1=yi. If T is chosen, we have xi+1=xi+1 and yi+1=yi+1 The actual y coordinate of the line at x=xi+1 is y=m(xi+1)+b The distance from S to actual line in the y-direction is s=y-yi The distance from T to actual line is t=(yi +1)-y

Now consider the difference between these two distance values:s-t When s-t is less than zero we have s<t and the closest pixel is S. When s-t is greater than zero we have s>t and the closest pixel is T We also choose T when s-t=0 Derivation: s-t=(y-yi)-[(yi+1)-y] s-t= 2y-2yi-1 = 2m(xi+1)+2b-2yi-1 Substituting m=dy/dx and introducing a decision variable di=dx(s-t). di= 2dy*xi - 2dx*yi+C Where C=2dy+dx(2b-1) Similarly we can write decision variable di+1 for the next step as

di+1 = 2dy*xi+1-2dx*yi+1+c Then di+1-di= 2dy(xi+1-xi)-2dx(yi+1-yi) Since xi+1=xi+1, we have di+1=di+2dy-2dx(yi+1-yi) If the chosen pixel is the top pixel T (di>=0) then yi+1=yi+1 and so di+1=di+2dy-dx On the other hand if the chosen pixel is the bottom pixel S( meaning that di<0) then yi+1=yi and so di+1=di+2dy

Algo: Input (x0,y0) and (xn,yn) Calculate dx ,dy and Plot (x0,y0) Calculate p0=2dy-dx At each xk if pk<0 then { plot(xk+1,yk) Calculate pk+1=pk+2dy } Else { Plot(xk+1,yk+1) Calculate pk+1=pk+2dy-2dx } 6)Repeat step 5 dx times. 7) stop.

Line endpoints(20,10) and (30,18) dy=y2-y1=18-10=8 dx= x2-x1=30-20=10 Initial Decision Parameterhas the value. 1) P0=2*dy-dx=2*8-10=16-10=6 2) If pk<0 then plot(xk+1,yk) Calculate pk+1=pk+2dy Else Plot(xk+1,yk+1) Calculate pk+1=pk+2dy-2dx (This Will repeat dx no of times) K Pk (xk+1,yk+1) 6 21,11 1 2 22,12 -2 23,12 3 14 24,13 4 10 25,14 5 26,15 27,16 7 28,16 8 29,17 9 30,18

Circle Drawing Algorithm 8 segments of octants for a circle: If point 1 (x,y) were calculated with a circle algorithm seven more points could be found by reflection.

Two Algorithms: Bresenham and Mid- point 1) The best approximation of the true circle will be described by those pixels in the raster that fall the least distance from the true circle. 2) Each new point closest to the true circle can be found by taking either of the two actions a) move in the x direction. b) move in x-direction one unit and move in negative y direction by 1.

Derivation: T= (xi+1,yi) S=(xi+1,yi-1) D(T)= (xi+1)2 +yi2-r2 D(S)=(xi+1)2+(yi-1)2-r2 D(T) will always be positive outside the circle and D(S) will always be negative inside the circle. di=D(T)+D(S) di=2(xi+1)2+yi2+(yi-1)2-2r2 When di<0 we have D(T) <D(S) and pixel T is chosen. When di>0 then D(T)>=D(S) and pixel S is selected.

di+1=2(xi+1+1)2 + yi2+1 +(yi+1-1)2 - 2r2 di+1-di=2(xi+1+1)2+ yi2+1 + (yi+1-1)2 – 2(xi+1)2 - yi2 –(yi-1)2 Since xi+1 =xi+1 di+1=di+4xi+2(yi2+1-yi2)-2(yi+1-yi)+6 If T is chosen (meaning that di<0) then yi+1=yi and di+1=di+4xi+6 If s is chosen meaning di>0) then yi+1=yi-1 di+1=di + 4(xi-yi) + 10. d1= 3-2r

Algo Input x=0,y=r, d=3-2r Repeat while (x<=y) { plot(x,y,10); if(d<0) then d=d+4x+6 } else d=d+4(x-y)+10 y- - 3. Plot (x,y,10) { plot the co-ordinate x and y and all other symmetric point

Program: Main() { void circle1(int,int,int); void plotpoints(int,int,int,int); cout<<"Enter the location of the circle:"; cin>>x>>y; cout<<endl<<"Enter the radius of circle:"; cin>>r; putpixel(x,y,15); circle1(x,y,r); } void circle1(int xc , int yc , int r) plotpoints(xc,yc,x,y); int x=0,y=r,p=3-(2*r);

while(x<y) {if(p<0) { x++; p=p+4*x+6;} else { x++; y--; p=p+4*(x-y)+10 } plotpoints(xc,yc,x,y); sleep(1); }} void plotpoints(int xc ,int yc ,int x ,int y) { putpixel(xc+x,yc+y,11); putpixel(xc+x,yc-y,11); putpixel(xc-x,yc+y,11); putpixel(xc-x,yc-y,11); putpixel(xc+y,yc+x,11); putpixel(xc-y,yc-x,11); putpixel(xc-y,yc+x,11); putpixel(xc+y,yc-x,11); }

Midpoint Circle Drawing Algorithm Circle function: fcircle (x,y) = x2 + y2 –r2 > 0, (x,y) outside the circle < 0, (x,y) inside the circle = 0, (x,y) is on the circle boundary { fcircle (x,y) =

Now consider the Co-ordinates of the point halfway between pixel T and Pixel S (Xi+1,yi-1/2). This is called mid-point and we use it to define a decision parameter. pi=f(xi+1,yi-1/2)=(xi+1)2 + (yi-1/2)2 –r2 If pi is negative then the midpoint is inside the circle, and we choose T pixel . On the other hand if pi is positive (or equal to zero), the mid-point is outside the circle(or on the circle) and we choose pixel S similarly the decision parameter for the next step is pi+1=(xi+1)2 + (yi+1-1/2)2 –r2 Since xi+1=xi+1 we have pi+1 = pi + 2(xi+1) +1+(yi2+1-yi2)-(yi+1-yi) If pixel T is chosen (meaning pi<0) we have yi+1=yi on the other hand if pixel S is chosen(meaning pi>0) we have yi+1=yi-1

Pi+1=pi+2(xi+1)+1 if pi<0 pi+2(xi+1)+1-2(yi-1) if pi>=0 Final pi+1=pi+2xi+3 if pi<0 pi+1 = pi+2( xi-yi )+5 if pi>0 Finaly we compute the initial value for the decision parameter using the original defination pi and (0,r) pi=5/4-r

Algo: Input x=0,y=r p=1-r; While(x<=y) { plot(x,y) if(p<0) p=p+2x+3} Else { p=p+2(x-y)+5 y- - } X+ + 3) Plot (x,y,10) Plot the co-ordinate x and y and all the other symmetric point;