Download presentation
Presentation is loading. Please wait.
1
CSCE 441 Lecture 2: Scan Conversion of Lines
Jinxiang Chai
2
Displays – Cathode Ray Tube
3
Displays – Liquid Crystal Displays
4
Displays – Plasma
5
Displays – Pixels Pixel: the smallest element of picture
- Integer position (i,j) - Color information (r,g,b) y x (0,0)
6
Digital Scan Conversion
Convert graphics output primitives into a set of pixel values for storage in the frame buffer
7
OpenGL Geometric Primitives
All geometric primitives are specified by vertices GL_LINE_STRIP GL_LINE_LOOP GL_POLYGON GL_LINES GL_POINTS GL_TRIANGLE_STRIP GL_QUAD_STRIP GL_TRIANGLES GL_QUADS GL_TRIANGLE_FAN
8
OpenGL Geometric Primitives
All geometric primitives are specified by vertices GL_LINE_STRIP GL_LINE_LOOP GL_POLYGON GL_LINES GL_POINTS GL_TRIANGLE_STRIP GL_QUAD_STRIP GL_TRIANGLES GL_QUADS GL_TRIANGLE_FAN
9
Outline How to draw a line? - Digital Differential Analyzer (DDA)
- Midpoint algorithm Required readings - HB 3.1 to 3.8
10
Problem Given two points (P, Q) on the screen (with integer coordinates) determine which pixels should be drawn to display a unit width line
11
Problem Given two points (P, Q) on the screen (with integer coordinates) determine which pixels should be drawn to display a unit width line
12
Problem Given two points (P, Q) on the screen (with integer coordinates) determine which pixels should be drawn to display a unit width line
13
Special Lines - Horizontal
14
Special Lines - Horizontal
Increment x by 1, keep y constant
15
Special Lines - Vertical
16
Special Lines - Vertical
Keep x constant, increment y by 1
17
Special Lines - Diagonal
18
Special Lines - Diagonal
Increment x by 1, increment y by 1
19
How about Arbitrary Lines?
How to draw an arbitrary line?
20
Arbitrary Lines Slope-intercept equation for a line: m: slope
b: y-intercept Slope-intercept equation for a straight line. Here me is the slope of the line and b is the y intercept
21
Arbitrary Lines Slope-intercept equation for a line:
How can we compute the equation from (xL,yL), (xH,yH)? m: slope b: y-intercept Slope-intercept equation for a straight line. Here me is the slope of the line and b is the y intercept
22
Arbitrary Lines Slope-intercept equation for a line:
How can we compute the equation from (xL,yL), (xH,yH)? m: slope b: y-intercept Slope-intercept equation for a straight line. Here me is the slope of the line and b is the y intercept
23
Arbitrary Lines Assume Other lines by swapping x, y or negating
Take steps in x and determine where to fill y Slope-intercept equation for a straight line. Here me is the slope of the line and b is the y intercept
24
Digital Differential Analyzer
Start from (xL, yL) and draw to (xH, yH) where xL< xH ( x0, y0 ) = ( xL, yL ) For ( i = 0; i <= xH-xL; i++ ) DrawPixel ( xi, Round ( yi ) ) xi+1 = xi + 1 yi+1 = m xi+1 + b
25
Digital Differential Analyzer
Simple algorithm: - sample unit intervals in one coordinate - find the nearest pixel for each sampled point.
26
Digital Differential Analyzer (DDA)
Start from (xL, yL) and draw to (xH, yH) where xL< xH ( x0, y0 ) = ( xL, yL ) For ( i = 0; i <= xH-xL; i++ ) //sample unit intervals in x coordinate DrawPixel ( xi, Round ( yi ) ) //find the nearest pixel for each sampled point. xi+1 = xi + 1 yi+1 = m ( xi + 1 ) + b
27
DDA Start from (xL, yL) and draw to (xH, yH) where xL< xH
( x0, y0 ) = ( xL, yL ) For ( i = 0; i <= xH-xL; i++ ) DrawPixel ( xi, Round ( yi ) ) xi+1 = xi + 1 yi+1 = m xi + m + b
28
DDA Start from (xL, yL) and draw to (xH, yH) where xL< xH
( x0, y0 ) = ( xL, yL ) For ( i = 0; i <= xH-xL; i++ ) DrawPixel ( xi, Round ( yi ) ) xi+1 = xi + 1 yi+1 = m xi + b + m
29
DDA Start from (xL, yL) and draw to (xH, yH) where xL< xH
( x0, y0 ) = ( xL, yL ) For ( i = 0; i <= xH-xL; i++ ) DrawPixel ( xi, Round ( yi ) ) xi+1 = xi + 1 yi+1 = m xi + b + m
30
DDA Start from (xL, yL) and draw to (xH, yH) where xL< xH
( x0, y0 ) = ( xL, yL ) For ( i = 0; i <= xH-xL; i++ ) DrawPixel ( xi, Round ( yi ) ) xi+1 = xi + 1 yi+1 = yi + m
31
DDA - Example
32
DDA - Example
33
DDA - Example
34
DDA - Example
35
DDA - Example
36
DDA - Example
37
DDA - Example
38
DDA - Example
39
DDA - Example
40
DDA - Example
41
DDA - Example
42
DDA - Example
43
DDA - Example
44
DDA - Example
45
DDA - Example
46
DDA - Problems Floating point operations Rounding Can we do better?
( x0, y0 ) = ( xL, yL ) For ( i = 0; i <= xH-xL; i++ ) DrawPixel ( xi, Round ( yi ) ) xi+1 = xi + 1 yi+1 = yi + m
47
Outline How to draw a line? - Digital Differential Analyzer (DDA)
- Midpoint algorithm
48
How to Improve It? Question: if we draw the current pixel,, where is the next pixel?
49
How to Improve It? Question: if we draw the current pixel,, where is the next pixel? Next column, E or NE direction
50
Midpoint Algorithm Given a point just drawn, determine whether we move E or NE on next step
51
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
52
Above/Below the Line?
53
Two Issues How to evaluate if the midpoint is above or below the line?
How to incrementally evaluate this?
54
Midpoint Algorithm – Implicit Forms
How do we tell if a point is above or below the line?
55
Midpoint Algorithm – Implicit Forms
How do we tell if a point is above or below the line?
56
Midpoint Algorithm – Implicit Forms
How do we tell if a point is above or below the line?
57
Midpoint Algorithm – Implicit Forms
How do we tell if a point is above or below the line?
58
Midpoint Algorithm – Implicit Forms
How do we tell if a point is above or below the line?
59
Midpoint Algorithm – Implicit Forms
How do we tell if a point is above or below the line?
60
Midpoint Algorithm – Implicit Forms
How do we tell if a point is above or below the line?
61
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)<0 (x,y) below the line f(x,y)>0 (x,y) above the line
62
Midpoint Algorithm – Implicit Forms
63
Midpoint Algorithm – Implicit Forms
64
Midpoint Algorithm – Implicit Forms
65
Midpoint Algorithm – Implicit Forms
66
Midpoint Algorithm – Implicit Forms
67
Midpoint Algorithm – Implicit Forms
68
Two Issues How to evaluate if the midpoint is above or below the line?
How to incrementally evaluate this?
69
Above/Below the Line?
70
Midpoint Algorithm What about starting value?
What is the middle point?
71
Midpoint Algorithm What about starting value?
What is the middle point? (xL+1,yL+1/2)
72
Midpoint Algorithm What about starting value?
What is the middle point? (xL+1,yL+1/2)
73
What about starting value?
Midpoint Algorithm What about starting value?
74
What about starting value?
Midpoint Algorithm What about starting value? is on the line!
75
What about starting value?
Midpoint Algorithm What about starting value?
76
What about starting value?
Midpoint Algorithm What about starting value? Multiplying coefficients by 2 doesn’t change sign of f
77
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
78
Midpoint Algorithm Need value of to determine E or NE
Build incremental algorithm Assume we have value of Find value of if E chosen
79
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 79/110 79
80
Midpoint Algorithm If E was chosen, find
81
Midpoint Algorithm If E was chosen, find
82
Midpoint Algorithm If NE was chosen, find
83
Midpoint Algorithm If NE was chosen, find
84
Midpoint Algorithm – Summary
x=xL y=yL d=xH - xL c=yL - yH sum=2c+d draw(x,y) while ( x < xH) if ( sum < 0 ) sum += 2d y++ x++ sum += 2c
85
Midpoint Algorithm – Summary
x=xL y=yL d=xH - xL c=yL - yH sum=2c+d //initial value draw(x,y) while ( x < xH) if ( sum < 0 ) sum += 2d y++ x++ sum += 2c
86
Midpoint Algorithm – Summary
x=xL y=yL d=xH - xL c=yL - yH sum=2c+d //initial value draw(x,y) while ( x < xH) // iterate until reaching the end point if ( sum < 0 ) sum += 2d y++ x++ sum += 2c
87
Midpoint Algorithm – Summary
x=xL y=yL d=xH - xL c=yL - yH sum=2c+d //initial value draw(x,y) while ( x < xH) // iterate until reaching the end point if ( sum < 0 ) // below the line and choose NE sum += 2d y++ x++ sum += 2c
88
Midpoint Algorithm – Summary
x=xL y=yL d=xH - xL c=yL - yH sum=2c+d //initial value draw(x,y) while ( x < xH) // iterate until reaching the end point if ( sum < 0 ) // below the line and choose NE sum += 2d y++ x++ sum += 2c - Update the current pixel - Update the function value of midpoint 88/110 88
89
Midpoint Algorithm – Summary
x=xL y=yL d=xH - xL c=yL - yH sum=2c+d //initial value draw(x,y) while ( x < xH) // iterate until reaching the end point if ( sum < 0 ) // below the line and choose NE sum += 2d y++ x++ sum += 2c - Draw the pixel based on the function value of midpoint 89/110 89
90
Midpoint Algorithm – Example
x=xL y=yL d=xH - xL c=yL - yH sum=2c+d draw(x,y) while ( x < xH) if ( sum < 0 ) sum += 2d y++ x++ sum += 2c Dx =6 dy = 2 d =6 c = -2
91
Midpoint Algorithm – Example
x=xL y=yL d=xH - xL c=yL - yH sum=2c+d draw(x,y) while ( x < xH) if ( sum < 0 ) sum += 2d y++ x++ sum += 2c d =6 c = -2
92
Midpoint Algorithm – Example
x=xL y=yL d=xH - xL c=yL - yH sum=2c+d draw(x,y) while ( x < xH) if ( sum < 0 ) sum += 2d y++ x++ sum += 2c d =6 c = -2
93
Midpoint Algorithm – Example
x=xL y=yL d=xH - xL c=yL - yH sum=2c+d draw(x,y) while ( x < xH) if ( sum < 0 ) sum += 2d y++ x++ sum += 2c d =6 c = -2
94
Midpoint Algorithm – Example
x=xL y=yL d=xH - xL c=yL - yH sum=2c+d draw(x,y) while ( x < xH) if ( sum < 0 ) sum += 2d y++ x++ sum += 2c d =6 c = -2
95
Midpoint Algorithm – Example
x=xL y=yL d=xH - xL c=yL - yH sum=2c+d draw(x,y) while ( x < xH) if ( sum < 0 ) sum += 2d y++ x++ sum += 2c d =6 c = -2
96
Midpoint Algorithm – Example
x=xL y=yL d=xH - xL c=yL - yH sum=2c+d draw(x,y) while ( x < xH) if ( sum < 0 ) sum += 2d y++ x++ sum += 2c d =6 c = -2
97
Midpoint Algorithm – Example
x=xL y=yL d=xH - xL c=yL - yH sum=2c+d draw(x,y) while ( x < xH) if ( sum < 0 ) sum += 2d y++ x++ sum += 2c d =6 c = -2
98
Midpoint Algorithm Only integer operations
Exactly the same as the more commonly found Bresenham’s line drawing algorithm Extends to other types of shapes (circles)
99
Midpoint Algorithm: Circle
100
Midpoint Algorithm: Circle
101
Midpoint Algorithm: Circle
102
Midpoint Algorithm: Circle
Two issues: What are two possible solutions? What is the evaluation function?
103
Midpoint Algorithm: Circle
104
Midpoint Algorithm: Circle
(xk+1,yk) (xk+1,yk-1) Two issues: What are two possible solutions? What is the evaluation function?
105
Midpoint Algorithm: Circle
(xk+1,yk) Midpoint: (xk+1,yk-1/2) (xk+1,yk-1) Two issues: What are two possible solutions? What is the evaluation function?
106
Midpoint Algorithm: Circle
(xk+1,yk) Midpoint: (xk+1,yk-1/2) (xk+1,yk-1) Two issues: What are two possible solutions? What is the evaluation function?
107
Circle, Ellipse, etc Need implicit forms - circle: - ellipse:
Equations for incremental calculations Initial positions More details in section of the textbook
108
Next Lecture How to draw a polygon? - section
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.