Professional Documents
Culture Documents
Raster Conversion Algorithms For Line and Circle
Raster Conversion Algorithms For Line and Circle
and circle
Introduction
- Pixel addressing
- Primitives and attributes
Line drawing algorithms
- DDA
- Bresenham
Circle generating algorithms
- Direct method
- Bresenham algorithm
Pixel addressing in raster graphics
Theoretical length
Pixel
address
y+1
Pixel
y+2
y+3
x x+1 x+2 x+3 x+4
Actual length
Raster conversion algorithms:
requirements
• visual accuracy
• spatial accuracy
• speed
Line drawing algorithms
thickness = 4
Line – raster representation
DDA ( Digital Differential Algorithm )
m<1
DDA ( Digital Differential Algorithm )
m>1
DDA ( Digital Differential Algorithm )
m>1
Digital Differential Algorithm
y = mx + b
d2
y = m(x+1) + b
y d1
x x+1
Bresenham's line algorithm (slope ≤ 1)
• input line endpoints, (x0,y0) and (xn, yn)
• calculate x = xn - x0 and y = yn - y0
• calculate parameter p0 = 2 y - x
• set pixel at position (x0,y0)
• repeat the following steps until (xn, yn) is reached:
• if pi < 0
• set the next pixel at position (xi +1, yi )
• calculate new pi+1 = pi + 2 y
• if pi ≥ 0
• set the next pixel at position (xi +1, yi + 1 )
• calculate new pi+1 = pi + 2(y - x)
DDA versus Bresenham’s Algorithm
• Direct
• Polar coordinate based
• Bresenham’s
Direct circle algorithm
• Cartesian coordinates
• Circle equation:
( x - xc )2 + ( y - yc )2 = r2
1. Input radius r
if pk < 0
plot point at (xk +1, yk)
compute new pk+1 = pk + 2xk+1 + 1
else
plot point at (xk + 1, yk – 1)
compute new pk+1 = pk + 2xk+1 + 1 – 2yk+1