@Don: The sequence of points (x+a, y+b) generated by your algorithm moves along the arc of the circle from theta = 90 degrees to theta = 45 degrees. Along this arc, the slope of the curve is -1 <= dy/dx <= 0. Thus, rather than moving from (x+a, y+b) to either (x+a+1, y+b) or (x+a, y+b-1), you should be moving to either (x+a+1, y+b) or (x+a+1, y +b-1). In words, you always increase a, and decrease b when that gets you closer to the circle. Furthermore, you can algebraically simplify the comparison so that no multiplications are required. See, e.g., http://homepage.smc.edu/kennedy_john/bcircle.pdf.
Dave On Aug 5, 1:06 pm, Don <dondod...@gmail.com> wrote: > // Draw a circle with center (x,y) and radius r > circle(int x, int y, int r) > { > int a = 0; > int b = r; > while(a <= b) > { > // Draw the current location in all 4 quadrants > plot(x+a, y+b); > plot(x-a, y+b); > plot(x+a, y-b); > plot(x-a, y-b); > plot(x+b, y+a); > plot(x-b, y+a); > plot(x+b, y-a); > plot(x-b, y-a); > > // Look at two possible next points and pick the better > int delta1 = r*r - (a+1)*(a+1) - b*b; > int delta2 = r*r - a*a - (b-1)*(b-1); > if (delta1*delta1 < delta2*delta2) ++a; > else --b; > } > > } > > On Aug 5, 8:38 am, rShetty <rajeevr...@gmail.com> wrote: > > > > > Write a routine to draw a circle (x ** 2 + y ** 2 = r ** 2) without > > making use of any floating point > > computations at all.- Hide quoted text - > > - Show quoted text - -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.