SlideShare uma empresa Scribd logo
1 de 36
159.235 Graphics & Graphical  Programming Lecture 14 - Lines & Circles
Towards the Ideal Line ,[object Object],[object Object],[object Object]
What is an  ideal  line ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Simple Line Based on  slope-intercept algorithm  from algebra : y = mx + b Simple approach: increment x, solve for y Floating point arithmetic required
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.
Modify algorithm per octant OR, increment along x-axis if dy<dx else increment along y-axis
DDA algorithm ,[object Object],[object Object],[object Object],Start point - End point  -
DDA Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
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.
DDA algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object]
Observation on lines. while( n-- )  { draw(x,y); move right ; if(  below line  ) move up ; }
Testing for the side of a line. ,[object Object],[object Object],[object Object]
Testing for the side of a line. ,[object Object],[object Object],[object Object]
Decision variable. Previous Pixel ( x p ,y p ) Choices for Current pixel Choices for Next pixel Evaluate  F  at point M  Referred to as  decision variable M NE E
Decision variable. Evaluate d for next pixel, Depends on whether E or NE Is chosen : If E chosen : M E NE Previous Pixel (x p ,y p ) Choices for Current pixel Choices for Next pixel But recall : So :
Decision variable. If NE was chosen : M E NE Previous Pixel (x p ,y p ) Choices for Current pixel Choices for Next pixel So :
Summary of mid-point algorithm ,[object Object],[object Object],[object Object],[object Object]
Initial value of d. But  (x 1, y 1 ) is a point on the line, so F( x 1, y 1 ) =0 Conventional to multiply by 2 to remove fraction    doesn’t effect sign. Start point is  (x 1, y 1 )
Bresenham algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],while (x < x2) { if (d<= 0) { d+=incrE; x++ } else { d+=incrNE; x++; y++; } WritePixel(x,y); } }
Bresenham was not the end! 2-step algorithm by Xiaolin Wu: (see Graphics Gems 1, by Brian Wyvill) Treat line drawing as an automaton , or finite state machine, ie. looking at next two pixels of a line, easy to see that only a finite set of possibilities exist. The 2-step algorithm exploits symmetry by simultaneously drawing from both ends towards the midpoint.
Two-step Algorithm Possible positions of next two pixels dependent on slope – current pixel in blue: Slope between 0 and ½  Slope between ½ and 1 Slope between 1 and 2 Slope greater than 2
Circle drawing. ,[object Object],[object Object],Choices for Next pixel M E SE Previous Pixel Choices for Current pixel
Circle drawing. ,[object Object],[object Object],[object Object]
Problems with Bresenham algorithm ,[object Object],Pixel density = n pixels/mm Pixel density =   2.n pixels/mm Can draw lines in darker colours according to line direction. - Better solution : antialiasing !
Summary of line drawing so far. ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],Summary of aliasing.
Antialiasing ,[object Object],[object Object],[object Object],[object Object],[object Object],(Pixel Grid    Impulse) x line
Antialiasing ,[object Object],[object Object],[object Object],[object Object],(Line    Pixel) x impulse
Antialiasing lines. ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],1 pixel
Antialiasing by area sampling. ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Weighted area filtering. ,[object Object],[object Object],Lines are same distance from pixel centre, but  area of pixel covered is very different in the square case
Weighted area filtering. ,[object Object],[object Object],[object Object],[object Object],[object Object]
Gupta-Sproull algorithm. M NE Calculate distance using features of mid-point algorithm D Angle =   v dy dx E
Gupta-Sproull algorithm. Calculate distance using features of mid-point algorithm See Foley Van-Dam  Sec. 3.17 d is the decision variable.
Filter shape. ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Summary of antialiasing lines ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

Mais conteúdo relacionado

Mais procurados

Line drawing algo.
Line drawing algo.Line drawing algo.
Line drawing algo.
Mohd Arif
 
Lines and curves algorithms
Lines and curves algorithmsLines and curves algorithms
Lines and curves algorithms
Mohammad Sadiq
 

Mais procurados (20)

Line drawing algo.
Line drawing algo.Line drawing algo.
Line drawing algo.
 
A mid point ellipse drawing algorithm on a hexagonal grid
A mid  point ellipse drawing algorithm on a hexagonal gridA mid  point ellipse drawing algorithm on a hexagonal grid
A mid point ellipse drawing algorithm on a hexagonal grid
 
DDA (digital differential analyzer)
DDA (digital differential analyzer)DDA (digital differential analyzer)
DDA (digital differential analyzer)
 
Output primitives in Computer Graphics
Output primitives in Computer GraphicsOutput primitives in Computer Graphics
Output primitives in Computer Graphics
 
bresenham circles and polygons in computer graphics(Computer graphics tutorials)
bresenham circles and polygons in computer graphics(Computer graphics tutorials)bresenham circles and polygons in computer graphics(Computer graphics tutorials)
bresenham circles and polygons in computer graphics(Computer graphics tutorials)
 
DDA algorithm
DDA algorithmDDA algorithm
DDA algorithm
 
Dda algorithm
Dda algorithmDda algorithm
Dda algorithm
 
Unit 3
Unit 3Unit 3
Unit 3
 
Dda line algorithm presentatiion
Dda line algorithm presentatiionDda line algorithm presentatiion
Dda line algorithm presentatiion
 
Line Detection
Line DetectionLine Detection
Line Detection
 
Computer vision lane line detection
Computer vision lane line detectionComputer vision lane line detection
Computer vision lane line detection
 
Image enhancement
Image enhancementImage enhancement
Image enhancement
 
Lab lecture 1 line_algo
Lab lecture 1 line_algoLab lecture 1 line_algo
Lab lecture 1 line_algo
 
Dda algo notes
Dda algo notesDda algo notes
Dda algo notes
 
BRESENHAM’S LINE DRAWING ALGORITHM
BRESENHAM’S  LINE DRAWING ALGORITHMBRESENHAM’S  LINE DRAWING ALGORITHM
BRESENHAM’S LINE DRAWING ALGORITHM
 
Histogram processing
Histogram processingHistogram processing
Histogram processing
 
COMPUTER GRAPHICS
COMPUTER GRAPHICSCOMPUTER GRAPHICS
COMPUTER GRAPHICS
 
Lines and curves algorithms
Lines and curves algorithmsLines and curves algorithms
Lines and curves algorithms
 
Chapter 2 Image Processing: Pixel Relation
Chapter 2 Image Processing: Pixel RelationChapter 2 Image Processing: Pixel Relation
Chapter 2 Image Processing: Pixel Relation
 
Lec02 03 rasterization
Lec02 03 rasterizationLec02 03 rasterization
Lec02 03 rasterization
 

Destaque (12)

Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
 
Lab lecture 2 bresenham
Lab lecture 2 bresenhamLab lecture 2 bresenham
Lab lecture 2 bresenham
 
Bresenham circles and polygons derication
Bresenham circles and polygons dericationBresenham circles and polygons derication
Bresenham circles and polygons derication
 
Bresenham Line Drawing Algorithm
Bresenham Line Drawing AlgorithmBresenham Line Drawing Algorithm
Bresenham Line Drawing Algorithm
 
Anti aliasing Computer Graphics
Anti aliasing Computer GraphicsAnti aliasing Computer Graphics
Anti aliasing Computer Graphics
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
Anti aliasing
Anti aliasingAnti aliasing
Anti aliasing
 
Antialiasing
Antialiasing  Antialiasing
Antialiasing
 
Image enhancement
Image enhancementImage enhancement
Image enhancement
 
Introduction to Data Mining and Big Data Analytics
Introduction to Data Mining and Big Data AnalyticsIntroduction to Data Mining and Big Data Analytics
Introduction to Data Mining and Big Data Analytics
 
Introduction to Computer graphics
Introduction to Computer graphics Introduction to Computer graphics
Introduction to Computer graphics
 
Data mining slides
Data mining slidesData mining slides
Data mining slides
 

Semelhante a Lect14 lines+circles

Bresenham circlesandpolygons
Bresenham circlesandpolygonsBresenham circlesandpolygons
Bresenham circlesandpolygons
aa11bb11
 
Lec02 03 rasterization
Lec02 03 rasterizationLec02 03 rasterization
Lec02 03 rasterization
Maaz Rizwan
 
ImageSegmentation (1).ppt
ImageSegmentation (1).pptImageSegmentation (1).ppt
ImageSegmentation (1).ppt
NoorUlHaq47
 
Open GL T0074 56 sm3
Open GL T0074 56 sm3Open GL T0074 56 sm3
Open GL T0074 56 sm3
Roziq Bahtiar
 
Kulum alin-11 jan2014
Kulum alin-11 jan2014Kulum alin-11 jan2014
Kulum alin-11 jan2014
rolly purnomo
 

Semelhante a Lect14 lines+circles (20)

1536 graphics &amp; graphical programming
1536 graphics &amp; graphical  programming1536 graphics &amp; graphical  programming
1536 graphics &amp; graphical programming
 
99995320.ppt
99995320.ppt99995320.ppt
99995320.ppt
 
Bresenham circlesandpolygons
Bresenham circlesandpolygonsBresenham circlesandpolygons
Bresenham circlesandpolygons
 
Lec02 03 rasterization
Lec02 03 rasterizationLec02 03 rasterization
Lec02 03 rasterization
 
03.Scan Conversion.ppt
03.Scan Conversion.ppt03.Scan Conversion.ppt
03.Scan Conversion.ppt
 
Shi.pdf
Shi.pdfShi.pdf
Shi.pdf
 
ImageSegmentation (1).ppt
ImageSegmentation (1).pptImageSegmentation (1).ppt
ImageSegmentation (1).ppt
 
ImageSegmentation.ppt
ImageSegmentation.pptImageSegmentation.ppt
ImageSegmentation.ppt
 
ImageSegmentation.ppt
ImageSegmentation.pptImageSegmentation.ppt
ImageSegmentation.ppt
 
Image segmentation
Image segmentationImage segmentation
Image segmentation
 
Computer graphics notes
Computer graphics notesComputer graphics notes
Computer graphics notes
 
Computer Graphics - Introduction in Brief By: Prof. Manisha Waghmare- Butkar
Computer Graphics - Introduction in Brief By: Prof. Manisha Waghmare- ButkarComputer Graphics - Introduction in Brief By: Prof. Manisha Waghmare- Butkar
Computer Graphics - Introduction in Brief By: Prof. Manisha Waghmare- Butkar
 
Open GL T0074 56 sm3
Open GL T0074 56 sm3Open GL T0074 56 sm3
Open GL T0074 56 sm3
 
Computer Graphics Notes 2.pdf
Computer Graphics Notes 2.pdfComputer Graphics Notes 2.pdf
Computer Graphics Notes 2.pdf
 
Unit 2
Unit 2Unit 2
Unit 2
 
dokumen.tips_scan-conversion-568812b73d987.ppt
dokumen.tips_scan-conversion-568812b73d987.pptdokumen.tips_scan-conversion-568812b73d987.ppt
dokumen.tips_scan-conversion-568812b73d987.ppt
 
raster algorithm.pdf
raster algorithm.pdfraster algorithm.pdf
raster algorithm.pdf
 
Kulum alin-11 jan2014
Kulum alin-11 jan2014Kulum alin-11 jan2014
Kulum alin-11 jan2014
 
Computer graphics notes watermark
Computer graphics notes watermarkComputer graphics notes watermark
Computer graphics notes watermark
 
Two Dimensional Shape and Texture Quantification - Medical Image Processing
Two Dimensional Shape and Texture Quantification - Medical Image ProcessingTwo Dimensional Shape and Texture Quantification - Medical Image Processing
Two Dimensional Shape and Texture Quantification - Medical Image Processing
 

Último

Último (20)

Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
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...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
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
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
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
 
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...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
🐬 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 New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 

Lect14 lines+circles

  • 1. 159.235 Graphics & Graphical Programming Lecture 14 - Lines & Circles
  • 2.
  • 3.
  • 4. Simple Line Based on slope-intercept algorithm from algebra : y = mx + b Simple approach: increment x, solve for y Floating point arithmetic required
  • 5. 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.
  • 6. Modify algorithm per octant OR, increment along x-axis if dy<dx else increment along y-axis
  • 7.
  • 8.
  • 9. 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.
  • 10.
  • 11. Observation on lines. while( n-- ) { draw(x,y); move right ; if( below line ) move up ; }
  • 12.
  • 13.
  • 14. Decision variable. Previous Pixel ( x p ,y p ) Choices for Current pixel Choices for Next pixel Evaluate F at point M Referred to as decision variable M NE E
  • 15. Decision variable. Evaluate d for next pixel, Depends on whether E or NE Is chosen : If E chosen : M E NE Previous Pixel (x p ,y p ) Choices for Current pixel Choices for Next pixel But recall : So :
  • 16. Decision variable. If NE was chosen : M E NE Previous Pixel (x p ,y p ) Choices for Current pixel Choices for Next pixel So :
  • 17.
  • 18. Initial value of d. But (x 1, y 1 ) is a point on the line, so F( x 1, y 1 ) =0 Conventional to multiply by 2 to remove fraction  doesn’t effect sign. Start point is (x 1, y 1 )
  • 19.
  • 20. Bresenham was not the end! 2-step algorithm by Xiaolin Wu: (see Graphics Gems 1, by Brian Wyvill) Treat line drawing as an automaton , or finite state machine, ie. looking at next two pixels of a line, easy to see that only a finite set of possibilities exist. The 2-step algorithm exploits symmetry by simultaneously drawing from both ends towards the midpoint.
  • 21. Two-step Algorithm Possible positions of next two pixels dependent on slope – current pixel in blue: Slope between 0 and ½ Slope between ½ and 1 Slope between 1 and 2 Slope greater than 2
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33. Gupta-Sproull algorithm. M NE Calculate distance using features of mid-point algorithm D Angle =  v dy dx E
  • 34. Gupta-Sproull algorithm. Calculate distance using features of mid-point algorithm See Foley Van-Dam Sec. 3.17 d is the decision variable.
  • 35.
  • 36.

Notas do Editor

  1. Important algorithm.
  2. Very important.
  3. This is all you need to know on aliasing.
  4. Not examinable.
  5. Only principle of this method important.