Dr' Scott Schaefer - PowerPoint PPT Presentation

1 / 69
About This Presentation
Title:

Dr' Scott Schaefer

Description:

41 /69. Midpoint Algorithm Implicit Forms. How do we tell if a point is above or below the line? ... sum -= 2dy. draw(x,y) Midpoint Algorithm Example. 61 ... – PowerPoint PPT presentation

Number of Views:67
Avg rating:3.0/5.0
Slides: 70
Provided by: symo5
Category:
Tags: schaefer | scott | sum | tube

less

Transcript and Presenter's Notes

Title: Dr' Scott Schaefer


1
Scan Conversion of Lines
  • Dr. Scott Schaefer

2
Displays Cathode Ray Tube
3
Displays Liquid Crystal Displays
4
Displays Plasma
5
Displays Pixels
6
Problem
  • Given two points (P, Q) on the screen (with
    integer coordinates) determine which pixels
    should be drawn to display a unit width line

7
Problem
  • Given two points (P, Q) on the screen (with
    integer coordinates) determine which pixels
    should be drawn to display a unit width line

8
Problem
  • Given two points (P, Q) on the screen (with
    integer coordinates) determine which pixels
    should be drawn to display a unit width line

9
Special Lines - Horizontal
10
Special Lines - Horizontal
  • Increment x by 1, keep y constant

11
Special Lines - Vertical
12
Special Lines - Vertical
  • Keep x constant, increment y by 1

13
Special Lines - Diagonal
14
Special Lines - Diagonal
  • Increment x by 1, increment y by 1

15
How about Arbitrary Lines?
16
Arbitrary Lines
Slope-intercept equation for a line
m slope
b y-intercept
17
Arbitrary Lines
Slope-intercept equation for a line How can
we compute the equation from (xL,yL), (xH,yH)?
m slope
b y-intercept
18
Arbitrary Lines
Slope-intercept equation for a line How can
we compute the equation from (xL,yL), (xH,yH)?
m slope
b y-intercept
19
Arbitrary Lines
  • Assume
  • Other lines by swapping x, y or negating
  • Take steps in x and determine where to fill y

20
Simple 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

21
Simple 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

22
Simple 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

23
Simple 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

24
Simple Algorithm - Example
25
Simple Algorithm - Example
26
Simple Algorithm - Example
27
Simple Algorithm - Example
28
Simple Algorithm - Example
29
Simple Algorithm - Example
30
Simple Algorithm - Example
31
Simple Algorithm - Example
32
Simple Algorithm - Example
33
Simple 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

34
Midpoint Algorithm
  • Given a point just drawn, determine whether we
    move E or NE on next step

35
Midpoint 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

36
Midpoint Algorithm Implicit Forms
  • How do we tell if a point is above or below the
    line?

37
Midpoint Algorithm Implicit Forms
  • How do we tell if a point is above or below the
    line?

38
Midpoint Algorithm Implicit Forms
  • How do we tell if a point is above or below the
    line?

39
Midpoint Algorithm Implicit Forms
  • How do we tell if a point is above or below the
    line?

40
Midpoint Algorithm Implicit Forms
  • How do we tell if a point is above or below the
    line?

41
Midpoint Algorithm Implicit Forms
  • How do we tell if a point is above or below the
    line?

42
Midpoint 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
43
Midpoint Algorithm Implicit Forms
44
Midpoint Algorithm Implicit Forms
45
Midpoint Algorithm Implicit Forms
46
Midpoint Algorithm Implicit Forms
47
Midpoint Algorithm Implicit Forms
48
Midpoint Algorithm Implicit Forms
49
Midpoint 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

50
Midpoint Algorithm
  • If E was chosen, find

51
Midpoint Algorithm
  • If E was chosen, find

52
Midpoint Algorithm
  • If NE was chosen, find

53
Midpoint Algorithm
  • If NE was chosen, find

54
Midpoint Algorithm
  • What about starting value?

55
Midpoint Algorithm
  • What about starting value?

56
Midpoint Algorithm
  • What about starting value?

is on the line!
57
Midpoint Algorithm
  • What about starting value?

58
Midpoint Algorithm
  • What about starting value?

Multiplying coefficients by 2 doesnt change sign
of f
59
Midpoint 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)

60
Midpoint 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)
61
Midpoint 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)
62
Midpoint 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)
63
Midpoint 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)
64
Midpoint 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)
65
Midpoint 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)
66
Midpoint 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)
67
Midpoint 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)
68
Midpoint Algorithm
  • Only integer operations
  • Exactly the same as the more commonly found
    Bresenhams line drawing algorithm
  • Extends to other types of shapes (circles)

69
Circle, ellipse, etc
  • Need implicit forms
  • - circle
  • - ellipse
  • Equations for incremental calculations
  • Initial positions
  • More details in section 3.8-3.11 of the textbook
Write a Comment
User Comments (0)
About PowerShow.com