SlideShare ist ein Scribd-Unternehmen logo
1 von 17
A. A. Datti 2018
HTML5 Canvas
Wall Clock
Rasterization
2D Transformations
2
3
• Recall that a digital output device is arranged in form
of a rectangular grid of pixels call the raster
x
y
4
• Hence the reason an image appears ‘pixelated’ when
you zoom in:
5
• A line segment in a scene is defined by the coordinate
positions of the line end-points
x
y
(2, 2)
(7, 5)
6
• But what happens when we try to draw
this on a pixel based display?
• How do we choose which pixels to turn on?
Brute Force Line Drawing Algorithm
 The starting point is the equation of a straight line:
 where m, the gradient of the line is:
 and c, its intercept of the y-axis is:
8
x
y
(2, 2)
(7, 5)
2 3 4 5 6 7
2
5
6
.
0
5
3
2
7
2
5





m
8
.
0
5
4
2
5
3
2 




c
• First work out m and c:
• Now for each x value work out the y value:
6
.
2
5
3
2
5
4
3
5
3
)
3
( 




y 2
.
3
5
1
3
5
4
4
5
3
)
4
( 




y
8
.
3
5
4
3
5
4
5
5
3
)
5
( 




y 4
.
4
5
2
4
5
4
6
5
3
)
6
( 




y
Brute Force Line Drawing Algorithm
9
Now just round off the results and turn on these
pixels to draw our line
3
5
3
2
)
3
( 

y
3
5
1
3
)
4
( 

y
4
5
4
3
)
5
( 

y
4
5
2
4
)
6
( 

y
0 1 2 3 4 5 6 7 8
0
1
2
3
4
5
6
7
Brute Force Line Drawing Algorithm
 The routine (in pseudo code) to draw a line might look like this:
 method lineDraw(x0,y0,x1,y1)
 {
DeltaY = y1-y0;
DeltaX = x1-x0;
m = DeltaY/DeltaX;
c = y0 - (m*x0);
for(int x=x0; x<x1; x++) {
y=(m*x) + c;
plotPoint(x,y)
}
}
11
Observations
 Simple Implementation
 Gaps
 Vertical and Horizontal Lines
 High Computational Cost due to floating Point Arithmetic
 Integer Arithmetic is much faster.
12
If the slope of a line is between -1 and 1 then we work out the y
coordinates for a line based on it’s unit x coordinates. Otherwise
gaps will appear.
To solve this we do the opposite – x coordinates are computed
based on unit y coordinates
m = 0
m = -1/3
m = -1/2
m = -1
m = -2
m = -4
m = ∞
m = 1/3
m = 1/2
m = 1
m = 2
m = 4
m = 0
Reducing Gaps
13
Incremental algorithm - Each iteration is based on the
preceding step
yk =mxk+c
yk+1 =mxk+1+c
=m(xk+dx)+c
=mxk+c+mdx
=yk+mdx
If dx=1, then yk+1=yk+m
A unit change in x changes y by m
The slope of the line m needs to be computed just once
14
Again the values calculated by the equations used by the
DDA algorithm must be rounded to match pixel values
(xk, yk)
(xk+1, yk+m)
(xk, round(yk))
(xk+1, round(yk+m))
(xk, yk) (xk+ 1/m, yk+1)
(round(xk), yk)
(round(xk+ 1/m), yk+1)
15
compute m;
if m < 1:
{
float y = y0; // initial value
for(int x = x0;x <= x1; x++){
y += m;
setPixel(x, round(y));
}
}
else // m > 1
{
float x = x0; // initial value
for(int y = y0;y <= y1; y++){
x += 1/m;
setPixel(round(x), y);
}
}
16
How is DDA better than Brute Force?
What are the set of pixels to be activated when a line
between (20,10) and (30,18) is being drawn using:
Brute Force Line drawing algorithm?
DDA Line drawing algorithm?

Weitere ähnliche Inhalte

Ähnlich wie HTML5 Canvas Wall Clock Rasterization 2D Transformations

Computer Graphics Unit 1
Computer Graphics Unit 1Computer Graphics Unit 1
Computer Graphics Unit 1aravindangc
 
Output primitives in Computer Graphics
Output primitives in Computer GraphicsOutput primitives in Computer Graphics
Output primitives in Computer GraphicsKamal Acharya
 
Output primitives computer graphics c version
Output primitives   computer graphics c versionOutput primitives   computer graphics c version
Output primitives computer graphics c versionMarwa Al-Rikaby
 
Lab lecture 1 line_algo
Lab lecture 1 line_algoLab lecture 1 line_algo
Lab lecture 1 line_algosimpleok
 
Chapter 3 Output Primitives
Chapter 3 Output PrimitivesChapter 3 Output Primitives
Chapter 3 Output PrimitivesPrathimaBaliga
 
Output Primitives in Computer Graphics and Multimedia
Output Primitives in Computer Graphics and MultimediaOutput Primitives in Computer Graphics and Multimedia
Output Primitives in Computer Graphics and Multimediasaranyan75
 
Computer Graphics and Multimedia Output primitives
Computer Graphics and Multimedia Output primitivesComputer Graphics and Multimedia Output primitives
Computer Graphics and Multimedia Output primitivessaranyan75
 
Bresenham circlesandpolygons
Bresenham circlesandpolygonsBresenham circlesandpolygons
Bresenham circlesandpolygonsaa11bb11
 
Bresenham circles and polygons derication
Bresenham circles and polygons dericationBresenham circles and polygons derication
Bresenham circles and polygons dericationKumar
 
elementry-objects-CG give great effort on learning for exam
elementry-objects-CG give great effort on learning for examelementry-objects-CG give great effort on learning for exam
elementry-objects-CG give great effort on learning for examtigag49721
 
Lecture _Line Scan Conversion.ppt
Lecture _Line Scan Conversion.pptLecture _Line Scan Conversion.ppt
Lecture _Line Scan Conversion.pptGaganvirKaur
 
Line drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniquesLine drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniquesAnkit Garg
 
Chapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptxChapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptxKokebe2
 
Line drawing algo.
Line drawing algo.Line drawing algo.
Line drawing algo.Mohd Arif
 
OUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptxOUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptxIndhuMcamphil
 
OUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptxOUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptxAlamelu
 
Computer graphics LINE DRAWING algorithm.pptx
Computer graphics LINE DRAWING algorithm.pptxComputer graphics LINE DRAWING algorithm.pptx
Computer graphics LINE DRAWING algorithm.pptxR S Anu Prabha
 

Ähnlich wie HTML5 Canvas Wall Clock Rasterization 2D Transformations (20)

Computer Graphics Unit 1
Computer Graphics Unit 1Computer Graphics Unit 1
Computer Graphics Unit 1
 
Output primitives in Computer Graphics
Output primitives in Computer GraphicsOutput primitives in Computer Graphics
Output primitives in Computer Graphics
 
Output primitives computer graphics c version
Output primitives   computer graphics c versionOutput primitives   computer graphics c version
Output primitives computer graphics c version
 
Lab lecture 1 line_algo
Lab lecture 1 line_algoLab lecture 1 line_algo
Lab lecture 1 line_algo
 
raster algorithm.pdf
raster algorithm.pdfraster algorithm.pdf
raster algorithm.pdf
 
Chapter 3 Output Primitives
Chapter 3 Output PrimitivesChapter 3 Output Primitives
Chapter 3 Output Primitives
 
Output Primitives in Computer Graphics and Multimedia
Output Primitives in Computer Graphics and MultimediaOutput Primitives in Computer Graphics and Multimedia
Output Primitives in Computer Graphics and Multimedia
 
Computer Graphics and Multimedia Output primitives
Computer Graphics and Multimedia Output primitivesComputer Graphics and Multimedia Output primitives
Computer Graphics and Multimedia Output primitives
 
Bresenham circlesandpolygons
Bresenham circlesandpolygonsBresenham circlesandpolygons
Bresenham circlesandpolygons
 
Bresenham circles and polygons derication
Bresenham circles and polygons dericationBresenham circles and polygons derication
Bresenham circles and polygons derication
 
elementry-objects-CG give great effort on learning for exam
elementry-objects-CG give great effort on learning for examelementry-objects-CG give great effort on learning for exam
elementry-objects-CG give great effort on learning for exam
 
Lecture _Line Scan Conversion.ppt
Lecture _Line Scan Conversion.pptLecture _Line Scan Conversion.ppt
Lecture _Line Scan Conversion.ppt
 
Line drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniquesLine drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniques
 
Chapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptxChapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptx
 
Line drawing algo.
Line drawing algo.Line drawing algo.
Line drawing algo.
 
OUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptxOUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptx
 
OUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptxOUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptx
 
Primitives
PrimitivesPrimitives
Primitives
 
Computer graphics LINE DRAWING algorithm.pptx
Computer graphics LINE DRAWING algorithm.pptxComputer graphics LINE DRAWING algorithm.pptx
Computer graphics LINE DRAWING algorithm.pptx
 
03.Scan Conversion.ppt
03.Scan Conversion.ppt03.Scan Conversion.ppt
03.Scan Conversion.ppt
 

Mehr von AhmadAbba6

Transmission Medium.pptx
Transmission Medium.pptxTransmission Medium.pptx
Transmission Medium.pptxAhmadAbba6
 
Network Models.pptx
Network  Models.pptxNetwork  Models.pptx
Network Models.pptxAhmadAbba6
 
Basic Concepts of Networking.pptx
Basic Concepts of Networking.pptxBasic Concepts of Networking.pptx
Basic Concepts of Networking.pptxAhmadAbba6
 
HTML5 Canvas - Basics.pptx
HTML5 Canvas - Basics.pptxHTML5 Canvas - Basics.pptx
HTML5 Canvas - Basics.pptxAhmadAbba6
 
Introduction to Computer Graphics.pptx
Introduction to Computer Graphics.pptxIntroduction to Computer Graphics.pptx
Introduction to Computer Graphics.pptxAhmadAbba6
 
HTML5 Canvas (Wall Clock).pptx
HTML5 Canvas (Wall Clock).pptxHTML5 Canvas (Wall Clock).pptx
HTML5 Canvas (Wall Clock).pptxAhmadAbba6
 

Mehr von AhmadAbba6 (6)

Transmission Medium.pptx
Transmission Medium.pptxTransmission Medium.pptx
Transmission Medium.pptx
 
Network Models.pptx
Network  Models.pptxNetwork  Models.pptx
Network Models.pptx
 
Basic Concepts of Networking.pptx
Basic Concepts of Networking.pptxBasic Concepts of Networking.pptx
Basic Concepts of Networking.pptx
 
HTML5 Canvas - Basics.pptx
HTML5 Canvas - Basics.pptxHTML5 Canvas - Basics.pptx
HTML5 Canvas - Basics.pptx
 
Introduction to Computer Graphics.pptx
Introduction to Computer Graphics.pptxIntroduction to Computer Graphics.pptx
Introduction to Computer Graphics.pptx
 
HTML5 Canvas (Wall Clock).pptx
HTML5 Canvas (Wall Clock).pptxHTML5 Canvas (Wall Clock).pptx
HTML5 Canvas (Wall Clock).pptx
 

Kürzlich hochgeladen

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 

Kürzlich hochgeladen (20)

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 

HTML5 Canvas Wall Clock Rasterization 2D Transformations

  • 1. A. A. Datti 2018
  • 3. 3 • Recall that a digital output device is arranged in form of a rectangular grid of pixels call the raster x y
  • 4. 4 • Hence the reason an image appears ‘pixelated’ when you zoom in:
  • 5. 5 • A line segment in a scene is defined by the coordinate positions of the line end-points x y (2, 2) (7, 5)
  • 6. 6 • But what happens when we try to draw this on a pixel based display? • How do we choose which pixels to turn on? Brute Force Line Drawing Algorithm
  • 7.  The starting point is the equation of a straight line:  where m, the gradient of the line is:  and c, its intercept of the y-axis is:
  • 8. 8 x y (2, 2) (7, 5) 2 3 4 5 6 7 2 5 6 . 0 5 3 2 7 2 5      m 8 . 0 5 4 2 5 3 2      c • First work out m and c: • Now for each x value work out the y value: 6 . 2 5 3 2 5 4 3 5 3 ) 3 (      y 2 . 3 5 1 3 5 4 4 5 3 ) 4 (      y 8 . 3 5 4 3 5 4 5 5 3 ) 5 (      y 4 . 4 5 2 4 5 4 6 5 3 ) 6 (      y Brute Force Line Drawing Algorithm
  • 9. 9 Now just round off the results and turn on these pixels to draw our line 3 5 3 2 ) 3 (   y 3 5 1 3 ) 4 (   y 4 5 4 3 ) 5 (   y 4 5 2 4 ) 6 (   y 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 Brute Force Line Drawing Algorithm
  • 10.  The routine (in pseudo code) to draw a line might look like this:  method lineDraw(x0,y0,x1,y1)  { DeltaY = y1-y0; DeltaX = x1-x0; m = DeltaY/DeltaX; c = y0 - (m*x0); for(int x=x0; x<x1; x++) { y=(m*x) + c; plotPoint(x,y) } }
  • 11. 11 Observations  Simple Implementation  Gaps  Vertical and Horizontal Lines  High Computational Cost due to floating Point Arithmetic  Integer Arithmetic is much faster.
  • 12. 12 If the slope of a line is between -1 and 1 then we work out the y coordinates for a line based on it’s unit x coordinates. Otherwise gaps will appear. To solve this we do the opposite – x coordinates are computed based on unit y coordinates m = 0 m = -1/3 m = -1/2 m = -1 m = -2 m = -4 m = ∞ m = 1/3 m = 1/2 m = 1 m = 2 m = 4 m = 0 Reducing Gaps
  • 13. 13 Incremental algorithm - Each iteration is based on the preceding step yk =mxk+c yk+1 =mxk+1+c =m(xk+dx)+c =mxk+c+mdx =yk+mdx If dx=1, then yk+1=yk+m A unit change in x changes y by m The slope of the line m needs to be computed just once
  • 14. 14 Again the values calculated by the equations used by the DDA algorithm must be rounded to match pixel values (xk, yk) (xk+1, yk+m) (xk, round(yk)) (xk+1, round(yk+m)) (xk, yk) (xk+ 1/m, yk+1) (round(xk), yk) (round(xk+ 1/m), yk+1)
  • 15. 15 compute m; if m < 1: { float y = y0; // initial value for(int x = x0;x <= x1; x++){ y += m; setPixel(x, round(y)); } } else // m > 1 { float x = x0; // initial value for(int y = y0;y <= y1; y++){ x += 1/m; setPixel(round(x), y); } }
  • 16. 16 How is DDA better than Brute Force?
  • 17. What are the set of pixels to be activated when a line between (20,10) and (30,18) is being drawn using: Brute Force Line drawing algorithm? DDA Line drawing algorithm?