Scan Conversion - Line
Scan Conversion - Line
Line
Dr. Nahla Abid
Scan Conversion
• Points:
• A point in two dimensional space is given as an ordered pair (x, y)
• In three dimensions a point is given as an ordered triple (x, y, z)
• Lines: A line is defined using a start point and an end-point
• In 2d: (xstart, ystart) to (xend, yend)
• In 3d: (xstart, ystart , zstart) to (xend, yend , zend)
Line Drawing
y
(7, 1)
x
Goals
• The equation of the line gives us the corresponding y point for every x point
Example of Using Line Equation
3 4
Let’s draw a portion of the line given by the equation: y x
5 5
3 4 3 4 4
y (2) 2 2 y (5) 5 3 y
5 5 5 5 5 5
3 4 3 3 4 2
y (3) 3 2 y (6) 6 4
5 5 5 5 5 5 2
3 4 1 3 4
y (4) 4 3 y (7 ) 7 5
5 5 5 5 5 2 3 4 5 6 7 x
Digital Differential Analyser ( DDA) for a line
y y2 y1
m
x x2 x1
1
y mx or x y
m
Digital Differential Analyser ( DDA) for a line…
• A very simple procedure for scan converting a straight line is given as follows:
1. Plot the first pixel at (x,y)= (x1,y1 )
2. increment the x- and y-values by dx and dy respectively to get the next pixel . We
consider either dx or dy to be unity and compute the other . Plot pixel at
(x+dx,y+dy)
if dx=1 yi 1 yi m
1
else dy=1 xi 1 xi
m
3. Continue the above steps until the final (x2,y2) is reached
DDA Algorithm for a line (x1,y1,x2,y2)
• Trace the DDA algorithm for drawing a line segment from (2,3) to (8,7)
• solution :
dx = 8 – 2 = 6
dy = 7 – 3 = 4
|dx|>|dy| then steps=|dx|= 6
Xinc = dx/steps = 1
Yinc = dy/steps = 0.67
• Now starting with the point (2,3) ,generate the next points in sequence to reach
the point (8,7). the computational steps are shown in the next slide.
DDA: Example1…
• Trace the DDA algorithm for drawing a line segment from (2,3) to (8,10)
• solution:
dx = 8 – 2 = 6
dy = 10 – 3 = 7
|dy|>|dx| then steps=|dy|=7
Xinc = dx/steps = 0.86
Yinc = dy/steps = 1
• Now starting with the point (2,3) ,generate the next points in sequence to reach
the point (8,10). the computational steps are shown in the next slide.
DDA: Example2…
• Assumptions:
• Drawing a line from the left hand side
• X2 > X1 and |dx| > |dy|
Big Idea
• Move across the x axis in unit intervals and at each step choose
between two different y coordinates
5
• For example, from position (2,
(xk+1, yk+1)
3) we have to choose between
4
(3, 3) and (3, 4)
(xk, yk)
• We would like the point that is 3
closer to the original line (xk+1, yk)
2
2 3 4 5
Bresenham’s Algorithm
xk+1
5
1. Input the two line end-points, storing the left end-point in (x0, y0)
2. Plot the point (x0, y0)
3. Calculate the constants Δx, Δy, 2Δy, and (2Δy - 2Δx) and get the first value for
the decision parameter as:
p0 2y x
4. At each xk along the line, starting at k = 0, perform the following test.
If pk < 0, the next point to plot is (xk+1, yk) and: pk 1 pk 2y
Otherwise, the next point to plot is (xk+1, yk+1) and: pk 1 pk 2y 2x
• Trace the Bresenham’s algorithm for drawing the line segment from
(2,3) to (8,7)
P0=2dy-dx=2*4-6=2
dx=6 and dy=4
Pk<0pk+1=pk+2dy;
xk+1=xk+1; and yk+1=yk
Pk>=0pk+1=pk+2dy-2dx;
xk+1=xk+1; and yk+1=yk+1
Example of Performing Bresenham’s algorithm
• Trace the Bresenham’s algorithm for drawing the line segment from
(1,1) to (6,7)
k xk yk pk Pk+1 Xk+1 Yk+1