Title: Dr' Scott Schaefer
1Scan Conversion of Lines
2Displays Cathode Ray Tube
3Displays Liquid Crystal Displays
4Displays Plasma
5Displays Pixels
6Problem
- Given two points (P, Q) on the screen (with
integer coordinates) determine which pixels
should be drawn to display a unit width line
7Problem
- Given two points (P, Q) on the screen (with
integer coordinates) determine which pixels
should be drawn to display a unit width line
8Problem
- Given two points (P, Q) on the screen (with
integer coordinates) determine which pixels
should be drawn to display a unit width line
9Special Lines - Horizontal
10Special Lines - Horizontal
- Increment x by 1, keep y constant
11Special Lines - Vertical
12Special Lines - Vertical
- Keep x constant, increment y by 1
13Special Lines - Diagonal
14Special Lines - Diagonal
- Increment x by 1, increment y by 1
15How about Arbitrary Lines?
16Arbitrary Lines
Slope-intercept equation for a line
m slope
b y-intercept
17Arbitrary Lines
Slope-intercept equation for a line How can
we compute the equation from (xL,yL), (xH,yH)?
m slope
b y-intercept
18Arbitrary Lines
Slope-intercept equation for a line How can
we compute the equation from (xL,yL), (xH,yH)?
m slope
b y-intercept
19Arbitrary Lines
- Assume
- Other lines by swapping x, y or negating
- Take steps in x and determine where to fill y
20Simple Algorithm
- Start from (xL, yL) and draw to (xH, yH)
- where xLlt xH
- ( x0, y0 ) ( xL, yL )
- For ( i 0 i lt xH-xL i )
- DrawPixel ( xi, Round ( yi ) )
- xi1 xi 1
- yi1 m xi1 b
21Simple Algorithm
- Start from (xL, yL) and draw to (xH, yH)
- where xLlt xH
- ( x0, y0 ) ( xL, yL )
- For ( i 0 i lt xH-xL i )
- DrawPixel ( xi, Round ( yi ) )
- xi1 xi 1
- yi1 m ( xi 1 ) b
22Simple Algorithm
- Start from (xL, yL) and draw to (xH, yH)
- where xLlt xH
- ( x0, y0 ) ( xL, yL )
- For ( i 0 i lt xH-xL i )
- DrawPixel ( xi, Round ( yi ) )
- xi1 xi 1
- yi1 m xi m b
23Simple Algorithm
- Start from (xL, yL) and draw to (xH, yH)
- where xLlt xH
- ( x0, y0 ) ( xL, yL )
- For ( i 0 i lt xH-xL i )
- DrawPixel ( xi, Round ( yi ) )
- xi1 xi 1
- yi1 yi m
24Simple Algorithm - Example
25Simple Algorithm - Example
26Simple Algorithm - Example
27Simple Algorithm - Example
28Simple Algorithm - Example
29Simple Algorithm - Example
30Simple Algorithm - Example
31Simple Algorithm - Example
32Simple Algorithm - Example
33Simple Algorithm - Problems
- Floating point operations
- Rounding
- Can we do better?
- ( x0, y0 ) ( xL, yL )
- For ( i 0 i lt xH-xL i )
- DrawPixel ( xi, Round ( yi ) )
- xi1 xi 1
- yi1 yi m
34Midpoint Algorithm
- Given a point just drawn, determine whether we
move E or NE on next step
35Midpoint Algorithm
- Given a point just drawn, determine whether we
move E or NE on next step - Is the line above or below ?
- Below move E
- Above move NE
36Midpoint Algorithm Implicit Forms
- How do we tell if a point is above or below the
line?
37Midpoint Algorithm Implicit Forms
- How do we tell if a point is above or below the
line?
38Midpoint Algorithm Implicit Forms
- How do we tell if a point is above or below the
line?
39Midpoint Algorithm Implicit Forms
- How do we tell if a point is above or below the
line?
40Midpoint Algorithm Implicit Forms
- How do we tell if a point is above or below the
line?
41Midpoint Algorithm Implicit Forms
- How do we tell if a point is above or below the
line?
42Midpoint Algorithm Implicit Forms
- How do we tell if a point is above or below the
line?
Properties f(x,y)0 (x,y) on the line f(x,y)lt0
(x,y) below the line f(x,y)gt0 (x,y) above the
line
43Midpoint Algorithm Implicit Forms
44Midpoint Algorithm Implicit Forms
45Midpoint Algorithm Implicit Forms
46Midpoint Algorithm Implicit Forms
47Midpoint Algorithm Implicit Forms
48Midpoint Algorithm Implicit Forms
49Midpoint Algorithm
- Need value of to determine
E or NE - Build incremental algorithm
- Assume we have value of
- Find value of if E chosen
- Find value of if NE chosen
50Midpoint Algorithm
51Midpoint Algorithm
52Midpoint Algorithm
53Midpoint Algorithm
54Midpoint Algorithm
- What about starting value?
55Midpoint Algorithm
- What about starting value?
56Midpoint Algorithm
- What about starting value?
is on the line!
57Midpoint Algorithm
- What about starting value?
58Midpoint Algorithm
- What about starting value?
Multiplying coefficients by 2 doesnt change sign
of f
59Midpoint Algorithm Summary
- xxL yyL
- dxxH - xL dyyH - yL
- sumdx - 2dy
- draw(x,y)
- while ( x lt xH)
- if ( sum lt 0 )
- sum 2dx
- y
- x
- sum - 2dy
- draw(x,y)
60Midpoint Algorithm Example
xxL yyL dxxH - xL dyyH -
yL sumdx - 2dy draw(x,y) while ( x lt xH) if (
sum lt 0 ) sum 2dx y x sum -
2dy draw(x,y)
61Midpoint Algorithm Example
xxL yyL dxxH - xL dyyH -
yL sumdx - 2dy draw(x,y) while ( x lt xH) if (
sum lt 0 ) sum 2dx y x sum -
2dy draw(x,y)
62Midpoint Algorithm Example
xxL yyL dxxH - xL dyyH -
yL sumdx - 2dy draw(x,y) while ( x lt xH) if (
sum lt 0 ) sum 2dx y x sum -
2dy draw(x,y)
63Midpoint Algorithm Example
xxL yyL dxxH - xL dyyH -
yL sumdx - 2dy draw(x,y) while ( x lt xH) if (
sum lt 0 ) sum 2dx y x sum -
2dy draw(x,y)
64Midpoint Algorithm Example
xxL yyL dxxH - xL dyyH -
yL sumdx - 2dy draw(x,y) while ( x lt xH) if (
sum lt 0 ) sum 2dx y x sum -
2dy draw(x,y)
65Midpoint Algorithm Example
xxL yyL dxxH - xL dyyH -
yL sumdx - 2dy draw(x,y) while ( x lt xH) if (
sum lt 0 ) sum 2dx y x sum -
2dy draw(x,y)
66Midpoint Algorithm Example
xxL yyL dxxH - xL dyyH -
yL sumdx - 2dy draw(x,y) while ( x lt xH) if (
sum lt 0 ) sum 2dx y x sum -
2dy draw(x,y)
67Midpoint Algorithm Example
xxL yyL dxxH - xL dyyH -
yL sumdx - 2dy draw(x,y) while ( x lt xH) if (
sum lt 0 ) sum 2dx y x sum -
2dy draw(x,y)
68Midpoint Algorithm
- Only integer operations
- Exactly the same as the more commonly found
Bresenhams line drawing algorithm - Extends to other types of shapes (circles)
69Circle, ellipse, etc
- Need implicit forms
- - circle
- - ellipse
- Equations for incremental calculations
- Initial positions
- More details in section 3.8-3.11 of the textbook