rasterisation - university of exeterempslocal.ex.ac.uk/people/staff/pjk205/ecm2410/slides07.pdf ·...
TRANSCRIPT
ECM2410: Graphics and Animation
Rasterisation
Part I: Simple Lines
Rasterisation 1/16
Rendering a scene
User space Device space
Compose Render
Affine transformation
Transform
Compose from primitives (lines, ellipses, etc) in user space.
Transform affine transformations:lines→ lines;ellipses→ ellipses
Render primitives on device.Rasterisation Line Rasterisation 2/16
Rendering a scene
User space Device space
Compose Render
Affine transformation
Transform
Compose from primitives (lines, ellipses, etc) in user space.
Transform affine transformations:lines→ lines;ellipses→ ellipses
Render primitives on device.Rasterisation Line Rasterisation 2/16
Rendering a scene
User space Device space
Compose Render
Affine transformation
Transform
Compose from primitives (lines, ellipses, etc) in user space.
Transform affine transformations:lines→ lines;ellipses→ ellipses
Render primitives on device.Rasterisation Line Rasterisation 2/16
Rendering a scene
User space Device space
Compose Render
Affine transformation
Transform
Compose from primitives (lines, ellipses, etc) in user space.
Transform affine transformations:lines→ lines;ellipses→ ellipses
Render primitives on device.Rasterisation Line Rasterisation 2/16
Rendering a scene
User space Device space
Compose Render
Affine transformation
Transform
Compose from primitives (lines, ellipses, etc) in user space.
Transform affine transformations:lines→ lines;ellipses→ ellipses
Render primitives on device.Rasterisation Line Rasterisation 2/16
Rasterisation
Vector displaysPen plottersTektronix cathode ray tubes
Raster displaysMonitorsTelevisionsLaser, ink-jet, dot matrix printersLiquid crystal displaysArrays of LEDs
Rasterisation is the conversion of ideal, mathematicalgraphics primitives onto raster displays.
Drawing linesDrawing circles and ellipsesFilling areas
Hearn & Baker, Chapter 2 for displays.Rasterisation Line Rasterisation 3/16
Rasterisation
Vector displaysPen plottersTektronix cathode ray tubes
Raster displaysMonitorsTelevisionsLaser, ink-jet, dot matrix printersLiquid crystal displaysArrays of LEDs
Rasterisation is the conversion of ideal, mathematicalgraphics primitives onto raster displays.
Drawing linesDrawing circles and ellipsesFilling areas
Hearn & Baker, Chapter 2 for displays.Rasterisation Line Rasterisation 3/16
Rasterisation
Vector displaysPen plottersTektronix cathode ray tubes
Raster displaysMonitorsTelevisionsLaser, ink-jet, dot matrix printersLiquid crystal displaysArrays of LEDs
Rasterisation is the conversion of ideal, mathematicalgraphics primitives onto raster displays.
Drawing linesDrawing circles and ellipsesFilling areas
Hearn & Baker, Chapter 2 for displays.Rasterisation Line Rasterisation 3/16
Rasterisation
Vector displaysPen plottersTektronix cathode ray tubes
Raster displaysMonitorsTelevisionsLaser, ink-jet, dot matrix printersLiquid crystal displaysArrays of LEDs
Rasterisation is the conversion of ideal, mathematicalgraphics primitives onto raster displays.
Drawing linesDrawing circles and ellipsesFilling areas
Hearn & Baker, Chapter 2 for displays.Rasterisation Line Rasterisation 3/16
Rasterisation
Vector displaysPen plottersTektronix cathode ray tubes
Raster displaysMonitorsTelevisionsLaser, ink-jet, dot matrix printersLiquid crystal displaysArrays of LEDs
Rasterisation is the conversion of ideal, mathematicalgraphics primitives onto raster displays.
Drawing linesDrawing circles and ellipsesFilling areas
Hearn & Baker, Chapter 2 for displays.Rasterisation Line Rasterisation 3/16
Rasterisation
Vector displaysPen plottersTektronix cathode ray tubes
Raster displaysMonitorsTelevisionsLaser, ink-jet, dot matrix printersLiquid crystal displaysArrays of LEDs
Rasterisation is the conversion of ideal, mathematicalgraphics primitives onto raster displays.
Drawing linesDrawing circles and ellipsesFilling areas
Hearn & Baker, Chapter 2 for displays.Rasterisation Line Rasterisation 3/16
Rasterisation
Vector displaysPen plottersTektronix cathode ray tubes
Raster displaysMonitorsTelevisionsLaser, ink-jet, dot matrix printersLiquid crystal displaysArrays of LEDs
Rasterisation is the conversion of ideal, mathematicalgraphics primitives onto raster displays.
Drawing linesDrawing circles and ellipsesFilling areas
Hearn & Baker, Chapter 2 for displays.Rasterisation Line Rasterisation 3/16
Rasterisation
Vector displaysPen plottersTektronix cathode ray tubes
Raster displaysMonitorsTelevisionsLaser, ink-jet, dot matrix printersLiquid crystal displaysArrays of LEDs
Rasterisation is the conversion of ideal, mathematicalgraphics primitives onto raster displays.
Drawing linesDrawing circles and ellipsesFilling areas
Hearn & Baker, Chapter 2 for displays.Rasterisation Line Rasterisation 3/16
Rasterisation
Vector displaysPen plottersTektronix cathode ray tubes
Raster displaysMonitorsTelevisionsLaser, ink-jet, dot matrix printersLiquid crystal displaysArrays of LEDs
Rasterisation is the conversion of ideal, mathematicalgraphics primitives onto raster displays.
Drawing linesDrawing circles and ellipsesFilling areas
Hearn & Baker, Chapter 2 for displays.Rasterisation Line Rasterisation 3/16
Rasterisation
Vector displaysPen plottersTektronix cathode ray tubes
Raster displaysMonitorsTelevisionsLaser, ink-jet, dot matrix printersLiquid crystal displaysArrays of LEDs
Rasterisation is the conversion of ideal, mathematicalgraphics primitives onto raster displays.
Drawing linesDrawing circles and ellipsesFilling areas
Hearn & Baker, Chapter 2 for displays.Rasterisation Line Rasterisation 3/16
Rasterisation
Vector displaysPen plottersTektronix cathode ray tubes
Raster displaysMonitorsTelevisionsLaser, ink-jet, dot matrix printersLiquid crystal displaysArrays of LEDs
Rasterisation is the conversion of ideal, mathematicalgraphics primitives onto raster displays.
Drawing linesDrawing circles and ellipsesFilling areas
Hearn & Baker, Chapter 2 for displays.Rasterisation Line Rasterisation 3/16
Rasterisation
Vector displaysPen plottersTektronix cathode ray tubes
Raster displaysMonitorsTelevisionsLaser, ink-jet, dot matrix printersLiquid crystal displaysArrays of LEDs
Rasterisation is the conversion of ideal, mathematicalgraphics primitives onto raster displays.
Drawing linesDrawing circles and ellipsesFilling areas
Hearn & Baker, Chapter 2 for displays.Rasterisation Line Rasterisation 3/16
Rasterisation
Vector displaysPen plottersTektronix cathode ray tubes
Raster displaysMonitorsTelevisionsLaser, ink-jet, dot matrix printersLiquid crystal displaysArrays of LEDs
Rasterisation is the conversion of ideal, mathematicalgraphics primitives onto raster displays.
Drawing linesDrawing circles and ellipsesFilling areas
Hearn & Baker, Chapter 2 for displays.Rasterisation Line Rasterisation 3/16
Rasterisation
Vector displaysPen plottersTektronix cathode ray tubes
Raster displaysMonitorsTelevisionsLaser, ink-jet, dot matrix printersLiquid crystal displaysArrays of LEDs
Rasterisation is the conversion of ideal, mathematicalgraphics primitives onto raster displays.
Drawing linesDrawing circles and ellipsesFilling areas
Hearn & Baker, Chapter 2 for displays.Rasterisation Line Rasterisation 3/16
Rasterisation
Vector displaysPen plottersTektronix cathode ray tubes
Raster displaysMonitorsTelevisionsLaser, ink-jet, dot matrix printersLiquid crystal displaysArrays of LEDs
Rasterisation is the conversion of ideal, mathematicalgraphics primitives onto raster displays.
Drawing linesDrawing circles and ellipsesFilling areas
Hearn & Baker, Chapter 2 for displays.Rasterisation Line Rasterisation 3/16
Framebuffer
Raster display is a 2D array of picture elements: pixelsFramebuffer: in-memory image of the display.
00
1 2
12
Screen coordinates of pixelsare centered at the integers.
Pixels are individually set orcleared (random access).Sequential readout byphysical device.
Graphical objects arecontinuous.Framebuffer is discrete.
Rasterisation / Framebuffer Line Rasterisation 4/16
Framebuffer
Raster display is a 2D array of picture elements: pixelsFramebuffer: in-memory image of the display.
00
1 2
12
Screen coordinates of pixelsare centered at the integers.
Pixels are individually set orcleared (random access).Sequential readout byphysical device.
Graphical objects arecontinuous.Framebuffer is discrete.
Rasterisation / Framebuffer Line Rasterisation 4/16
Framebuffer
Raster display is a 2D array of picture elements: pixelsFramebuffer: in-memory image of the display.
00
1 2
12
Screen coordinates of pixelsare centered at the integers.
Pixels are individually set orcleared (random access).Sequential readout byphysical device.
Graphical objects arecontinuous.Framebuffer is discrete.
Rasterisation / Framebuffer Line Rasterisation 4/16
Framebuffer
Raster display is a 2D array of picture elements: pixelsFramebuffer: in-memory image of the display.
00
1 2
12
Screen coordinates of pixelsare centered at the integers.
Pixels are individually set orcleared (random access).Sequential readout byphysical device.
Graphical objects arecontinuous.Framebuffer is discrete.
Rasterisation / Framebuffer Line Rasterisation 4/16
Framebuffer
Raster display is a 2D array of picture elements: pixelsFramebuffer: in-memory image of the display.
00
1 2
12
Screen coordinates of pixelsare centered at the integers.
Pixels are individually set orcleared (random access).Sequential readout byphysical device.
Graphical objects arecontinuous.Framebuffer is discrete.
Rasterisation / Framebuffer Line Rasterisation 4/16
Framebuffer
Raster display is a 2D array of picture elements: pixelsFramebuffer: in-memory image of the display.
00
1 2
12
Screen coordinates of pixelsare centered at the integers.
Pixels are individually set orcleared (random access).Sequential readout byphysical device.
Graphical objects arecontinuous.Framebuffer is discrete.
Rasterisation / Framebuffer Line Rasterisation 4/16
Framebuffer
Raster display is a 2D array of picture elements: pixelsFramebuffer: in-memory image of the display.
00
1 2
12
Screen coordinates of pixelsare centered at the integers.
Pixels are individually set orcleared (random access).Sequential readout byphysical device.
Graphical objects arecontinuous.Framebuffer is discrete.
Rasterisation / Framebuffer Line Rasterisation 4/16
Framebuffer
Raster display is a 2D array of picture elements: pixelsFramebuffer: in-memory image of the display.
00
1 2
12
Screen coordinates of pixelsare centered at the integers.
Pixels are individually set orcleared (random access).Sequential readout byphysical device.
Graphical objects arecontinuous.Framebuffer is discrete.
Rasterisation / Framebuffer Line Rasterisation 4/16
Rasterisation
Rasterisationis the conversion of ideal, mathematical graphicsprimitives onto raster displays.
Efficiencywe seek efficient algorithms for computing thediscrete approximation to continuous description.
Scan Conversionrasterisation line by line of the raster display.
Rasterisation / Framebuffer Line Rasterisation 5/16
Rasterisation
Rasterisationis the conversion of ideal, mathematical graphicsprimitives onto raster displays.
Efficiencywe seek efficient algorithms for computing thediscrete approximation to continuous description.
Scan Conversionrasterisation line by line of the raster display.
Rasterisation / Framebuffer Line Rasterisation 5/16
Rasterisation
Rasterisationis the conversion of ideal, mathematical graphicsprimitives onto raster displays.
Efficiencywe seek efficient algorithms for computing thediscrete approximation to continuous description.
Scan Conversionrasterisation line by line of the raster display.
Rasterisation / Framebuffer Line Rasterisation 5/16
Rasterisation
Rasterisationis the conversion of ideal, mathematical graphicsprimitives onto raster displays.
Efficiencywe seek efficient algorithms for computing thediscrete approximation to continuous description.
Scan Conversionrasterisation line by line of the raster display.
Rasterisation / Framebuffer Line Rasterisation 5/16
Rasterisation
Rasterisationis the conversion of ideal, mathematical graphicsprimitives onto raster displays.
Efficiencywe seek efficient algorithms for computing thediscrete approximation to continuous description.
Scan Conversionrasterisation line by line of the raster display.
Rasterisation / Framebuffer Line Rasterisation 5/16
Rasterisation
Rasterisationis the conversion of ideal, mathematical graphicsprimitives onto raster displays.
Efficiencywe seek efficient algorithms for computing thediscrete approximation to continuous description.
Scan Conversionrasterisation line by line of the raster display.
Rasterisation / Framebuffer Line Rasterisation 5/16
Rasterisation
Rasterisationis the conversion of ideal, mathematical graphicsprimitives onto raster displays.
Efficiencywe seek efficient algorithms for computing thediscrete approximation to continuous description.
Scan Conversionrasterisation line by line of the raster display.
Rasterisation / Framebuffer Line Rasterisation 5/16
Line Segments
Problem: Draw a line from (Xstart ,Ystart) to (Xend ,Yend )Simplified: Draw a line from (0, 0) to (Xend ,Yend )
(Xend > 0 and Yend > 0)
(0,0)
(19,4)
Grid marks pixel centres
Example: Line from (0, 0) to (Xend ,Yend )= (19, 4)
Lines Line Rasterisation 6/16
Line Segments
Problem: Draw a line from (Xstart ,Ystart) to (Xend ,Yend )Simplified: Draw a line from (0, 0) to (Xend ,Yend )
(Xend > 0 and Yend > 0)
(0,0)
(19,4)
Grid marks pixel centres
Example: Line from (0, 0) to (Xend ,Yend )= (19, 4)
Lines Line Rasterisation 6/16
Line Segments
Problem: Draw a line from (Xstart ,Ystart) to (Xend ,Yend )Simplified: Draw a line from (0, 0) to (Xend ,Yend )
(Xend > 0 and Yend > 0)
(0,0)
(19,4)
Grid marks pixel centres
Example: Line from (0, 0) to (Xend ,Yend )= (19, 4)
Lines Line Rasterisation 6/16
Line Segments
Problem: Draw a line from (Xstart ,Ystart) to (Xend ,Yend )Simplified: Draw a line from (0, 0) to (Xend ,Yend )
(Xend > 0 and Yend > 0)
(0,0)
(19,4)
Grid marks pixel centres
Example: Line from (0, 0) to (Xend ,Yend )= (19, 4)
Lines Line Rasterisation 6/16
Line Segments
Problem: Draw a line from (Xstart ,Ystart) to (Xend ,Yend )Simplified: Draw a line from (0, 0) to (Xend ,Yend )
(Xend > 0 and Yend > 0)
(0,0)
(19,4)
Grid marks pixel centres
Example: Line from (0, 0) to (Xend ,Yend )= (19, 4)
Lines Line Rasterisation 6/16
Line Segments
Problem: Draw a line from (Xstart ,Ystart) to (Xend ,Yend )Simplified: Draw a line from (0, 0) to (Xend ,Yend )
(Xend > 0 and Yend > 0)
(0,0)
(19,4)
Grid marks pixel centres
Example: Line from (0, 0) to (Xend ,Yend )= (19, 4)
Lines Line Rasterisation 6/16
Line Segments
Problem: Draw a line from (Xstart ,Ystart) to (Xend ,Yend )Simplified: Draw a line from (0, 0) to (Xend ,Yend )
(Xend > 0 and Yend > 0)
(0,0)
(19,4)
Grid marks pixel centres
Example: Line from (0, 0) to (Xend ,Yend )= (19, 4)
Lines Line Rasterisation 6/16
Line Segments
Problem: Draw a line from (Xstart ,Ystart) to (Xend ,Yend )Simplified: Draw a line from (0, 0) to (Xend ,Yend )
(Xend > 0 and Yend > 0)
(0,0)
(19,4)
Grid marks pixel centres
Example: Line from (0, 0) to (Xend ,Yend )= (19, 4)
Lines Line Rasterisation 6/16
Which pixels to illuminate?
Illuminate every pixel the line intersects
Illuminate the vertically closest pixel
Lines / Which Pixel? Line Rasterisation 7/16
Which pixels to illuminate?
Illuminate every pixel the line intersects
Illuminate the vertically closest pixel
Lines / Which Pixel? Line Rasterisation 7/16
Which pixels to illuminate?
Illuminate every pixel the line intersects
Illuminate the vertically closest pixel
Lines / Which Pixel? Line Rasterisation 7/16
Which pixels to illuminate?
Illuminate every pixel the line intersects
Illuminate the vertically closest pixel
Lines / Which Pixel? Line Rasterisation 7/16
Which pixels to illuminate?
Illuminate every pixel the line intersects
Illuminate the vertically closest pixel
Lines / Which Pixel? Line Rasterisation 7/16
Gradient
Gradient of line
y = m x + c
m =Yend − Ystart
Xend − Xstart
Simplified line from (0, 0) to (Xend ,Yend ):
y = m x , m =Yend
Xend
Lines / Gradient Line Rasterisation 8/16
Gradient
Gradient of line
y = m x + c
m =Yend − Ystart
Xend − Xstart
Simplified line from (0, 0) to (Xend ,Yend ):
y = m x , m =Yend
Xend
Lines / Gradient Line Rasterisation 8/16
Gradient
Gradient of line
y = m x + c
m =Yend − Ystart
Xend − Xstart
Simplified line from (0, 0) to (Xend ,Yend ):
y = m x , m =Yend
Xend
Lines / Gradient Line Rasterisation 8/16
Gradient
Gradient of line
y = m x + c
m =Yend − Ystart
Xend − Xstart
Simplified line from (0, 0) to (Xend ,Yend ):
y = m x , m =Yend
Xend
Lines / Gradient Line Rasterisation 8/16
Gradient
Gradient of line
y = m x + c
m =Yend − Ystart
Xend − Xstart
Simplified line from (0, 0) to (Xend ,Yend ):
y = m x , m =Yend
Xend
Lines / Gradient Line Rasterisation 8/16
Gradient
Gradient of line
y = m x + c
m =Yend − Ystart
Xend − Xstart
Simplified line from (0, 0) to (Xend ,Yend ):
y = m x , m =Yend
Xend
Lines / Gradient Line Rasterisation 8/16
Gradient
Gradient of line
y = m x + c
m =Yend − Ystart
Xend − Xstart
Simplified line from (0, 0) to (Xend ,Yend ):
y = m x , m =Yend
Xend
Lines / Gradient Line Rasterisation 8/16
Naïve Midpoint Algorithm
Illuminate pixel vertically closest to the line
4/198/19 16/19
12/19
double m = Yend / Xend;int x = 0;double y = 0.0;
while ( x <= Xend ) {y = m * x;iy = round(y);setpixel(x, iy);x++;
}
DDA Digital Differential Analyser. Hearn & Baker, p86.
Floating point operations and round() are computationallyexpensive.
Lines / Naïve Algorithm Line Rasterisation 9/16
Naïve Midpoint Algorithm
Illuminate pixel vertically closest to the line
4/198/19 16/19
12/19
double m = Yend / Xend;int x = 0;double y = 0.0;
while ( x <= Xend ) {y = m * x;iy = round(y);setpixel(x, iy);x++;
}
DDA Digital Differential Analyser. Hearn & Baker, p86.
Floating point operations and round() are computationallyexpensive.
Lines / Naïve Algorithm Line Rasterisation 9/16
Naïve Midpoint Algorithm
Illuminate pixel vertically closest to the line
4/198/19 16/19
12/19
double m = Yend / Xend;int x = 0;double y = 0.0;
while ( x <= Xend ) {y = m * x;iy = round(y);setpixel(x, iy);x++;
}
DDA Digital Differential Analyser. Hearn & Baker, p86.
Floating point operations and round() are computationallyexpensive.
Lines / Naïve Algorithm Line Rasterisation 9/16
Naïve Midpoint Algorithm
Illuminate pixel vertically closest to the line
4/198/19 16/19
12/19
double m = Yend / Xend;int x = 0;double y = 0.0;
while ( x <= Xend ) {y = m * x;iy = round(y);setpixel(x, iy);x++;
}
DDA Digital Differential Analyser. Hearn & Baker, p86.
Floating point operations and round() are computationallyexpensive.
Lines / Naïve Algorithm Line Rasterisation 9/16
Naïve Midpoint Algorithm
Illuminate pixel vertically closest to the line
4/198/19 16/19
12/19
double m = Yend / Xend;int x = 0;double y = 0.0;
while ( x <= Xend ) {y = m * x;iy = round(y);setpixel(x, iy);x++;
}
DDA Digital Differential Analyser. Hearn & Baker, p86.
Floating point operations and round() are computationallyexpensive.
Lines / Naïve Algorithm Line Rasterisation 9/16
Naïve Midpoint Algorithm
Illuminate pixel vertically closest to the line
4/198/19 16/19
12/19
double m = Yend / Xend;int x = 0;double y = 0.0;
while ( x <= Xend ) {y = m * x;iy = round(y);setpixel(x, iy);x++;
}
DDA Digital Differential Analyser. Hearn & Baker, p86.
Floating point operations and round() are computationallyexpensive.
Lines / Naïve Algorithm Line Rasterisation 9/16
Remove round()
Line coherence: As x 7→ x + 1 then y 7→ y + m
4/1916/19
12/19
8/19
At each step: move right one pixeland up by 4
19 .
midpoint indicates pixel centreabove illuminated pixel.
When y crosses verticalmidpoint between two centresmove up and compute newmidpoint target.
double m = Yend / Xend;int x = 0;int iy = 0;double y = 0.0;double midpoint = 0.5;
while (x <= Xend) {setpixel(x, iy);x++;y += m;
if (y > midpoint) {iy++;midpoint += 1.0;
}}
Lines / Eliminating Floats Line Rasterisation 10/16
Remove round()
Line coherence: As x 7→ x + 1 then y 7→ y + m
4/1916/19
12/19
8/19
At each step: move right one pixeland up by 4
19 .
midpoint indicates pixel centreabove illuminated pixel.
When y crosses verticalmidpoint between two centresmove up and compute newmidpoint target.
double m = Yend / Xend;int x = 0;int iy = 0;double y = 0.0;double midpoint = 0.5;
while (x <= Xend) {setpixel(x, iy);x++;y += m;
if (y > midpoint) {iy++;midpoint += 1.0;
}}
Lines / Eliminating Floats Line Rasterisation 10/16
Remove round()
Line coherence: As x 7→ x + 1 then y 7→ y + m
4/1916/19
12/19
8/19
At each step: move right one pixeland up by 4
19 .
midpoint indicates pixel centreabove illuminated pixel.
When y crosses verticalmidpoint between two centresmove up and compute newmidpoint target.
double m = Yend / Xend;int x = 0;int iy = 0;double y = 0.0;double midpoint = 0.5;
while (x <= Xend) {setpixel(x, iy);x++;y += m;
if (y > midpoint) {iy++;midpoint += 1.0;
}}
Lines / Eliminating Floats Line Rasterisation 10/16
Remove round()
Line coherence: As x 7→ x + 1 then y 7→ y + m
4/1916/19
12/19
8/19
At each step: move right one pixeland up by 4
19 .
midpoint indicates pixel centreabove illuminated pixel.
When y crosses verticalmidpoint between two centresmove up and compute newmidpoint target.
double m = Yend / Xend;int x = 0;int iy = 0;double y = 0.0;double midpoint = 0.5;
while (x <= Xend) {setpixel(x, iy);x++;y += m;
if (y > midpoint) {iy++;midpoint += 1.0;
}}
Lines / Eliminating Floats Line Rasterisation 10/16
Remove round()
Line coherence: As x 7→ x + 1 then y 7→ y + m
4/1916/19
12/19
8/19
At each step: move right one pixeland up by 4
19 .
midpoint indicates pixel centreabove illuminated pixel.
When y crosses verticalmidpoint between two centresmove up and compute newmidpoint target.
double m = Yend / Xend;int x = 0;int iy = 0;double y = 0.0;double midpoint = 0.5;
while (x <= Xend) {setpixel(x, iy);x++;y += m;
if (y > midpoint) {iy++;midpoint += 1.0;
}}
Lines / Eliminating Floats Line Rasterisation 10/16
Remove round()
Line coherence: As x 7→ x + 1 then y 7→ y + m
4/1916/19
12/19
8/19
At each step: move right one pixeland up by 4
19 .
midpoint indicates pixel centreabove illuminated pixel.
When y crosses verticalmidpoint between two centresmove up and compute newmidpoint target.
double m = Yend / Xend;int x = 0;int iy = 0;double y = 0.0;double midpoint = 0.5;
while (x <= Xend) {setpixel(x, iy);x++;y += m;
if (y > midpoint) {iy++;midpoint += 1.0;
}}
Lines / Eliminating Floats Line Rasterisation 10/16
Remove round()
Line coherence: As x 7→ x + 1 then y 7→ y + m
4/1916/19
12/19
8/19
At each step: move right one pixeland up by 4
19 .
midpoint indicates pixel centreabove illuminated pixel.
When y crosses verticalmidpoint between two centresmove up and compute newmidpoint target.
double m = Yend / Xend;int x = 0;int iy = 0;double y = 0.0;double midpoint = 0.5;
while (x <= Xend) {setpixel(x, iy);x++;y += m;
if (y > midpoint) {iy++;midpoint += 1.0;
}}
Lines / Eliminating Floats Line Rasterisation 10/16
Integers only
m =Yend
Xendy = m x =
Yend xXend
Multiply m, y and midpoint bytwice total change in x ;(i.e. by 2Xend )
m = 2 Yend y = 2 Yendx
2432
y=816
19 19 57midpoint19 57
int m = 2 * Yend;int x = 0;int iy = 0;int y = 0;int midpoint = Xend;
while (x <= Xend) {setpixel(x, iy);x++;y += m;
if (y > midpoint) {iy++;midpoint += 2 * Xend;
}}
Lines / Eliminating Floats Line Rasterisation 11/16
Integers only
m =Yend
Xendy = m x =
Yend xXend
Multiply m, y and midpoint bytwice total change in x ;(i.e. by 2Xend )
m = 2 Yend y = 2 Yendx
2432
y=816
19 19 57midpoint19 57
int m = 2 * Yend;int x = 0;int iy = 0;int y = 0;int midpoint = Xend;
while (x <= Xend) {setpixel(x, iy);x++;y += m;
if (y > midpoint) {iy++;midpoint += 2 * Xend;
}}
Lines / Eliminating Floats Line Rasterisation 11/16
Integers only
m =Yend
Xendy = m x =
Yend xXend
Multiply m, y and midpoint bytwice total change in x ;(i.e. by 2Xend )
m = 2 Yend y = 2 Yendx
2432
y=816
19 19 57midpoint19 57
int m = 2 * Yend;int x = 0;int iy = 0;int y = 0;int midpoint = Xend;
while (x <= Xend) {setpixel(x, iy);x++;y += m;
if (y > midpoint) {iy++;midpoint += 2 * Xend;
}}
Lines / Eliminating Floats Line Rasterisation 11/16
Integers only
m =Yend
Xendy = m x =
Yend xXend
Multiply m, y and midpoint bytwice total change in x ;(i.e. by 2Xend )
m = 2 Yend y = 2 Yendx
2432
y=816
19 19 57midpoint19 57
int m = 2 * Yend;int x = 0;int iy = 0;int y = 0;int midpoint = Xend;
while (x <= Xend) {setpixel(x, iy);x++;y += m;
if (y > midpoint) {iy++;midpoint += 2 * Xend;
}}
Lines / Eliminating Floats Line Rasterisation 11/16
Integers only
m =Yend
Xendy = m x =
Yend xXend
Multiply m, y and midpoint bytwice total change in x ;(i.e. by 2Xend )
m = 2 Yend y = 2 Yendx
2432
y=816
19 19 57midpoint19 57
int m = 2 * Yend;int x = 0;int iy = 0;int y = 0;int midpoint = Xend;
while (x <= Xend) {setpixel(x, iy);x++;y += m;
if (y > midpoint) {iy++;midpoint += 2 * Xend;
}}
Lines / Eliminating Floats Line Rasterisation 11/16
Integers only
m =Yend
Xendy = m x =
Yend xXend
Multiply m, y and midpoint bytwice total change in x ;(i.e. by 2Xend )
m = 2 Yend y = 2 Yendx
2432
y=816
19 19 57midpoint19 57
int m = 2 * Yend;int x = 0;int iy = 0;int y = 0;int midpoint = Xend;
while (x <= Xend) {setpixel(x, iy);x++;y += m;
if (y > midpoint) {iy++;midpoint += 2 * Xend;
}}
Lines / Eliminating Floats Line Rasterisation 11/16
Integers only
m =Yend
Xendy = m x =
Yend xXend
Multiply m, y and midpoint bytwice total change in x ;(i.e. by 2Xend )
m = 2 Yend y = 2 Yendx
2432
y=816
19 19 57midpoint19 57
int m = 2 * Yend;int x = 0;int iy = 0;int y = 0;int midpoint = Xend;
while (x <= Xend) {setpixel(x, iy);x++;y += m;
if (y > midpoint) {iy++;midpoint += 2 * Xend;
}}
Lines / Eliminating Floats Line Rasterisation 11/16
Bresenham’s algorithm
Eliminate midpoint by adjusting y tostart at the midpoint and decreasingto 0.
y=19
3 −5 => 332511
Hearn & Baker, page 88
int m = 2 * Yend;int x = 0;int iy = 0;int y = Xend;
while (x <= Xend) {setpixel(x, iy);x++;y -= m;
if (y < 0) {iy++;y += 2 * Xend;
}}
Lines / Bresenham’s Algorithm Line Rasterisation 12/16
Bresenham’s algorithm
Eliminate midpoint by adjusting y tostart at the midpoint and decreasingto 0.
y=19
3 −5 => 332511
Hearn & Baker, page 88
int m = 2 * Yend;int x = 0;int iy = 0;int y = Xend;
while (x <= Xend) {setpixel(x, iy);x++;y -= m;
if (y < 0) {iy++;y += 2 * Xend;
}}
Lines / Bresenham’s Algorithm Line Rasterisation 12/16
Bresenham’s algorithm
Eliminate midpoint by adjusting y tostart at the midpoint and decreasingto 0.
y=19
3 −5 => 332511
Hearn & Baker, page 88
int m = 2 * Yend;int x = 0;int iy = 0;int y = Xend;
while (x <= Xend) {setpixel(x, iy);x++;y -= m;
if (y < 0) {iy++;y += 2 * Xend;
}}
Lines / Bresenham’s Algorithm Line Rasterisation 12/16
Bresenham’s algorithm
Eliminate midpoint by adjusting y tostart at the midpoint and decreasingto 0.
y=19
3 −5 => 332511
Hearn & Baker, page 88
int m = 2 * Yend;int x = 0;int iy = 0;int y = Xend;
while (x <= Xend) {setpixel(x, iy);x++;y -= m;
if (y < 0) {iy++;y += 2 * Xend;
}}
Lines / Bresenham’s Algorithm Line Rasterisation 12/16
Bresenham’s algorithm
Eliminate midpoint by adjusting y tostart at the midpoint and decreasingto 0.
y=19
3 −5 => 332511
Hearn & Baker, page 88
int m = 2 * Yend;int x = 0;int iy = 0;int y = Xend;
while (x <= Xend) {setpixel(x, iy);x++;y -= m;
if (y < 0) {iy++;y += 2 * Xend;
}}
Lines / Bresenham’s Algorithm Line Rasterisation 12/16
Caveats
Needs adjustment for:
General starting pointm > 1
Negative slopes
Lines with different slope may have different brightness.Alleviated with anti-aliasing(give pixels different brightness).
References
Hearn & Baker, pp. 84-94Foley & van Dam
Lines / Bresenham’s Algorithm Line Rasterisation 13/16
Caveats
Needs adjustment for:
General starting pointm > 1
Negative slopes
Lines with different slope may have different brightness.Alleviated with anti-aliasing(give pixels different brightness).
References
Hearn & Baker, pp. 84-94Foley & van Dam
Lines / Bresenham’s Algorithm Line Rasterisation 13/16
Caveats
Needs adjustment for:
General starting pointm > 1
Negative slopes
Lines with different slope may have different brightness.Alleviated with anti-aliasing(give pixels different brightness).
References
Hearn & Baker, pp. 84-94Foley & van Dam
Lines / Bresenham’s Algorithm Line Rasterisation 13/16
Caveats
Needs adjustment for:
General starting pointm > 1
Negative slopes
Lines with different slope may have different brightness.Alleviated with anti-aliasing(give pixels different brightness).
References
Hearn & Baker, pp. 84-94Foley & van Dam
Lines / Bresenham’s Algorithm Line Rasterisation 13/16
Caveats
Needs adjustment for:
General starting pointm > 1
Negative slopes
Lines with different slope may have different brightness.Alleviated with anti-aliasing(give pixels different brightness).
References
Hearn & Baker, pp. 84-94Foley & van Dam
Lines / Bresenham’s Algorithm Line Rasterisation 13/16
Caveats
Needs adjustment for:
General starting pointm > 1
Negative slopes
Lines with different slope may have different brightness.Alleviated with anti-aliasing(give pixels different brightness).
References
Hearn & Baker, pp. 84-94Foley & van Dam
Lines / Bresenham’s Algorithm Line Rasterisation 13/16
Caveats
Needs adjustment for:
General starting pointm > 1
Negative slopes
Lines with different slope may have different brightness.Alleviated with anti-aliasing(give pixels different brightness).
References
Hearn & Baker, pp. 84-94Foley & van Dam
Lines / Bresenham’s Algorithm Line Rasterisation 13/16
Caveats
Needs adjustment for:
General starting pointm > 1
Negative slopes
Lines with different slope may have different brightness.Alleviated with anti-aliasing(give pixels different brightness).
References
Hearn & Baker, pp. 84-94Foley & van Dam
Lines / Bresenham’s Algorithm Line Rasterisation 13/16
Caveats
Needs adjustment for:
General starting pointm > 1
Negative slopes
Lines with different slope may have different brightness.Alleviated with anti-aliasing(give pixels different brightness).
References
Hearn & Baker, pp. 84-94Foley & van Dam
Lines / Bresenham’s Algorithm Line Rasterisation 13/16
Caveats
Needs adjustment for:
General starting pointm > 1
Negative slopes
Lines with different slope may have different brightness.Alleviated with anti-aliasing(give pixels different brightness).
References
Hearn & Baker, pp. 84-94Foley & van Dam
Lines / Bresenham’s Algorithm Line Rasterisation 13/16
Caveats
Needs adjustment for:
General starting pointm > 1
Negative slopes
Lines with different slope may have different brightness.Alleviated with anti-aliasing(give pixels different brightness).
References
Hearn & Baker, pp. 84-94Foley & van Dam
Lines / Bresenham’s Algorithm Line Rasterisation 13/16
Caveats
Needs adjustment for:
General starting pointm > 1
Negative slopes
Lines with different slope may have different brightness.Alleviated with anti-aliasing(give pixels different brightness).
References
Hearn & Baker, pp. 84-94Foley & van Dam
Lines / Bresenham’s Algorithm Line Rasterisation 13/16
Bresenham Circle Algorithm
Choose pixel withcentre closest tocircle.
Work on a singleoctant and drawothers by symmetry.
Can be written ininteger arithmetic.
Details in Hearn &Baker, Foley et al.
Lines / Bresenham Circle Algorithm Line Rasterisation 14/16
Bresenham Circle Algorithm
Choose pixel withcentre closest tocircle.
Work on a singleoctant and drawothers by symmetry.
Can be written ininteger arithmetic.
Details in Hearn &Baker, Foley et al.
Lines / Bresenham Circle Algorithm Line Rasterisation 14/16
Bresenham Circle Algorithm
Choose pixel withcentre closest tocircle.
Work on a singleoctant and drawothers by symmetry.
Can be written ininteger arithmetic.
Details in Hearn &Baker, Foley et al.
Lines / Bresenham Circle Algorithm Line Rasterisation 14/16
Bresenham Circle Algorithm
Choose pixel withcentre closest tocircle.
Work on a singleoctant and drawothers by symmetry.
Can be written ininteger arithmetic.
Details in Hearn &Baker, Foley et al.
Lines / Bresenham Circle Algorithm Line Rasterisation 14/16
Bresenham Circle Algorithm
Choose pixel withcentre closest tocircle.
Work on a singleoctant and drawothers by symmetry.
Can be written ininteger arithmetic.
Details in Hearn &Baker, Foley et al.
Lines / Bresenham Circle Algorithm Line Rasterisation 14/16
Bresenham Circle Algorithm
Choose pixel withcentre closest tocircle.
Work on a singleoctant and drawothers by symmetry.
Can be written ininteger arithmetic.
Details in Hearn &Baker, Foley et al.
Lines / Bresenham Circle Algorithm Line Rasterisation 14/16
Bresenham Circle Algorithm
Choose pixel withcentre closest tocircle.
Work on a singleoctant and drawothers by symmetry.
Can be written ininteger arithmetic.
Details in Hearn &Baker, Foley et al.
Lines / Bresenham Circle Algorithm Line Rasterisation 14/16
Thick Primitives
Column Replication
Efficient, easily implemented.Perceived thickness varieswith slope.Gaps at joins.
Rectangular Pen
Ends are thicker than middle.Perceived thickness varieswith slope.Pixels are set multiple times.
Lines / Thick Primitives Line Rasterisation 15/16
Thick Primitives
Column Replication
Efficient, easily implemented.Perceived thickness varieswith slope.Gaps at joins.
Rectangular Pen
Ends are thicker than middle.Perceived thickness varieswith slope.Pixels are set multiple times.
Lines / Thick Primitives Line Rasterisation 15/16
Thick Primitives
Column Replication
Efficient, easily implemented.Perceived thickness varieswith slope.Gaps at joins.
Rectangular Pen
Ends are thicker than middle.Perceived thickness varieswith slope.Pixels are set multiple times.
Lines / Thick Primitives Line Rasterisation 15/16
Thick Primitives
Column Replication
Efficient, easily implemented.Perceived thickness varieswith slope.Gaps at joins.
Rectangular Pen
Ends are thicker than middle.Perceived thickness varieswith slope.Pixels are set multiple times.
Lines / Thick Primitives Line Rasterisation 15/16
Thick Primitives
Column Replication
Efficient, easily implemented.Perceived thickness varieswith slope.Gaps at joins.
Rectangular Pen
Ends are thicker than middle.Perceived thickness varieswith slope.Pixels are set multiple times.
Lines / Thick Primitives Line Rasterisation 15/16
Thick Primitives
Column Replication
Efficient, easily implemented.Perceived thickness varieswith slope.Gaps at joins.
Rectangular Pen
Ends are thicker than middle.Perceived thickness varieswith slope.Pixels are set multiple times.
Lines / Thick Primitives Line Rasterisation 15/16
Thick Primitives
Column Replication
Efficient, easily implemented.Perceived thickness varieswith slope.Gaps at joins.
Rectangular Pen
Ends are thicker than middle.Perceived thickness varieswith slope.Pixels are set multiple times.
Lines / Thick Primitives Line Rasterisation 15/16
Thick Primitives
Column Replication
Efficient, easily implemented.Perceived thickness varieswith slope.Gaps at joins.
Rectangular Pen
Ends are thicker than middle.Perceived thickness varieswith slope.Pixels are set multiple times.
Lines / Thick Primitives Line Rasterisation 15/16
Thick Primitives
Column Replication
Efficient, easily implemented.Perceived thickness varieswith slope.Gaps at joins.
Rectangular Pen
Ends are thicker than middle.Perceived thickness varieswith slope.Pixels are set multiple times.
Lines / Thick Primitives Line Rasterisation 15/16
Thick Primitives
Column Replication
Efficient, easily implemented.Perceived thickness varieswith slope.Gaps at joins.
Rectangular Pen
Ends are thicker than middle.Perceived thickness varieswith slope.Pixels are set multiple times.
Lines / Thick Primitives Line Rasterisation 15/16
Thick Primitives
Column Replication
Efficient, easily implemented.Perceived thickness varieswith slope.Gaps at joins.
Rectangular Pen
Ends are thicker than middle.Perceived thickness varieswith slope.Pixels are set multiple times.
Lines / Thick Primitives Line Rasterisation 15/16
Thick Primitives
Circular Pen
Thickness independent of slope.
Pixels are set multiple times.
Can be made efficient by settingonly boundary pixels.
Boundary Fill
Fill the area between boundaries.
Polygon with edges parallel toprimitive.
Precise control over joins(butt, bevel, cap ends)
Lines, circles become polygons.
Expensive.
Lines / Thick Primitives Line Rasterisation 16/16
Thick Primitives
Circular Pen
Thickness independent of slope.
Pixels are set multiple times.
Can be made efficient by settingonly boundary pixels.
Boundary Fill
Fill the area between boundaries.
Polygon with edges parallel toprimitive.
Precise control over joins(butt, bevel, cap ends)
Lines, circles become polygons.
Expensive.
Lines / Thick Primitives Line Rasterisation 16/16
Thick Primitives
Circular Pen
Thickness independent of slope.
Pixels are set multiple times.
Can be made efficient by settingonly boundary pixels.
Boundary Fill
Fill the area between boundaries.
Polygon with edges parallel toprimitive.
Precise control over joins(butt, bevel, cap ends)
Lines, circles become polygons.
Expensive.
Lines / Thick Primitives Line Rasterisation 16/16
Thick Primitives
Circular Pen
Thickness independent of slope.
Pixels are set multiple times.
Can be made efficient by settingonly boundary pixels.
Boundary Fill
Fill the area between boundaries.
Polygon with edges parallel toprimitive.
Precise control over joins(butt, bevel, cap ends)
Lines, circles become polygons.
Expensive.
Lines / Thick Primitives Line Rasterisation 16/16
Thick Primitives
Circular Pen
Thickness independent of slope.
Pixels are set multiple times.
Can be made efficient by settingonly boundary pixels.
Boundary Fill
Fill the area between boundaries.
Polygon with edges parallel toprimitive.
Precise control over joins(butt, bevel, cap ends)
Lines, circles become polygons.
Expensive.
Lines / Thick Primitives Line Rasterisation 16/16
Thick Primitives
Circular Pen
Thickness independent of slope.
Pixels are set multiple times.
Can be made efficient by settingonly boundary pixels.
Boundary Fill
Fill the area between boundaries.
Polygon with edges parallel toprimitive.
Precise control over joins(butt, bevel, cap ends)
Lines, circles become polygons.
Expensive.
Lines / Thick Primitives Line Rasterisation 16/16
Thick Primitives
Circular Pen
Thickness independent of slope.
Pixels are set multiple times.
Can be made efficient by settingonly boundary pixels.
Boundary Fill
Fill the area between boundaries.
Polygon with edges parallel toprimitive.
Precise control over joins(butt, bevel, cap ends)
Lines, circles become polygons.
Expensive.
Lines / Thick Primitives Line Rasterisation 16/16
Thick Primitives
Circular Pen
Thickness independent of slope.
Pixels are set multiple times.
Can be made efficient by settingonly boundary pixels.
Boundary Fill
Fill the area between boundaries.
Polygon with edges parallel toprimitive.
Precise control over joins(butt, bevel, cap ends)
Lines, circles become polygons.
Expensive.
Lines / Thick Primitives Line Rasterisation 16/16
Thick Primitives
Circular Pen
Thickness independent of slope.
Pixels are set multiple times.
Can be made efficient by settingonly boundary pixels.
Boundary Fill
Fill the area between boundaries.
Polygon with edges parallel toprimitive.
Precise control over joins(butt, bevel, cap ends)
Lines, circles become polygons.
Expensive.
Lines / Thick Primitives Line Rasterisation 16/16
Thick Primitives
Circular Pen
Thickness independent of slope.
Pixels are set multiple times.
Can be made efficient by settingonly boundary pixels.
Boundary Fill
Fill the area between boundaries.
Polygon with edges parallel toprimitive.
Precise control over joins(butt, bevel, cap ends)
Lines, circles become polygons.
Expensive.
Lines / Thick Primitives Line Rasterisation 16/16
Thick Primitives
Circular Pen
Thickness independent of slope.
Pixels are set multiple times.
Can be made efficient by settingonly boundary pixels.
Boundary Fill
Fill the area between boundaries.
Polygon with edges parallel toprimitive.
Precise control over joins(butt, bevel, cap ends)
Lines, circles become polygons.
Expensive.
Lines / Thick Primitives Line Rasterisation 16/16
Thick Primitives
Circular Pen
Thickness independent of slope.
Pixels are set multiple times.
Can be made efficient by settingonly boundary pixels.
Boundary Fill
Fill the area between boundaries.
Polygon with edges parallel toprimitive.
Precise control over joins(butt, bevel, cap ends)
Lines, circles become polygons.
Expensive.
Lines / Thick Primitives Line Rasterisation 16/16
Thick Primitives
Circular Pen
Thickness independent of slope.
Pixels are set multiple times.
Can be made efficient by settingonly boundary pixels.
Boundary Fill
Fill the area between boundaries.
Polygon with edges parallel toprimitive.
Precise control over joins(butt, bevel, cap ends)
Lines, circles become polygons.
Expensive.
Lines / Thick Primitives Line Rasterisation 16/16