Spring 2013 Line Characterizations Bresenham’s Midpoint Algorithm y mx B • Explicit: F x y ax by c • Implicit: ( , ) 0 CS5600 Computer Graphics Lecture Set 2 y adapted from k • Constant slope: x Rich Riesenfeld’s slides Spring 2013 ) f x k • Constant derivative: ( Line Characterizations - 2 Two Line Equations y mx B P t t t • Parametric: P P • Explicit: ( ) ( 1 ) 0 1 F x y ax by c • Implicit: ( , ) 0 1 P P where , P P ( 0 ) ; ( ) 0 1 Define: dy y y • Intersection of 2 planes 1 0 dx x x 1 0 • Shortest path between 2 points dy y x B Hence, • Convex hull of 2 discrete points dx Relating Explicit to Implicit Eq’s From previous dy x y B Recall, 0 dy dx y x B We have, dx dy x dx y dx B ( ) ( ) ( ) 0 Or, Hence, dy F x y dy x dx y dx B ( , ) ( ) ( ) ( ) 0 x y B 0 dx a dy b dx c B dx where, ( ); ( ); ( ) CS5600
Spring 2013 Discrete Lines “Good” Discrete Line • No gaps in adjacent pixels • Lines vs. Line Segments • Pixels close to ideal line • What is a discrete line segment? • Consistent choices; same pixels in same situations – This is a relatively recent problem • Smooth looking • Even brightness in all orientations – How to generate a discrete line? P P P P • Same line for as for 0 1 1 0 • Double pixels stacked up? How to Draw a Line? Derive from Line Equation Y = mX + b 1. Compute slope Y i = mX i + b 2. Start at on point (x o , y o ) X i+1 = X i + X 3. Increment x and draw Y i+1 = mX i+1 + b • How to figure this out? Y i+1 = m(X i + X) + b = mX i + m X + b = m X + mX i + b = m X + Y i Derive from Line Equation What about slope? Y = mX + b m = y / x If |y 1 – y 0 | > |x 1 – x 0 | Y i = mX i + b = (y 1 – y 0 ) / (x 1 – x 0 ) increment Y X i+1 = X i + X y = x (y 1 – y 0 ) / (x 1 – x 0 ) Y i+1 = Y i + Y Y i+1 = mX i+1 + b Y i+1 = m(X i + X) + b else = Y i + x (y 1 – y 0 ) / (x 1 – x 0 ) = mX i + m X + b = m X + mX i + b = Y i + X(m) increment X = m X + Y i CS5600
Spring 2013 Incremental Fn Eval Restricted Form f x f x x • Recall ( ) ( ) ( ) i i i 1 • Line segment in first octant with • Characteristics 0 < m < 1 – Fast – Cumulative Error • After we derive this, we’ll look at the • Need to define other cases (other octants) f x ( ) o CS 5600 13 Investigate Sign of F The Picture y Verify that F x y below line ( , ) 0 above line F x y ( , ) 0 on line above line F x y ( , ) 0 below line Look at extreme values of y x Decision Variable d (logical) Key to Bresenham Algorithm Define a logical decision variable d “Reasonable assumptions” have reduced the problem to making a – linear in form binary choice at each pixel: – incrementally updated (with addition) NE (next) – tells us whether to go E or NE (Previous) E (next) CS5600
Spring 2013 The Picture The Picture (again) x x p x y NE ( 1 , 1 ) NE p p y y 1 p Q Q M M midpoint midpoint 1 ideal line x y ( 1 , ) ideal line p p 2 E y y p x x p y y ( , ) previous ( , ) E 1 p previous p p x x 1 p The Picture (again) Observe the relationships x y ( 1 , 1 ) • Suppose Q is above M , as before. NE p p F M • Then ( ) 0 , M is below the line 1 x y F M ( 1 , ) means line is above M , ( ) 0 midpoint • So, p p 2 Q ideal line • Need to move NE, increase y value E x x p y y ( , ) ( 1 , ) p previous p p M = Midpoint = 1 : x y ( , ) 1 Observe the relationships p p 2 • Suppose Q is below M , as before. • Want to evaluate at M • Then F ( M ) < 0 , implies M is above the • Will use an incremental decision variable d line • So, F ( M ) < 0 , means line is below M , 1 d F x y ( , ) 1 p p 2 • Need to move to E; don’t increase y 1 d a x b y c • Let, ( ( ) 1 ) p p 2 CS5600
Spring 2013 How will d be used? Case E: Suppose E is chosen 1 d a x b y c • Recall ( ( ) 1 1 ) d a x b y c ( ( ) old p p 1 ) Let, p p 2 2 E x x y y • : ; , 1 Therefore, 1 d F x y • ... ( 2 , ) new p p NE 0 (midpoint below ideal line) 2 d E 1 0 (midpoint above ideal line) a x b y c ( ( ) 2 ) p p 2 E 0 (arbitrary ) Case E: Suppose E is chosen Review of Explicit to Implicit dy Recall, x y B 1 0 d d a x b y c ( 2 ( ) ) dx new old p p 2 dy x dx y dx B Or, ( ) ( ) ( ) 0 1 ... a x b y c ( 1 ( ) ) p p 2 F x y dy x dx y dx B ( , ) ( ) ( ) ( ) 0 d d a new old where, a dy b dx c B dx ( ); ( ); ( ) d d a Case E: new old Case NE: Suppose NE chosen . 1 d a x b y c E ( ( ) Recall 1) increment we add if is chosen. old p p E 2 a So, . But remember that E NE x x y y and, : ; , 1 1 a dy (from line equations). 3 F M d F x y ( Hence, ( ) is not evaluated explicitly. 2, ) new p p 2 a d E ... We simply add to update for E 3 a x b y c ( 2) ( ) p p 2 CS5600
Spring 2013 d d a b Case NE: . Case NE: Suppose NE new old d d new old NE increment that we add if is chosen. NE a b So, . But remember that 3 a x b y c NE ( 2 ( ) ) p p a dy b dx , and (from line equations). 2 ... F M Hence, ( ) is not evaluated explicitly. 1 a x b y c ( 1 ) ( ) a b d NE p p We simply add to update for NE 2 d d a b new old Case NE: d d a b Summary new old . • At each step of the procedure, we a b a dy b dx , where , and must choose between moving E or NE NE based on the sign of the a b means, we simply add , i.e., decision variable d NE • Then update according to dy dx d NE to update for . NE d dy , where , or E E d d dy dx , where NE NE What is initial value of d ? What is initial value of d ? x 0 y 1 1 ( , ) • First point is F x y a x b y c ( , ) ( ( ) 1 1) 0 0 0 0 0 1 2 2 x y ( , ) • First midpoint is 1 b 0 0 2 ax by c a • What is initial midpoint value? 0 0 2 b x y a 1 1 F , ) ( d x y F x y ( , ) ( , ) 0 0 1 1 2 0 0 0 0 2 2 CS5600
Spring 2013 What is initial value of d ? What Does Factor of 2 x Do ? F x y x y Note, ( , ) 0, since ( , ) is on line. • Has the same 0 -set 0 0 0 0 F x y ax by c 2 ( , ) 2 ( ) 0 b Hence, 1 F x y a ( , ) 0 1 • Changes the slope of the plane 0 0 2 2 • Rotates plane about the 0-set line dx dy ( ) • Gets rid of the denominator 2 What is initial value of d ? What is initial value of d ? Note, we can clear denominator F x y ax by c 2 ( , ) 2( ) 0 and not change line, So, first value of 1 F x y dy dx 2 ( 1 , ) 2( ) 0 0 d dy dx 2( ) ( ) 2 More Summary More Summary dy dx • Initial value 2 ( ) ( ) d d dy • Case E: , where 2 ( ) E E E d if 0 Choose d d • Case NE: , NE NE otherwise dy dx where 2 {( ) ( )} NE • Note, all deltas are constants CS5600
Recommend
More recommend