Presentation is loading. Please wait.

Presentation is loading. Please wait.

PRESENTATION Computer Graphics Lumbini City College

Similar presentations


Presentation on theme: "PRESENTATION Computer Graphics Lumbini City College"— Presentation transcript:

1 AASHISH ADHIKARI [mail@aashishadhikari.info.np]
PRESENTATION Computer Graphics Lumbini City College BSc. CSIT Third Semester Presenter : Aashish Adhikari AASHISH ADHIKARI

2 AASHISH ADHIKARI [mail@aashishadhikari.info.np]
Contents Digital Differential Analyzer (DDA) Algorithm Working Principle Examples Bresenham’s Line Drawing Algorithm (BSA) AASHISH ADHIKARI

3 Working Principle of DDA Algorithm
Definition: The Digital Differential Analyzer(DDA) is a scan conversion line drawing algorithm based on calculating either Δx or Δy from the equation m = Δy/Δx. Algorithm Step 1: Input the line endpoints and store the left endpoint in (x0, y0) and right endpoint in (x1, y1). Step 2: Calculate the values of Δx and Δy, Δx = x1 – x0, Δy = y1 – y0 Step 3: Based on the calculated difference in step 2, now we need to identify the number of steps to put pixel as follows: If Δx > Δy, then we need more steps in x co-ordinate; otherwise in y coordinate. I.e. if (absolute(Δx) > absolute (Δy) ), then steps = absolute(Δx) else steps = absolute(Δy) Step 4: We calculate the increment in x coordinate and y coordinate as follows: xincreament = Δx 𝑆𝑡𝑒𝑝𝑠 𝑓𝑙𝑜𝑎𝑡 Yincreament = Δy 𝑆𝑡𝑒𝑝𝑠 𝑓𝑙𝑜𝑎𝑡 Step 5: Perform round off, and plot each calculated (x, y) i.e. Plot(round(x), round(y)). Step 6: END AASHISH ADHIKARI

4 Example 1 : ( For m<1 OR Δx>Δy)
* Using DDA Plot (5,4) to (12,7) Steps X Y Y(Rounded off) 5 4 1 6 4.4 2 7 4.8 3 8 5.2 9 5.6 10 11 6.4 12 6.8 Solution: Given, (x0, y0) = ( 5,4) (x1, y1) = ( 12,7) Δx = x1 – x0 = 12-5 = 7 Δy = y1 – y0 = 7-4 = 3 Since, Δx > Δy or, Slope m= Δy Δx = i.e. <1 So, no. of Steps= absolute (Δx) = |7| = 7 Now, xincreament = Δx 𝑆𝑡𝑒𝑝𝑠 𝑓𝑙𝑜𝑎𝑡 = = 1 Yincreament = Δy 𝑆𝑡𝑒𝑝𝑠 𝑓𝑙𝑜𝑎𝑡 = = 0.4 AASHISH ADHIKARI

5 Example 2 : ( For m>1 OR Δx<Δy)
* Using DDA Plot (5,7) to (10,15) Steps X Y Y(Rounded off) 5 7 1 5.6 8 6 2 6.2 9 3 6.8 10 4 7.4 11 12 8.6 13 9.2 14 9.8 15 Solution: Given, (x0, y0) = ( 5,7) (x1, y1) = ( 10,15) Δx = x1 – x0 = 10-5 = 5 Δy = y1 – y0 =15-7 = 8 Since, Δx < Δy or, Slope m= Δy Δx = i.e. >1 So, no. of Steps= absolute (Δy) = |8| = 8 Now, xincreament = Δx 𝑆𝑡𝑒𝑝𝑠 𝑓𝑙𝑜𝑎𝑡 = = 0.6 Yincreament = Δy 𝑆𝑡𝑒𝑝𝑠 𝑓𝑙𝑜𝑎𝑡 = =1 AASHISH ADHIKARI

6 AASHISH ADHIKARI [mail@aashishadhikari.info.np]
Working Principle of Bresenham’s Line Drawing Algorithm (BSA) [for positive slope questions] Definition: An accurate and efficient raster line-drawing algorithm, developed by Bresenham‘s. It only uses integer calculations so can be adapted to display circles and other curves. Algorithm Step 1: Input the line endpoints and store the left endpoint in (x0, y0) and right endpoint in (x1, y1). Step 2: Calculate the values of Δx and Δy, Δx = abs(x1 – x0), Δy = abs(y1 – y0) Step 3: Calculate initial decision parameter as, p = 2 Δy- Δx Step 4: if x1 > x0 then Set x= x0 Set y=y0 Set xend=x1 Otherwise Set x= x1 Set y=y1 Set xend=x0 Step 5: Draw pixel at (x,y) Algorithm Step 6: while(x<xend) x++; if p<0 then p=p+2Δy Otherwise y++ p=p+2Δy-2Δx Draw pixel at (x,y) Step 7: END AASHISH ADHIKARI

7 Example 1 : ( For m<=1 OR Δx>Δy)
* Digitize a line with end points (10,15) to (15,18) using BSA Solution: Given, (x0, y0) = ( 10,15) (x1, y1) = ( 15,18) Δx = x1 – x0 = |15-10| = 5 Δy = y1 – y0 = |18-15| = 3 Since, Slope m= Δy Δx <=1 So, we sample at x direction i.e., at each step we simply increment x-coordinate by 1 and find appropriate y-coordinate. First pixel to plot is (10,15), which is the starting endpoint. Now, initial decision parameter, p0 = 2 Δy- Δx = 2*3-5 = 1 We know that, If pk < 0, then we need to set pk+1 = pk+2△y and plot pixel(xk+1, yk) And if pk ≥ 0, then we need to set pk+1 = pk + 2 △y – 2 △x then plot pixel(xk+1, yk+1) Here p0 = 1, we have i.e., pk ≥0 So, p1 = p0 + 2 △y – 2 △x = * 3 – 2 x 5 = -3 p2 = p1+ 2 △y = -3+2 * 3 = 3. p3 = p2 + 2 △y – 2 △x = = -1. p4 = p3 + 2 △y = = 5 Successive pixel positions and decision parameter calculation is shown in the table. AASHISH ADHIKARI

8 AASHISH ADHIKARI [mail@aashishadhikari.info.np]
Working Principle of Bresenham’s Line Drawing Algorithm (BSA) [for negative slope questions] Algorithm Step 1: Input the line endpoints and store the left endpoint in (x0, y0) and right endpoint in (x1, y1). Step 2: Calculate the values of Δx and Δy, Δx = abs(x1 – x0), Δy = abs(y1 – y0) Step 3: Calculate initial decision parameter as, pk = 2 Δy- Δx Step 4: for (i=1 to Δx) { set pixel (xs, ys) while (pk>0) y0=y0-1; pk= pk-2 Δx end while, (pk>0) x0=x0+1 pk= pk+2 Δy i++; } set pixel (x0, y0) AASHISH ADHIKARI

9 Example 2 : ( For m>=1 OR Δx>Δy)
* Digitize a line with end points (6,12) to (10,5) using BSA Solution: Given, (x0, y0) = ( 6,12), (x1, y1) = ( 10,05) Now, We calculate the Δx and Δy as follows: Δx = x1 – x0 = |10-6| = 4, Δy = y1 – y0 = |5-12| = 7 Since, Slope m= Δy Δx >=1 So, we sample at x direction i.e., at each step we simply increment x-coordinate by 1 and find appropriate y-coordinate. First pixel to plot is (10,15), which is the starting endpoint. Now, initial decision parameter, p0 = 2 Δy- Δx = 2*7-4 = 10 For (i=1 to 4) using the condition we proceed as follows: For i=1 set pixel (6,12) while (10>0) y0= 12-1 = 11 pk= 10-2*4 = 2 while (2>0) y0= 11-1 =10 pk= 2-2*4 = -6 end while x0= x0+1 = 6+1 = 7 pk = pk+ 2 Δy = -6+2*7 = 8 Successive pixel positions and decision parameter calculation is shown in the table. I X0 Y0 Pk Points 1 6 12 10 (7,10) 2 7 8 (8,9) 3 9 14 (9,7) 4 (10,5) AASHISH ADHIKARI

10 Working Principle of Bresenham’s Line Drawing Algorithm (BSA) [for negative slope questions]
* Digitize a line with end points (6,12) to (10,5) using BSA ( For m>=1 OR Δx>Δy) Alternative Method AASHISH ADHIKARI

11 AASHISH ADHIKARI [mail@aashishadhikari.info.np]
Thanks AASHISH ADHIKARI


Download ppt "PRESENTATION Computer Graphics Lumbini City College"

Similar presentations


Ads by Google