Presentation is loading. Please wait.

Presentation is loading. Please wait.

November 18, 20151. We could solve for y in terms of x ( x 0, y 0 ) are the origin points A Simple Circle Drawing Algorithm The equation for a circle.

Similar presentations


Presentation on theme: "November 18, 20151. We could solve for y in terms of x ( x 0, y 0 ) are the origin points A Simple Circle Drawing Algorithm The equation for a circle."— Presentation transcript:

1 November 18, 20151

2 We could solve for y in terms of x ( x 0, y 0 ) are the origin points A Simple Circle Drawing Algorithm The equation for a circle is: where r is the radius of the circle OR November 18, 20152

3 Let r = 20 November 18, 20153 x 0 = 0

4 However, unsurprisingly this is not a brilliant solution! Firstly, the resulting circle has large gaps where the slope approaches the vertical Secondly, the calculations are not very efficient The square (multiply) operations The square root operation – try really hard to avoid these! We need a more efficient, more accurate solution November 18, 20154

5 Parametric polar representation x = r. cos (ө) y = r. sin (ө) x = x c + r. cos (ө) y = y c + r. sin (ө) OR Arc Length x1 = r. cos (ө) x2 = r. cos (ө + dө) y1 = r. sin (ө) y2 = r. sin (ө + dө) dө: is a fixed angular step size November 18, 20155

6 x 2 = x 1. cos (dө) – y 1. sin (dө) y 2 = y 1. cos (dө) + x 1. sin (dө) By using trigonometry... get dtheta = 1/r ; cdetheta = cos (dtheta) ; sdetheta = sin (detheta) ; x = 0 ; y = r ; while (x<=y){ Plotpixel (x, y) ; // for eight points xtemp = x ; x = x * cdetheta – y * sdetheta ; y = y * cdetheta + xtemp * sdetheta ; } November 18, 20156 Help for programming

7 Bresenham’s algorithm for circles Key idea: compute the initial octant only Generate first octant 1 Reflect first octant about y=x 2 Reflect first quadrant about x=0 3 Reflect upper semicircle about y=0 4

8 Bresenham’s incremental circle algorithm Example: circle of radius 8 Bright pixels: initial pixel (0,8) (1,8) (2,8) (3,7) (4,7) (5,6) (6,5) (7,4) (7,3) (8,2) (8,1) end pixel (8,0) November 18, 20158

9 9

10 Eight-Way Symmetry The first thing we can notice to make our circle drawing algorithm more efficient is that circles centred at (0, 0) have eight-way symmetry November 18, 201510

11 Mid-Point Circle Algorithm Similarly to the case with lines, there is an incremental algorithm for drawing circles – the mid-point circle algorithm In the mid-point circle algorithm we use eight-way symmetry so only ever calculate the points for the top right eighth of a circle, and then use symmetry to get the rest of the points Assume that we have just plotted point (x k, y k ) The next point is a choice between (x k +1, y k ) and (x k +1, y k -1) We would like to choose the point that is nearest to the actual circle So how do we make this choice? November 18, 201511

12 November 18, 201512 Note: When x-axis increased by one unit, then the y-axis either increased by one or not

13 Assuming we have just plotted the pixel at ( x k,y k ) so we need to choose between ( x k +1,y k ) ( A), or ( x k +1,y k -1 ) (B)... By comparing distance between points and the real circle line. dA = (x k + 1) 2 + y k 2 – r 2 dB = (x k + 1) 2 + (y k -1) 2 – r 2 Now check the point with smallest distance, by checking the sum of (dA, and dB) S = dA + dB What are the probabilities of S value? November 18, 201513

14 1. Line between A and B dA > 0 and dB < 0 If abs (dA) > abs (dB) S >0 choose B If abs (dA) <= abs (dB) S<= 0 choose A 2. If the circle line pass through or up of A dA <= 0 and dB < 0 S < 0 choose A 3. If the circle line pass through or under the point B dA > 0 and dB >= 0 S > 0 choose B November 18, 201514

15 RULE If S >0 choose pixel B Else choose A November 18, 201515

16 Ellipses x = a. cos (ө) OR x = x c + a. cos (ө) y = b. sin(ө) OR y = y c + b. sin(ө) November 18, 201516

17 To draw ellipse : 1.The ellipse has four points symmetry 2.Increment angle with very small value (dө) 3.Find (x2, y2) from point (x1, y1) 4.Find (x2, y2) according to the following equations x2 = x1. cos (dө) – (a/b). y1. sin (dө) y2 = y1. cos (dө) + (b/a). x1. sin (dө) The start point will be (0, a) Ending of loop when x = b November 18, 201517

18 Home work / draw the following figure November 18, 201518

19 Home work / draw the following figure November 18, 201519


Download ppt "November 18, 20151. We could solve for y in terms of x ( x 0, y 0 ) are the origin points A Simple Circle Drawing Algorithm The equation for a circle."

Similar presentations


Ads by Google