720 likes | 1.21k Views
Bresenham’s Midpoint Algorithm. CS5600 Computer Graphics Rich Riesenfeld Spring 2006. Lecture Set 1. Line Characterizations. Explicit: Implicit: Constant slope: Constant derivative: . Line Characterizations - 2. Parametric: where , Intersection of 2 planes
E N D
Bresenham’s Midpoint Algorithm CS5600Computer Graphics Rich Riesenfeld Spring 2006 Lecture Set 1
Line Characterizations • Explicit: • Implicit: • Constant slope: • Constant derivative: CS 5600
Line Characterizations - 2 • Parametric: where, • Intersection of 2 planes • Shortest path between 2 points • Convex hull of 2 discrete points CS 5600
Discrete Lines • Lines vs. Line Segments • What is a discrete line segment? • This is a relatively recent problem • How to generate a discrete line? CS 5600
“Good” Discrete Line - 1 • No gaps in adjacent pixels • Pixels close to ideal line • Consistent choices; same pixels in same situations CS 5600
“Good” Discrete Line - 2 • Smooth looking • Even brightness in all orientations • Same line for as for • Double pixels stacked up? CS 5600
Incremental Fn Eval • Recall • Characteristics • Fast • Cumulative Error • Need to define CS 5600
Meeting Bresenham Criteria CS 5600
Case 1: Translate to Origin CS 5600
Case 0: Trivial Situations • Do not need Bresenham CS 5600
Case 1: Translate to Origin • Need only consider lines emanating from the origin. CS 5600
Case 2: Flip about x-axis CS 5600
Case 2: Flip about x-axis CS 5600
How do slopes relate? CS 5600
How do slopes relate? i.e., CS 5600
Case 3: Flip about line y=x CS 5600
Case 3: Flip about line y=x CS 5600
Case 3: m′=? CS 5600
Restricted Form • Line segment in first octant with 0 < m < 1 • Let us proceed CS 5600
Two Line Equations • Explicit: • Implicit: Define: Hence, CS 5600
From previous We have, Hence, CS 5600
Relating Explicit to Implicit Eq’s Recall, Or, where, CS 5600
Verify that Look at extreme values of y Investigate Sign ofF below line on line above line CS 5600
The Picture above line below line CS 5600
“Reasonable assumptions” have reduced the problem to making a binary choice at each pixel: Key to Bresenham Algorithm NE (next) E (next) (Previous) CS 5600
Define a logical decision variable d linear in form incrementally updated (with addition) tells us whether to go E or NE Decision Variable d(logical) CS 5600
The Picture NE Q midpoint M idealline previous E CS 5600
The Picture (again) NE Q midpoint M idealline E previous CS 5600
Observe the relationships • Suppose Q is above M, as before. • Then , M is below the line • So, means line is above M, • Need to move NE, increasey value CS 5600
The Picture (again) NE midpoint Q idealline E previous CS 5600
Observe the relationships • Suppose Q is below M, as before. • Then F(M) < 0 , implies M is above the line • So, F(M) < 0 , means line is below M, • Need to move to E; don’t increasey CS 5600
M= Midpoint = : • Want to evaluate at M • Will use an incr decision var d • Let, CS 5600
How will d be used? Recall, Therefore, CS 5600
Case 1: Suppose E is chosen • Recall • ... CS 5600
... Case 1: Suppose E is chosen CS 5600
Recall, Or, where, Review of Explicit to Implicit CS 5600
Case 1: . CS 5600
Case 2: Suppose NE chosen Recall ... CS 5600
Case 2: Suppose NE ... CS 5600
Case 2: . CS 5600
Case 2: . CS 5600
Summary • At each step of the procedure, we must choose between moving E or NE based on the sign of the decision variable d • Then update according to CS 5600
What is initial value of d ? • First point is • First midpoint is • What is initial midpoint value? CS 5600
What is initial value of d ? CS 5600
What is initial value of d ? Hence, CS 5600
What is initial value of d ? Hence, CS 5600
What Does “2 x ” Do ? • Has the same 0-set • Changes the slope of the plane • Rotates plane about the 0-set line CS 5600
What is initial value of d ? CS 5600
What is initial value of d ? CS 5600
More Summary • Initial value • Case 1: • Case 2: CS 5600