SlideShare uma empresa Scribd logo
1 de 32
Baixar para ler offline
Computer Graphics:
Line Drawing Algorithms


           Sudipta Mondal



                Sudipta.hit@gmail.com
2
of
32
                                      Contents
     Graphics hardware
     The problem of scan conversion
     Considerations
     Line equations
     Scan converting algorithms
       – A very simple solution
       – The DDA algorithm
     Conclusion
3
                                                  of
                                                  32
                                                                                        Graphics Hardware
                                                                It’s worth taking a little look at how graphics
                                                                hardware works before we go any further
Images taken from Hearn & Baker, “Computer Graphics C version




                                                                How do things end up on the screen?
4
of
32
           Architecture Of A Graphics System


                Display
                           Frame        Video
               Processor                            Monitor
                Memory     Buffer      Controller



                Display       System
     CPU
               Processor      Memory



              System Bus
5
of
32
                                   Output Devices
     There are a range of output devices
     currently available:
        – Printers/plotters
        – Cathode ray tube displays
        – Plasma displays
        – LCD displays
        – 3 dimensional viewers
        – Virtual/augmented reality headsets
     We will look briefly at some of the more
     common display devices
6
                                                  of
                                                  32
                                                                       Basic Cathode Ray Tube (CRT)
                                                                Fire an electron beam at a phosphor coated
                                                                screen
Images taken from Hearn & Baker, “Computer Graphics C version
Images taken from Hearn & Baker, “Computer Graphics C version
                                                                                          7
                                                                                          of
                                                                                          32


                                                                Draw one line at a time
                                                                                          Raster Scan Systems
8
                                                  of
                                                  32
                                                                                                Colour CRT
                                                                An electron gun for each colour – red, green
                                                                and blue
Images taken from Hearn & Baker, “Computer Graphics C version
9
                                                  of
                                                  32
                                                                                 Plasma-Panel Displays
                                                                Applying voltages to
                                                                crossing pairs of
Images taken from Hearn & Baker, “Computer Graphics C version




                                                                conductors causes
                                                                the gas (usually a
                                                                mixture including
                                                                neon) to break
                                                                down into a glowing
                                                                plasma of electrons
                                                                and ions
10
                                                  of
                                                  32
                                                                Liquid Crystal Displays
                                                                      Light passing
                                                                      through the liquid
Images taken from Hearn & Baker, “Computer Graphics C version




                                                                      crystal is twisted
                                                                      so it gets through
                                                                      the polarizer
                                                                      A voltage is
                                                                      applied using the
                                                                      crisscrossing
                                                                      conductors to stop
                                                                      the twisting and
                                                                      turn pixels off
11
of
32
          The Problem Of Scan Conversion
     A line segment in a scene is defined by the
     coordinate positions of the line end-points
                y


                                 (7, 5)




                    (2, 2)

                                    x
12
of
32
                        The Problem (cont…)
     But what happens when we try to draw this
     on a pixel based display?




     How do we choose which pixels to turn on?
13
of
32
                                         Considerations
     Considerations to keep in mind:
       – The line has to look good
          • Avoid jaggies
       – It has to be lightening fast!
          • How many lines need to be drawn in a typical
            scene?
          • This is going to come back to bite us again and
            again
14
of
32
                                      Line Equations
     Let’s quickly review the equations involved
     in drawing lines
        y                    Slope-intercept line
                             equation:
     yend                            y = m× x +b
                                  where:
                                       yend - y0
      y0                            m=
                                       xend - x0
                                     b = y 0 - m × x0
                              x
            x0         xend
15
of
32
                                                Lines & Slopes
     The slope of a line (m) is defined by its start
     and end coordinates
     The diagram below shows some examples
     of lines and their slopes
                                         m=∞
                                m = -4         m=4
                           m = -2                m=2

                  m = -1                               m=1


          m = - 1 /2                                     m = 1 /2
         m = - 1 /3                                          m = 1 /3


          m=0                                                 m=0
16
of
32
                             A Very Simple Solution
     We could simply work out the corresponding
     y coordinate for each unit x coordinate
     Let’s consider the following example:
                y


                                        (7, 5)
                5




                2
                    (2, 2)


                                           x
                         2          7
17
of
32
             A Very Simple Solution (cont…)

     5


     4


     3


     2


     1


     0

         0     1   2   3   4   5   6   7
18
of
32
        A Very Simple Solution (cont…)
 y
                  (7, 5)
5                    First work out m and b:
                                5-2 3
                            m=       =
2
                                7-2 5
  (2, 2)
                                   3      4
                            b = 2- *2 =
       2 3 4 5 6 7
                   x               5      5
Now for each x value work out the y value:
            3     4    3           3     4    1
     y (3) = × 3 + = 2     y ( 4) = × 4 + = 3
            5     5    5           5     5    5
            3     4    4           3     4    2
     y (5) = × 5 + = 3     y (6) = × 6 + = 4
            5     5    5           5     5    5
19
of
32
                  A Very Simple Solution (cont…)
     Now just round off the results and turn on
     these pixels to draw our line
                                                       3
      7                                       y (3) = 2 » 3
      6                                                5
      5                                                1
      4
                                              y (4) = 3 » 3
                                                       5
      3
                                                       4
      2                                       y (5) = 3 » 4
      1                                                5
      0                                                2
                                              y (6) = 4 » 4
          0   1   2   3   4   5   6   7   8            5
20
of
32
            A Very Simple Solution (cont…)
     However, this approach is just way too slow
     In particular look out for:
        – The equation y = mx + b requires the
          multiplication of m by x
        – Rounding off the resulting y coordinates
     We need a faster solution
21
of
32
                  A Quick Note About Slopes
     In the previous example we chose to solve
     the parametric line equation to give us the y
     coordinate for each unit x coordinate
     What if we had done it the other way
     around?
                            y -b
     So this gives us: x =
                              m
                yend - y0
     where: m =           and b = y0 - m × x0
                xend - x0
22
of
32
       A Quick Note About Slopes (cont…)
     Leaving out the details this gives us:
                2                 1
        x(3) = 3 » 4    x ( 4) = 5 » 5
                3                 3
     We can see easily that     7
     this line doesn’t look     6
     very good!                 5
                                4
     We choose which way        3
     to work out the line       2

     pixels based on the        1
                                0
     slope of the line
                                    0   1   2   3   4   5   6   7   8
23
of
32
       A Quick Note About Slopes (cont…)
     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 we do the opposite – x coordinates
     are computed based on unit y coordinates
                                   m=∞
                          m = -4         m=4
                       m = -2              m=2
                  m = -1                         m=1

          m = - 1 /2                               m = 1 /2
          m = - 1 /3                                m = 1 /3


           m=0                                         m=0
24
of
32
     A Quick Note About Slopes (cont…)

     5


     4


     3


     2


     1


     0

         0   1   2   3   4   5   6   7
25
of
32
                             The DDA Algorithm
     The digital differential
     analyzer (DDA) algorithm
     takes an incremental
     approach in order to
     speed up scan conversion
                                The original differential
     Simply calculate yk+1      a n a l yze r w as a p h ys i c a l
     based on yk                machine developed by
                                Vannevar Bush at MIT in the
                                1930’s in order to sol ve
                                ordinary differential equations.
26
of
32
                    The DDA Algorithm (cont…)
     Consider the list of points that we
     determined for the line in our previous
     example:
        (2, 2), (3, 23/5), (4, 31/5), (5, 34/5), (6, 42/5), (7, 5)
     Notice that as the x coordinates go up by
     one, the y coordinates simply go up by the
     slope of the line
     This is the key insight in the DDA algorithm
27
of
32
                 The DDA Algorithm (cont…)
     When the slope of the line is between -1 and 1
     begin at the first point in the line and, by
     incrementing the x coordinate by 1, calculate
     the corresponding y coordinates as follows:
                    yk +1 = yk + m
     When the slope is outside these limits,
     increment the y coordinate by 1 and calculate
     the corresponding x coordinates as follows:
                                 1
                    xk +1 = xk +
                                 m
28
of
32
                       The DDA Algorithm (cont…)
     Again the values calculated by the equations
     used by the DDA algorithm must be rounded
     to match pixel values



(xk+1, round(yk+m))               (round(xk+ 1/m), yk+1)

(xk, yk)                                                   (xk+ 1/m, yk+1)
                   (xk+1, yk+m)           (xk, yk)


           (xk, round(yk))                            (round(xk), yk)
29
of
32
                       DDA Algorithm Example
     Let’s try out the following examples:
          y                             y   (2, 7)
                                    7


                           (7, 5)
      5




      2                             2
              (2, 2)                                 (3, 2)


                              x                               x
                   2   7                         2   3
30
of
32
         DDA Algorithm Example (cont…)

     7


     6


     5


     4


     3


     2

         0   1   2   3   4   5   6   7
31
of
32
                The DDA Algorithm Summary
     The DDA algorithm is much faster than our
     previous attempt
        – In particular, there are no longer any
          multiplications involved
     However, there are still two big issues:
        – Accumulation of round-off errors can make
          the pixelated line drift away from what was
          intended
        – The rounding operations and floating point
          arithmetic involved are time consuming
32
of
32
                                      Conclusion
     In this lecture we took a very brief look at
     how graphics hardware works
     Drawing lines to pixel based displays is time
     consuming so we need good ways to do it
     The DDA algorithm is pretty good – but we
     can do better
     Next time we’ll like at the Bresenham line
     algorithm and how to draw circles, fill
     polygons and anti-aliasing

Mais conteúdo relacionado

Mais procurados

Content based lcd backlight power reduction
Content based lcd backlight power reductionContent based lcd backlight power reduction
Content based lcd backlight power reductionRavi Dharawadkar
 
Wavelet video processing tecnology
Wavelet video processing tecnologyWavelet video processing tecnology
Wavelet video processing tecnologyPrashant Madnavat
 
Spandana image processing and compression techniques (7840228)
Spandana   image processing and compression techniques (7840228)Spandana   image processing and compression techniques (7840228)
Spandana image processing and compression techniques (7840228)indianspandana
 
Image processing1 introduction
Image processing1 introductionImage processing1 introduction
Image processing1 introductionPreeti Gupta
 
DWT Based Audio Watermarking Schemes : A Comparative Study
DWT Based Audio Watermarking Schemes : A Comparative Study DWT Based Audio Watermarking Schemes : A Comparative Study
DWT Based Audio Watermarking Schemes : A Comparative Study ijcisjournal
 
JPEG2000 in a nutshell
JPEG2000 in a nutshellJPEG2000 in a nutshell
JPEG2000 in a nutshellBenoit Michel
 
Digital video watermarking using modified lsb and dct technique
Digital video watermarking using modified lsb and dct techniqueDigital video watermarking using modified lsb and dct technique
Digital video watermarking using modified lsb and dct techniqueeSAT Publishing House
 
A Dual Tree Complex Wavelet Transform Construction and Its Application to Ima...
A Dual Tree Complex Wavelet Transform Construction and Its Application to Ima...A Dual Tree Complex Wavelet Transform Construction and Its Application to Ima...
A Dual Tree Complex Wavelet Transform Construction and Its Application to Ima...CSCJournals
 
image compression using matlab project report
image compression  using matlab project reportimage compression  using matlab project report
image compression using matlab project reportkgaurav113
 
Jpeg 2000 For Digital Archives
Jpeg 2000 For Digital ArchivesJpeg 2000 For Digital Archives
Jpeg 2000 For Digital ArchivesRichard Bernier
 
International Journal of Computational Engineering Research(IJCER)
International Journal of Computational Engineering Research(IJCER)International Journal of Computational Engineering Research(IJCER)
International Journal of Computational Engineering Research(IJCER)ijceronline
 
Springer base paper
Springer base paperSpringer base paper
Springer base paperchndu
 

Mais procurados (18)

Ld2519361941
Ld2519361941Ld2519361941
Ld2519361941
 
rapport
rapportrapport
rapport
 
Content based lcd backlight power reduction
Content based lcd backlight power reductionContent based lcd backlight power reduction
Content based lcd backlight power reduction
 
Jpeg2000
Jpeg2000Jpeg2000
Jpeg2000
 
Wavelet video processing tecnology
Wavelet video processing tecnologyWavelet video processing tecnology
Wavelet video processing tecnology
 
Spandana image processing and compression techniques (7840228)
Spandana   image processing and compression techniques (7840228)Spandana   image processing and compression techniques (7840228)
Spandana image processing and compression techniques (7840228)
 
Image processing1 introduction
Image processing1 introductionImage processing1 introduction
Image processing1 introduction
 
Ppt
PptPpt
Ppt
 
DWT Based Audio Watermarking Schemes : A Comparative Study
DWT Based Audio Watermarking Schemes : A Comparative Study DWT Based Audio Watermarking Schemes : A Comparative Study
DWT Based Audio Watermarking Schemes : A Comparative Study
 
D0941824
D0941824D0941824
D0941824
 
JPEG2000 in a nutshell
JPEG2000 in a nutshellJPEG2000 in a nutshell
JPEG2000 in a nutshell
 
Digital video watermarking using modified lsb and dct technique
Digital video watermarking using modified lsb and dct techniqueDigital video watermarking using modified lsb and dct technique
Digital video watermarking using modified lsb and dct technique
 
Dip review
Dip reviewDip review
Dip review
 
A Dual Tree Complex Wavelet Transform Construction and Its Application to Ima...
A Dual Tree Complex Wavelet Transform Construction and Its Application to Ima...A Dual Tree Complex Wavelet Transform Construction and Its Application to Ima...
A Dual Tree Complex Wavelet Transform Construction and Its Application to Ima...
 
image compression using matlab project report
image compression  using matlab project reportimage compression  using matlab project report
image compression using matlab project report
 
Jpeg 2000 For Digital Archives
Jpeg 2000 For Digital ArchivesJpeg 2000 For Digital Archives
Jpeg 2000 For Digital Archives
 
International Journal of Computational Engineering Research(IJCER)
International Journal of Computational Engineering Research(IJCER)International Journal of Computational Engineering Research(IJCER)
International Journal of Computational Engineering Research(IJCER)
 
Springer base paper
Springer base paperSpringer base paper
Springer base paper
 

Destaque

Lect5 filling color_models
Lect5 filling color_modelsLect5 filling color_models
Lect5 filling color_modelsBCET
 
Lect3 bresenham circlesandpolygons
Lect3 bresenham circlesandpolygonsLect3 bresenham circlesandpolygons
Lect3 bresenham circlesandpolygonsBCET
 
Windowing and clipping final1
Windowing and clipping final1Windowing and clipping final1
Windowing and clipping final1kparthjadhav
 
Open GL 09 scan conversion
Open GL 09 scan conversionOpen GL 09 scan conversion
Open GL 09 scan conversionRoziq Bahtiar
 
Lect7 viewing in2d
Lect7 viewing in2dLect7 viewing in2d
Lect7 viewing in2dBCET
 
Extended Context/Extended Media - Class 02
Extended Context/Extended Media - Class 02Extended Context/Extended Media - Class 02
Extended Context/Extended Media - Class 02Bryan Chung
 
Digital vs Analog
Digital vs AnalogDigital vs Analog
Digital vs AnalogCara Nason
 
Analog to Digital Converters
Analog to Digital ConvertersAnalog to Digital Converters
Analog to Digital ConvertersAnas Smarty
 
Cohen-sutherland & liang-basky line clipping algorithm
Cohen-sutherland & liang-basky line clipping algorithmCohen-sutherland & liang-basky line clipping algorithm
Cohen-sutherland & liang-basky line clipping algorithmShilpa Hait
 
Two dimensional viewing
Two dimensional viewingTwo dimensional viewing
Two dimensional viewingMohd Arif
 
Midpoint circle algo
Midpoint circle algoMidpoint circle algo
Midpoint circle algoMohd Arif
 
Clipping in Computer Graphics
Clipping in Computer GraphicsClipping in Computer Graphics
Clipping in Computer GraphicsLaxman Puri
 
Lecture 9 animation
Lecture 9 animationLecture 9 animation
Lecture 9 animationMr SMAK
 
Notes 2D-Transformation Unit 2 Computer graphics
Notes 2D-Transformation Unit 2 Computer graphicsNotes 2D-Transformation Unit 2 Computer graphics
Notes 2D-Transformation Unit 2 Computer graphicsNANDINI SHARMA
 

Destaque (20)

Lect5 filling color_models
Lect5 filling color_modelsLect5 filling color_models
Lect5 filling color_models
 
Lect3 bresenham circlesandpolygons
Lect3 bresenham circlesandpolygonsLect3 bresenham circlesandpolygons
Lect3 bresenham circlesandpolygons
 
Windowing and clipping final1
Windowing and clipping final1Windowing and clipping final1
Windowing and clipping final1
 
Open GL 09 scan conversion
Open GL 09 scan conversionOpen GL 09 scan conversion
Open GL 09 scan conversion
 
Lect7 viewing in2d
Lect7 viewing in2dLect7 viewing in2d
Lect7 viewing in2d
 
Extended Context/Extended Media - Class 02
Extended Context/Extended Media - Class 02Extended Context/Extended Media - Class 02
Extended Context/Extended Media - Class 02
 
Digital vs Analog
Digital vs AnalogDigital vs Analog
Digital vs Analog
 
Curve clipping
Curve clippingCurve clipping
Curve clipping
 
Clipping
ClippingClipping
Clipping
 
Analog to Digital Converters
Analog to Digital ConvertersAnalog to Digital Converters
Analog to Digital Converters
 
Cohen-sutherland & liang-basky line clipping algorithm
Cohen-sutherland & liang-basky line clipping algorithmCohen-sutherland & liang-basky line clipping algorithm
Cohen-sutherland & liang-basky line clipping algorithm
 
Two dimensional viewing
Two dimensional viewingTwo dimensional viewing
Two dimensional viewing
 
Midpoint circle algo
Midpoint circle algoMidpoint circle algo
Midpoint circle algo
 
Clipping in Computer Graphics
Clipping in Computer GraphicsClipping in Computer Graphics
Clipping in Computer Graphics
 
Windows and viewport
Windows and viewportWindows and viewport
Windows and viewport
 
Clipping
ClippingClipping
Clipping
 
Principles of animation
Principles of animationPrinciples of animation
Principles of animation
 
Lecture 9 animation
Lecture 9 animationLecture 9 animation
Lecture 9 animation
 
Curves and surfaces
Curves and surfacesCurves and surfaces
Curves and surfaces
 
Notes 2D-Transformation Unit 2 Computer graphics
Notes 2D-Transformation Unit 2 Computer graphicsNotes 2D-Transformation Unit 2 Computer graphics
Notes 2D-Transformation Unit 2 Computer graphics
 

Semelhante a Lect2 scan convertinglines

CG Lecture 1.pptx GRAPHIS VENNELA DONTHIREDDY
CG Lecture 1.pptx GRAPHIS VENNELA DONTHIREDDYCG Lecture 1.pptx GRAPHIS VENNELA DONTHIREDDY
CG Lecture 1.pptx GRAPHIS VENNELA DONTHIREDDYVenneladonthireddy1
 
Digital image processing using matlab
Digital image processing using matlab Digital image processing using matlab
Digital image processing using matlab Amr Rashed
 
Build Your Own 3D Scanner: Course Notes
Build Your Own 3D Scanner: Course NotesBuild Your Own 3D Scanner: Course Notes
Build Your Own 3D Scanner: Course NotesDouglas Lanman
 
Introduction with graphics
Introduction with graphicsIntroduction with graphics
Introduction with graphicsmsouravmishra
 
Image Access by PrintLAT
Image Access by PrintLATImage Access by PrintLAT
Image Access by PrintLATPrintLAT
 
Analysis of KinectFusion
Analysis of KinectFusionAnalysis of KinectFusion
Analysis of KinectFusionDong-Won Shin
 
A concept of graphics
A concept of graphicsA concept of graphics
A concept of graphicsmsouravmishra
 
การสอนครั้งที่ 2 intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิก
การสอนครั้งที่ 2   intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิกการสอนครั้งที่ 2   intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิก
การสอนครั้งที่ 2 intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิกjibbie23
 
การสอนครั้งที่ 2 intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิก
การสอนครั้งที่ 2   intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิกการสอนครั้งที่ 2   intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิก
การสอนครั้งที่ 2 intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิกjibbie23
 
การสอนครั้งที่ 2 intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิก
การสอนครั้งที่ 2   intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิกการสอนครั้งที่ 2   intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิก
การสอนครั้งที่ 2 intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิกjibbie23
 
การสอนครั้งที่ 2 intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิก
การสอนครั้งที่ 2   intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิกการสอนครั้งที่ 2   intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิก
การสอนครั้งที่ 2 intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิกjibbie23
 
การสอนครั้งที่ 2 intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิก
การสอนครั้งที่ 2   intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิกการสอนครั้งที่ 2   intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิก
การสอนครั้งที่ 2 intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิกjibbie23
 
Computer Graphics Interview Questions.pdf
Computer Graphics Interview Questions.pdfComputer Graphics Interview Questions.pdf
Computer Graphics Interview Questions.pdfAOUNHAIDER7
 

Semelhante a Lect2 scan convertinglines (18)

digital radiography
digital radiographydigital radiography
digital radiography
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
CG Lecture 1.pptx GRAPHIS VENNELA DONTHIREDDY
CG Lecture 1.pptx GRAPHIS VENNELA DONTHIREDDYCG Lecture 1.pptx GRAPHIS VENNELA DONTHIREDDY
CG Lecture 1.pptx GRAPHIS VENNELA DONTHIREDDY
 
Digital image processing using matlab
Digital image processing using matlab Digital image processing using matlab
Digital image processing using matlab
 
lecture2 computer graphics graphics hardware(Computer graphics tutorials)
 lecture2  computer graphics graphics hardware(Computer graphics tutorials) lecture2  computer graphics graphics hardware(Computer graphics tutorials)
lecture2 computer graphics graphics hardware(Computer graphics tutorials)
 
Build Your Own 3D Scanner: Course Notes
Build Your Own 3D Scanner: Course NotesBuild Your Own 3D Scanner: Course Notes
Build Your Own 3D Scanner: Course Notes
 
Introduction with graphics
Introduction with graphicsIntroduction with graphics
Introduction with graphics
 
Image Access by PrintLAT
Image Access by PrintLATImage Access by PrintLAT
Image Access by PrintLAT
 
Overview of Computer Graphics
Overview of Computer GraphicsOverview of Computer Graphics
Overview of Computer Graphics
 
Analysis of KinectFusion
Analysis of KinectFusionAnalysis of KinectFusion
Analysis of KinectFusion
 
A concept of graphics
A concept of graphicsA concept of graphics
A concept of graphics
 
Ei2004 presentation
Ei2004 presentationEi2004 presentation
Ei2004 presentation
 
การสอนครั้งที่ 2 intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิก
การสอนครั้งที่ 2   intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิกการสอนครั้งที่ 2   intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิก
การสอนครั้งที่ 2 intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิก
 
การสอนครั้งที่ 2 intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิก
การสอนครั้งที่ 2   intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิกการสอนครั้งที่ 2   intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิก
การสอนครั้งที่ 2 intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิก
 
การสอนครั้งที่ 2 intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิก
การสอนครั้งที่ 2   intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิกการสอนครั้งที่ 2   intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิก
การสอนครั้งที่ 2 intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิก
 
การสอนครั้งที่ 2 intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิก
การสอนครั้งที่ 2   intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิกการสอนครั้งที่ 2   intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิก
การสอนครั้งที่ 2 intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิก
 
การสอนครั้งที่ 2 intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิก
การสอนครั้งที่ 2   intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิกการสอนครั้งที่ 2   intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิก
การสอนครั้งที่ 2 intro ความรู้เบื้องต้นเกี่ยวกับคอมพิวเตอร์กราฟิก
 
Computer Graphics Interview Questions.pdf
Computer Graphics Interview Questions.pdfComputer Graphics Interview Questions.pdf
Computer Graphics Interview Questions.pdf
 

Mais de BCET

Lect11 clipping in3d
Lect11 clipping in3dLect11 clipping in3d
Lect11 clipping in3dBCET
 
Lect9 transformation3d
Lect9 transformation3dLect9 transformation3d
Lect9 transformation3dBCET
 
Lect8 viewing in3d&transformation
Lect8 viewing in3d&transformationLect8 viewing in3d&transformation
Lect8 viewing in3d&transformationBCET
 
Lect6 transformation2d
Lect6 transformation2dLect6 transformation2d
Lect6 transformation2dBCET
 
Lect4 ellipse
Lect4 ellipseLect4 ellipse
Lect4 ellipseBCET
 
Lect2 scan convertinglines
Lect2 scan convertinglinesLect2 scan convertinglines
Lect2 scan convertinglinesBCET
 
Light pens
Light pensLight pens
Light pensBCET
 
Lcd
LcdLcd
LcdBCET
 
Graphics inputdevices
Graphics inputdevicesGraphics inputdevices
Graphics inputdevicesBCET
 
Crt
CrtCrt
CrtBCET
 
Colour models
Colour modelsColour models
Colour modelsBCET
 
Cathode ray tube
Cathode ray tubeCathode ray tube
Cathode ray tubeBCET
 
Plasma display pannel
Plasma display pannelPlasma display pannel
Plasma display pannelBCET
 
php&mysql with Ethical Hacking
php&mysql with Ethical Hackingphp&mysql with Ethical Hacking
php&mysql with Ethical HackingBCET
 

Mais de BCET (14)

Lect11 clipping in3d
Lect11 clipping in3dLect11 clipping in3d
Lect11 clipping in3d
 
Lect9 transformation3d
Lect9 transformation3dLect9 transformation3d
Lect9 transformation3d
 
Lect8 viewing in3d&transformation
Lect8 viewing in3d&transformationLect8 viewing in3d&transformation
Lect8 viewing in3d&transformation
 
Lect6 transformation2d
Lect6 transformation2dLect6 transformation2d
Lect6 transformation2d
 
Lect4 ellipse
Lect4 ellipseLect4 ellipse
Lect4 ellipse
 
Lect2 scan convertinglines
Lect2 scan convertinglinesLect2 scan convertinglines
Lect2 scan convertinglines
 
Light pens
Light pensLight pens
Light pens
 
Lcd
LcdLcd
Lcd
 
Graphics inputdevices
Graphics inputdevicesGraphics inputdevices
Graphics inputdevices
 
Crt
CrtCrt
Crt
 
Colour models
Colour modelsColour models
Colour models
 
Cathode ray tube
Cathode ray tubeCathode ray tube
Cathode ray tube
 
Plasma display pannel
Plasma display pannelPlasma display pannel
Plasma display pannel
 
php&mysql with Ethical Hacking
php&mysql with Ethical Hackingphp&mysql with Ethical Hacking
php&mysql with Ethical Hacking
 

Lect2 scan convertinglines

  • 1. Computer Graphics: Line Drawing Algorithms Sudipta Mondal Sudipta.hit@gmail.com
  • 2. 2 of 32 Contents Graphics hardware The problem of scan conversion Considerations Line equations Scan converting algorithms – A very simple solution – The DDA algorithm Conclusion
  • 3. 3 of 32 Graphics Hardware It’s worth taking a little look at how graphics hardware works before we go any further Images taken from Hearn & Baker, “Computer Graphics C version How do things end up on the screen?
  • 4. 4 of 32 Architecture Of A Graphics System Display Frame Video Processor Monitor Memory Buffer Controller Display System CPU Processor Memory System Bus
  • 5. 5 of 32 Output Devices There are a range of output devices currently available: – Printers/plotters – Cathode ray tube displays – Plasma displays – LCD displays – 3 dimensional viewers – Virtual/augmented reality headsets We will look briefly at some of the more common display devices
  • 6. 6 of 32 Basic Cathode Ray Tube (CRT) Fire an electron beam at a phosphor coated screen Images taken from Hearn & Baker, “Computer Graphics C version
  • 7. Images taken from Hearn & Baker, “Computer Graphics C version 7 of 32 Draw one line at a time Raster Scan Systems
  • 8. 8 of 32 Colour CRT An electron gun for each colour – red, green and blue Images taken from Hearn & Baker, “Computer Graphics C version
  • 9. 9 of 32 Plasma-Panel Displays Applying voltages to crossing pairs of Images taken from Hearn & Baker, “Computer Graphics C version conductors causes the gas (usually a mixture including neon) to break down into a glowing plasma of electrons and ions
  • 10. 10 of 32 Liquid Crystal Displays Light passing through the liquid Images taken from Hearn & Baker, “Computer Graphics C version crystal is twisted so it gets through the polarizer A voltage is applied using the crisscrossing conductors to stop the twisting and turn pixels off
  • 11. 11 of 32 The Problem Of Scan Conversion A line segment in a scene is defined by the coordinate positions of the line end-points y (7, 5) (2, 2) x
  • 12. 12 of 32 The Problem (cont…) But what happens when we try to draw this on a pixel based display? How do we choose which pixels to turn on?
  • 13. 13 of 32 Considerations Considerations to keep in mind: – The line has to look good • Avoid jaggies – It has to be lightening fast! • How many lines need to be drawn in a typical scene? • This is going to come back to bite us again and again
  • 14. 14 of 32 Line Equations Let’s quickly review the equations involved in drawing lines y Slope-intercept line equation: yend y = m× x +b where: yend - y0 y0 m= xend - x0 b = y 0 - m × x0 x x0 xend
  • 15. 15 of 32 Lines & Slopes The slope of a line (m) is defined by its start and end coordinates The diagram below shows some examples of lines and their slopes m=∞ m = -4 m=4 m = -2 m=2 m = -1 m=1 m = - 1 /2 m = 1 /2 m = - 1 /3 m = 1 /3 m=0 m=0
  • 16. 16 of 32 A Very Simple Solution We could simply work out the corresponding y coordinate for each unit x coordinate Let’s consider the following example: y (7, 5) 5 2 (2, 2) x 2 7
  • 17. 17 of 32 A Very Simple Solution (cont…) 5 4 3 2 1 0 0 1 2 3 4 5 6 7
  • 18. 18 of 32 A Very Simple Solution (cont…) y (7, 5) 5 First work out m and b: 5-2 3 m= = 2 7-2 5 (2, 2) 3 4 b = 2- *2 = 2 3 4 5 6 7 x 5 5 Now for each x value work out the y value: 3 4 3 3 4 1 y (3) = × 3 + = 2 y ( 4) = × 4 + = 3 5 5 5 5 5 5 3 4 4 3 4 2 y (5) = × 5 + = 3 y (6) = × 6 + = 4 5 5 5 5 5 5
  • 19. 19 of 32 A Very Simple Solution (cont…) Now just round off the results and turn on these pixels to draw our line 3 7 y (3) = 2 » 3 6 5 5 1 4 y (4) = 3 » 3 5 3 4 2 y (5) = 3 » 4 1 5 0 2 y (6) = 4 » 4 0 1 2 3 4 5 6 7 8 5
  • 20. 20 of 32 A Very Simple Solution (cont…) However, this approach is just way too slow In particular look out for: – The equation y = mx + b requires the multiplication of m by x – Rounding off the resulting y coordinates We need a faster solution
  • 21. 21 of 32 A Quick Note About Slopes In the previous example we chose to solve the parametric line equation to give us the y coordinate for each unit x coordinate What if we had done it the other way around? y -b So this gives us: x = m yend - y0 where: m = and b = y0 - m × x0 xend - x0
  • 22. 22 of 32 A Quick Note About Slopes (cont…) Leaving out the details this gives us: 2 1 x(3) = 3 » 4 x ( 4) = 5 » 5 3 3 We can see easily that 7 this line doesn’t look 6 very good! 5 4 We choose which way 3 to work out the line 2 pixels based on the 1 0 slope of the line 0 1 2 3 4 5 6 7 8
  • 23. 23 of 32 A Quick Note About Slopes (cont…) 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 we do the opposite – x coordinates are computed based on unit y coordinates m=∞ m = -4 m=4 m = -2 m=2 m = -1 m=1 m = - 1 /2 m = 1 /2 m = - 1 /3 m = 1 /3 m=0 m=0
  • 24. 24 of 32 A Quick Note About Slopes (cont…) 5 4 3 2 1 0 0 1 2 3 4 5 6 7
  • 25. 25 of 32 The DDA Algorithm The digital differential analyzer (DDA) algorithm takes an incremental approach in order to speed up scan conversion The original differential Simply calculate yk+1 a n a l yze r w as a p h ys i c a l based on yk machine developed by Vannevar Bush at MIT in the 1930’s in order to sol ve ordinary differential equations.
  • 26. 26 of 32 The DDA Algorithm (cont…) Consider the list of points that we determined for the line in our previous example: (2, 2), (3, 23/5), (4, 31/5), (5, 34/5), (6, 42/5), (7, 5) Notice that as the x coordinates go up by one, the y coordinates simply go up by the slope of the line This is the key insight in the DDA algorithm
  • 27. 27 of 32 The DDA Algorithm (cont…) When the slope of the line is between -1 and 1 begin at the first point in the line and, by incrementing the x coordinate by 1, calculate the corresponding y coordinates as follows: yk +1 = yk + m When the slope is outside these limits, increment the y coordinate by 1 and calculate the corresponding x coordinates as follows: 1 xk +1 = xk + m
  • 28. 28 of 32 The DDA Algorithm (cont…) Again the values calculated by the equations used by the DDA algorithm must be rounded to match pixel values (xk+1, round(yk+m)) (round(xk+ 1/m), yk+1) (xk, yk) (xk+ 1/m, yk+1) (xk+1, yk+m) (xk, yk) (xk, round(yk)) (round(xk), yk)
  • 29. 29 of 32 DDA Algorithm Example Let’s try out the following examples: y y (2, 7) 7 (7, 5) 5 2 2 (2, 2) (3, 2) x x 2 7 2 3
  • 30. 30 of 32 DDA Algorithm Example (cont…) 7 6 5 4 3 2 0 1 2 3 4 5 6 7
  • 31. 31 of 32 The DDA Algorithm Summary The DDA algorithm is much faster than our previous attempt – In particular, there are no longer any multiplications involved However, there are still two big issues: – Accumulation of round-off errors can make the pixelated line drift away from what was intended – The rounding operations and floating point arithmetic involved are time consuming
  • 32. 32 of 32 Conclusion In this lecture we took a very brief look at how graphics hardware works Drawing lines to pixel based displays is time consuming so we need good ways to do it The DDA algorithm is pretty good – but we can do better Next time we’ll like at the Bresenham line algorithm and how to draw circles, fill polygons and anti-aliasing