370 likes | 633 Views
Chapter 4 元素. Scan-Converting a LINE. 畫出顯示一條線. Simple DDA. Digital Differential Analyzer. ( x 2 ,y 2 ). ( x 1 ,y 1 ). 第一象限 first octant. x end > x start y end > y start Length=(x end - x start )>(y end - y start ) Slope=(y end - y start ) /Length. Simple DDA.
E N D
Chapter 4 元素 Scan-Converting a LINE 畫出顯示一條線 Simple DDA Digital Differential Analyzer (x2,y2) (x1,y1)
第一象限 first octant xend> xstart yend>ystart Length=(xend-xstart)>(yend-ystart) Slope=(yend-ystart) /Length
Simple DDA Digital Differential Analyzer (x2,y2) (x2,y2) (x1,y1) (x1,y1)
Left to Right (Left to Right) (Left to Right)
Right to Left ( Right to Left) x1 x2 ( Right to Left) y1 y2
Simple DDA (x2,y2) (x1,y1) +m
Simple DDA (x2,y2) (x1,y1) -m
Simple DDA Example : From (2,2) to (7,8) (x1,y1) (x2,y2) (7,8) , (2,2)
Simple DDA Example From (6,-2) to (-4,2) (x1,y1) (x2,y2)
Bresenham’s Line Algorithm 1. Left end point (x1,y1) Right end point (x2,y2) 2. First point (x1,y1)
Bresenham’s Line Algorithm(Cont.) 3. if if 4. Until X2 is reached
Bresenham’s Line Example (8,5) From (1,1) to (8,5) (1,1) 解:
Bresenham’s Line Algorithm 1. Left end point (x1,y1) Right end point (x2,y2) 2. First point (x1,y1)
Bresenham’s Line Algorithm(Cont.) 3. if if 4. Until X2 is reached
Bresenham’s Line Example (7,8) From (2,2) to (7,8) (2,2) 解:
Ⅱ Ⅰ Ⅲ Ⅳ Quadrantal DDA 4 個象限的DDA Use line error (tracking sum) No float point calculation 4 Quadrant 象限 開始 e=0
4 Quadrant 象限 Ⅱ Ⅰ Ⅲ Ⅳ Ⅰ Quadrant 1 Rules 1.if error <0, move +x ,add to error 2.if error 0, move +y ,add to error Ⅱ Quadrant 2 Rules 1.if error <0, move –x ,add to error 2.if error 0, move +y ,add to error Ⅲ Quadrant 3 Rules 1.if error <0, move –x ,add to error 2.if error 0, move –y ,add to error Ⅳ Quadrant 4 Rules 1.if error <0, move +x ,add to error 2.if error 0, move –y ,add to error
Quadrantal DDA Example x2>x1 From (2,2) to (7,8) I{ y2>y1 開始 e=0
Quadrantal DDA Example(Cont.) From (2,2) to (7,8)
Octantal DDA 2 3 4 1 8 octants 象限 5 8 6 7 Octant 1 Rules: 1.if error <0, move +x ,add to error 2.if error 0, move +x+y ,add to error
2 3 8 octants 象限 4 1 8 5 Octant 2 Rules: 6 7 1.if error <0, move +x+y ,add to error 2.if error 0, move +y ,add to error Octant 3,4,5,6 Rules: Swap start point and End point , Draw as 1,2,7,8 Octant 7 Rules: 1.if error <0, move +x-y ,add to error 2.if error 0, move –y ,add to error Octant 8 Rules : 1.if error <0, move +x ,add to error 2.if error > 0, move +x–y ,add to error
Octantal DDA Example From (2,2) to (7,8) 2 Octant 2 Ⅱ
Octantal DDA Example(Cont.) From (2,2) to (7,8)
Scan-Converting a Circle y Pythagoream Theorem x Stepping along x axis Unit steps from x = (xc-r) to x = (xc+r) Calculate y Not Uniform
Parametric Polar r fixed step angular value step size 1/r
Bresenham’s Circle Algorithm 1. first point (x1 , y1)=(0 , r) 2.P1= 3-2r if P1<0, If P1 0, 3. Plot 8 points (x,y), (-x,y) , (x,-y) , (-x,-y) , (y,x) , (-y,x) , (y,-x) , (-y,-x) 4. Until x y
Bresenham’s Circle 1/8圓
Incremental Drawing 圓上的連續兩點產生 Two consecutive points (x1,y1) , (x2,y2) is a fixed angular step size { (x3,y3) (x2,y2) 先畫1/8 circle , 再畫全圖 (x1,y1)
Mid point Circle Algorithm Input r , (xc,yc) 1. First point (x0,y0)=(0 , r) 2. 3. k =0,… If ,Next point (xk+1,yk) Otherwise , Next point (xk+1,yk-1) 4.決定其他對稱象限 5. 圓心 6. 直到
例: r =10 第一象限 from x = 0 to x = y P0=1-r = -9 (x0,y0)=(0,10) 2x0 =0 , 2y0=20