- Home
- Documents
- 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.

Published on

14-Jan-2016View

213Download

0

Transcript

<ul><li><p>**</p></li><li><p>We could solve for y in terms of x( x0, y0 ) are the origin points</p><p>A Simple Circle Drawing AlgorithmThe equation for a circle is:</p><p>where r is the radius of the circleOR**</p></li><li><p>Let r = 20** x0 = 0</p></li><li><p>However, unsurprisingly this is not a brilliant solution!</p><p>Firstly, the resulting circle has large gaps where the slope approaches the vertical</p><p>Secondly, the calculations are not very efficientThe square (multiply) operationsThe square root operation try really hard to avoid these!</p><p>We need a more efficient, more accurate solution**</p></li><li><p>Parametric polar representationx = r . cos ()y = r . sin ()x = xc + r . cos ()y = yc + r . sin ()ORArc Lengthx1 = r . cos ()x2 = r . cos ( + d)y1 = r . sin ()y2 = r . sin ( + d)d: is a fixed angular step size **</p></li><li> x2 = x1 . cos (d) y1 . sin (d)y2 = y1 . cos (d) + x1 . sin (d)By using trigonometry ... getdtheta = 1/r ;cdetheta = cos (dtheta) ;sdetheta = sin (detheta) ;x = 0 ;y = r ;while (x</li><li><p>Bresenhams algorithm for circlesKey idea: compute the initial octant only</p></li><li><p>Bresenhams incremental circle algorithmExample: 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)**</p></li><li><p>**</p></li><li><p>Eight-Way SymmetryThe first thing we can notice to make our circle drawing algorithm more efficient is that circles centred at (0, 0) have eight-way symmetry**</p></li><li><p>Mid-Point Circle AlgorithmSimilarly to the case with lines, there is an incremental algorithm for drawing circles the mid-point circle algorithmIn 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 pointsAssume that we have just plotted point (xk, yk)The next point is a choice between (xk+1, yk) and (xk+1, yk-1)We would like to choose the point that is nearest to the actual circleSo how do we make this choice?**</p></li><li><p>**Note: When x-axis increased by one unit, then the y-axis either increased by one or not</p></li><li><p>Assuming we have just plotted the pixel at (xk,yk) so we need to choose between (xk+1,yk) ( A), or (xk+1,yk-1) (B)... By comparing distance between points and the real circle line.dA = (xk + 1)2 + yk2 r2 dB = (xk + 1)2 + (yk -1)2 r2Now check the point with smallest distance, by checking the sum of (dA, and dB)S = dA + dBWhat are the probabilities of S value?**</p></li><li><p>1. Line between A and BdA > 0 and dB < 02. If the circle line pass through or up of AdA 0 and dB >= 0S > 0 choose B**</p></li><li><p>RULEIf S >0 choose pixel B Else choose A**</p></li><li><p>Ellipsesx = a . cos () OR x = xc + a . cos ()</p><p>y = b . sin() OR y = yc + b . sin() **</p></li><li><p>To draw ellipse:</p><p>The ellipse has four points symmetryIncrement angle with very small value (d)Find (x2, y2) from point (x1, y1)Find (x2, y2) according to the following equations</p><p>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**</p></li><li><p>Home work / draw the following figure**</p></li><li><p>Home work / draw the following figure**</p></li></ul>