SlideShare a Scribd company logo
3
Most read
6
Most read
7
Most read
Computer Graphics
PRESENTATION
Presenter :
• Aashish Adhikari
AASHISH ADHIKARI [mail@aashishadhikari.info.np]
• Digital Differential Analyzer (DDA) Algorithm
a. Working Principle
b. Examples
• Bresenham’s Line Drawing Algorithm (BSA)
a. Working Principle
b. Examples
Contents
AASHISH ADHIKARI [mail@aashishadhikari.info.np]
Working Principle of DDA Algorithm
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
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.
AASHISH ADHIKARI [mail@aashishadhikari.info.np]
Example 1 : ( For m<1 OR Δx>Δy)
* Using DDA Plot (5,4) to (12,7)
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
=
3
7
i.e. <1
So, no. of Steps= absolute (Δx)
= |7| = 7
Now,
xincreament =
Δx
𝑆𝑡𝑒𝑝𝑠 𝑓𝑙𝑜𝑎𝑡
=
7
7
= 1
Yincreament =
Δy
𝑆𝑡𝑒𝑝𝑠 𝑓𝑙𝑜𝑎𝑡
=
3
7
= 0.4
Steps X Y Y(Rounded off)
0 5 4 4
1 6 4.4 4
2 7 4.8 5
3 8 5.2 5
4 9 5.6 6
5 10 6 6
6 11 6.4 6
7 12 6.8 7
AASHISH ADHIKARI [mail@aashishadhikari.info.np]
Example 2 : ( For m>1 OR Δx<Δy)
* Using DDA Plot (5,7) to (10,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
=
8
5
i.e. >1
So, no. of Steps= absolute (Δy)
= |8| = 8
Now,
xincreament =
Δx
𝑆𝑡𝑒𝑝𝑠 𝑓𝑙𝑜𝑎𝑡
=
5
8
= 0.6
Yincreament =
Δy
𝑆𝑡𝑒𝑝𝑠 𝑓𝑙𝑜𝑎𝑡
=
8
8
=1
Steps X Y Y(Rounded off)
0 5 7 5
1 5.6 8 6
2 6.2 9 6
3 6.8 10 7
4 7.4 11 7
5 8 12 8
6 8.6 13 9
7 9.2 14 9
8 9.8 15 10
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.
AlgorithmAlgorithm
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)
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 [mail@aashishadhikari.info.np]
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 = 1 + 2 * 3 – 2 x 5 = -3
p2 = p1+ 2 △y = -3+2 * 3 = 3.
p3 = p2 + 2 △y – 2 △x = 3+6-10 = -1.
p4 = p3 + 2 △y = -1+ 6 = 5
Successive pixel positions and decision parameter calculation is shown in the table.
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 [mail@aashishadhikari.info.np]
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 10 8 (8,9)
3 8 9 14 (9,7)
4 9 7 12 (10,5)
AASHISH ADHIKARI [mail@aashishadhikari.info.np]
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 [mail@aashishadhikari.info.np]
Thanks
2020.04.19
AASHISH ADHIKARI [mail@aashishadhikari.info.np]

More Related Content

PDF
Addressing modes of 80386
PPTX
State space search and Problem Solving techniques
PPTX
Iot based health monitoring system
DOCX
Computer Graphics Lab File C Programs
PPTX
Addressing modes of 8086
PPTX
Automatic chocolate vending machine using mucos rtos ppt
PPTX
Physical design of io t
PDF
An introduction to MQTT
Addressing modes of 80386
State space search and Problem Solving techniques
Iot based health monitoring system
Computer Graphics Lab File C Programs
Addressing modes of 8086
Automatic chocolate vending machine using mucos rtos ppt
Physical design of io t
An introduction to MQTT

What's hot (20)

PPT
2D transformation (Computer Graphics)
PPTX
Ant colony optimization
PDF
Finite State Machines with Output
PPT
UDP and TCP header.ppt
PPTX
Presentation on 8086 Microprocessor
PPTX
Timing and control unit
PPTX
IOT System Management with NETCONF-YANG.pptx
PPTX
Microcontoller and Embedded System
PDF
Bus structure in Computer Organization.pdf
PPT
Pin Description Of Intel 80386 DX Microprocessor
PPTX
Presentation on arp protocol
PDF
8086 microprocessor lab manual
PDF
Arm instruction set
PPTX
PIC Microcontroller | ADC Interfacing
PPTX
INTERNAL STRUCTURE OF 8086 MICROPROCESSOR
PPTX
Local Area Network – Wired LAN
PPTX
Instruction Set Architecture
PPTX
convex hull
PPT
DSP architecture
2D transformation (Computer Graphics)
Ant colony optimization
Finite State Machines with Output
UDP and TCP header.ppt
Presentation on 8086 Microprocessor
Timing and control unit
IOT System Management with NETCONF-YANG.pptx
Microcontoller and Embedded System
Bus structure in Computer Organization.pdf
Pin Description Of Intel 80386 DX Microprocessor
Presentation on arp protocol
8086 microprocessor lab manual
Arm instruction set
PIC Microcontroller | ADC Interfacing
INTERNAL STRUCTURE OF 8086 MICROPROCESSOR
Local Area Network – Wired LAN
Instruction Set Architecture
convex hull
DSP architecture
Ad

Similar to Working principle of dda and bresenham line drawing explaination with example (20)

PPTX
Output primitives in Computer Graphics
PPT
2.Line,circle drawing.ppt line circlw drawing algorith
PDF
module 1.pdf
PDF
Computer Graphics_Module 2_Output Primitives.pdf
PPT
Line drawing algorithm and antialiasing techniques
PPTX
Chapter 3 - Part 1 [Autosaved].pptx
PDF
UNIT 4-geometry of which and line drawing.pdf
PPTX
L-6 (Circle Drawing Algorithm Computer graphics).pptx
PDF
Unit-2 raster scan graphics,line,circle and polygon algorithms
PPTX
Algorithm.pptx
PPTX
dddddddddddddddddddddddddddddddddddddddddddddddddddddAlgorithm.pptx
PPTX
Math is fun!
PPTX
DDA (Digital Differential Analyzer ) Line Drawing Algorithm.pptx
PPT
computer_graphics_line_algorithm in Computer Graphics
PDF
Open GL T0074 56 sm4
PDF
Computer Graphics Unit 2
PPTX
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
PDF
Bresenham derivation
PDF
Bresenham derivation
PDF
cgrchapter2version-1-200729063505 (1).pdf
Output primitives in Computer Graphics
2.Line,circle drawing.ppt line circlw drawing algorith
module 1.pdf
Computer Graphics_Module 2_Output Primitives.pdf
Line drawing algorithm and antialiasing techniques
Chapter 3 - Part 1 [Autosaved].pptx
UNIT 4-geometry of which and line drawing.pdf
L-6 (Circle Drawing Algorithm Computer graphics).pptx
Unit-2 raster scan graphics,line,circle and polygon algorithms
Algorithm.pptx
dddddddddddddddddddddddddddddddddddddddddddddddddddddAlgorithm.pptx
Math is fun!
DDA (Digital Differential Analyzer ) Line Drawing Algorithm.pptx
computer_graphics_line_algorithm in Computer Graphics
Open GL T0074 56 sm4
Computer Graphics Unit 2
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
Bresenham derivation
Bresenham derivation
cgrchapter2version-1-200729063505 (1).pdf
Ad

Recently uploaded (20)

PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Complications of Minimal Access Surgery at WLH
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
Cell Types and Its function , kingdom of life
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
Lesson notes of climatology university.
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Classroom Observation Tools for Teachers
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Cell Structure & Organelles in detailed.
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Basic Mud Logging Guide for educational purpose
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Complications of Minimal Access Surgery at WLH
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Renaissance Architecture: A Journey from Faith to Humanism
Cell Types and Its function , kingdom of life
2.FourierTransform-ShortQuestionswithAnswers.pdf
GDM (1) (1).pptx small presentation for students
Lesson notes of climatology university.
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Classroom Observation Tools for Teachers
TR - Agricultural Crops Production NC III.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Cell Structure & Organelles in detailed.
Abdominal Access Techniques with Prof. Dr. R K Mishra
Basic Mud Logging Guide for educational purpose
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPH.pptx obstetrics and gynecology in nursing
O5-L3 Freight Transport Ops (International) V1.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf

Working principle of dda and bresenham line drawing explaination with example

  • 1. Computer Graphics PRESENTATION Presenter : • Aashish Adhikari AASHISH ADHIKARI [mail@aashishadhikari.info.np]
  • 2. • Digital Differential Analyzer (DDA) Algorithm a. Working Principle b. Examples • Bresenham’s Line Drawing Algorithm (BSA) a. Working Principle b. Examples Contents AASHISH ADHIKARI [mail@aashishadhikari.info.np]
  • 3. Working Principle of DDA Algorithm 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 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. AASHISH ADHIKARI [mail@aashishadhikari.info.np]
  • 4. Example 1 : ( For m<1 OR Δx>Δy) * Using DDA Plot (5,4) to (12,7) 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 = 3 7 i.e. <1 So, no. of Steps= absolute (Δx) = |7| = 7 Now, xincreament = Δx 𝑆𝑡𝑒𝑝𝑠 𝑓𝑙𝑜𝑎𝑡 = 7 7 = 1 Yincreament = Δy 𝑆𝑡𝑒𝑝𝑠 𝑓𝑙𝑜𝑎𝑡 = 3 7 = 0.4 Steps X Y Y(Rounded off) 0 5 4 4 1 6 4.4 4 2 7 4.8 5 3 8 5.2 5 4 9 5.6 6 5 10 6 6 6 11 6.4 6 7 12 6.8 7 AASHISH ADHIKARI [mail@aashishadhikari.info.np]
  • 5. Example 2 : ( For m>1 OR Δx<Δy) * Using DDA Plot (5,7) to (10,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 = 8 5 i.e. >1 So, no. of Steps= absolute (Δy) = |8| = 8 Now, xincreament = Δx 𝑆𝑡𝑒𝑝𝑠 𝑓𝑙𝑜𝑎𝑡 = 5 8 = 0.6 Yincreament = Δy 𝑆𝑡𝑒𝑝𝑠 𝑓𝑙𝑜𝑎𝑡 = 8 8 =1 Steps X Y Y(Rounded off) 0 5 7 5 1 5.6 8 6 2 6.2 9 6 3 6.8 10 7 4 7.4 11 7 5 8 12 8 6 8.6 13 9 7 9.2 14 9 8 9.8 15 10 AASHISH ADHIKARI [mail@aashishadhikari.info.np]
  • 6. 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. AlgorithmAlgorithm 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) 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 [mail@aashishadhikari.info.np]
  • 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 = 1 + 2 * 3 – 2 x 5 = -3 p2 = p1+ 2 △y = -3+2 * 3 = 3. p3 = p2 + 2 △y – 2 △x = 3+6-10 = -1. p4 = p3 + 2 △y = -1+ 6 = 5 Successive pixel positions and decision parameter calculation is shown in the table. AASHISH ADHIKARI [mail@aashishadhikari.info.np]
  • 8. 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 [mail@aashishadhikari.info.np]
  • 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 10 8 (8,9) 3 8 9 14 (9,7) 4 9 7 12 (10,5) AASHISH ADHIKARI [mail@aashishadhikari.info.np]
  • 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 [mail@aashishadhikari.info.np]