| 2.Lines |
![[prev]](common/prev.gif)
Pixel Screen Positions Stored Linearly in Row Major Order Within the Frame Buffer
|
Finding Pixels that are on a Line
|
Finding Pixels that are on a Line
for y in [ 0, n ]
for x in [ 0, n ]
if | y-mx-b | = 0
setPixel ( x, y )
|
Finding Pixels that are nearly on a Line
for y in [ 0, n ]
for x in [ 0, n ]
if | y-mx-b | <= [delta]
setPixel ( x, y )
|
Finding the Pixels on a Line - Implicit
|
Finding the Pixels on a Line - Implicit
for x in [ 0, n ] y = 1/2 x setPixel ( x, y ) |
Finding the Pixels on a Line - Implicit
for x in [ 0, n ] y = 2 x setPixel ( x, y ) |
Finding the Pixels on a Line - Implicit
for x in [ 0, n ] y = 5x setPixel ( x, y ) |
Finding the Pixels on a Line - Implicit
for y in [ 0, n ] x = 1/5 y setPixel ( x, y ) |
Incremental Calculation of (xi, yi)
|
Finding the Pixels on a Line - DDA
y = 0 for x in [ 0, n ] y = y + 1/10 setPixel ( x, y ) |
Finding the Pixels on a Line - DDA
y = 0 for x in [ 0, n ] y = y + 1/10 setPixel ( x, y ) |
void Line ( int x0, int y0, int x1, int y1, int value )
{ /* Assumes -1 <= m <= 1, x0 < x1 */
int x; /* x runs from x0 to x1 in unit increments. */
float dy, dx, y, m;
dy = y1 - y0;
dx = x1 - x0;
m = dy / dx;
y = y0;
for ( x = x0; x <= x1; x++ ) {
WritePixel ( x, (int) floor ( y + 0.5 ), value );
/* Set pixel to value */
y += m; /* Step y by slope m */
}
}
|
Midpoint Line Algorithm
|
Midpoint Line AlgorithmMidpoint: F(M) < 0? Bresenham: d1 > d2?
|
Midpoint AlgorithmEquations:
|
Midpoint AlgorithmEquations:
-> a = dy, b = -dx, c = B.dx |
Midpoint AlgorithmEquations:
-> a = dy, b = -dx, c = B.dx Midpoint Criteria
d = F(m) = F(xp+1, yp+ 1/2)
if d > 0,
choose NE
else
choose E
|
Midpoint Algorithm - Book Keeping
|
Midpoint Algorithm - Book Keeping
|
Midpoint Algorithm - Book Keeping
|
Midpoint Algorithm - Book Keeping, Integer Calculations
|
void MidpointLine ( int x0, int y0, int x1, int y1, int value )
{
int dx, dy, incrE, incrNE, d, x, y;
dx = x1 - x0;
dy = y1 - y0;
d = dy * 2 - dx;
incrE = dy * 2;
incrNE = (dy - dx) * 2;
x = x0;
y = y0;
WritePixel ( x, y, value );
while ( x < x1 ) {
if ( d <= 0 ) {
d += incrE;
x ++;
}
else {
d += incrNE;
x ++;
y ++;
}
WritePixel ( x, y, value );
}
}
|
Midpoint Line Algorithm
|
Midpoint Line Algorithm
|
Midpoint Line Algorithm
|
||||||||||||||||||||
Midpoint Line Algorithm
|
||||||||||||||||||||||||||
Midpoint Line Algorithm
|
||||||||||||||||||||||||||||
Midpoint Line Algorithm
|
||||||||||||||||||||||||||||||||
Varying Intensity of Raster Lines as a Function of Slope
|
![[prev]](common/prev.gif)
| Made by dynaPage 0.2 |