CS U540 Sample Problems


      (Midpoint Circle Algorithm)

Below is the circle routine that appears on page 102 of Hearn and Baker (modified slightly to work on my MAC).

void circleMidpoint(int xCenter, int yCenter, int radius){
	int x = 0;
	int y = radius;
	int p = 1 - radius;
	void circlePlotPoints(int xCenter, int yCenter, int x, int y);
	
	/* Plot first set of points */
	circlePlotPoints(xCenter, yCenter, x, y);
	
	while (x < y) {
		x++;
		if (p < 0)
			p += 2*x + 1;
		else {
			y--;
			p += 2 * (x-y) + 1;
		}
		circlePlotPoints(xCenter, yCenter, x, y);
	}
}
void circlePlotPoints(int xCenter, int yCenter, int x, int y){
// SetColorPixel(x, y, r, g, b);  sets the pixel (x, y) to rgb (r, g, b)
	SetColorPixel(xCenter + x, yCenter + y, 0, 0, 0);
	SetColorPixel(xCenter - x, yCenter + y, 0, 0, 0);
	SetColorPixel(xCenter + x, yCenter - y, 0, 0, 0);
	SetColorPixel(xCenter - x, yCenter - y, 0, 0, 0);
	SetColorPixel(xCenter + y, yCenter + x, 0, 0, 0);
	SetColorPixel(xCenter - y, yCenter + x, 0, 0, 0);
	SetColorPixel(xCenter + y, yCenter - x, 0, 0, 0);
	SetColorPixel(xCenter - y, yCenter - x, 0, 0, 0);
}
Assume that you have a function:
void HLine(int x1, int x2, int y);
that efficiently draws the horizontal line from (x1, y) to (x2, y).
For each of the shapes on below, show the changes you would make, to the circle code, to generate the shape shown. USE HLine.


Last Updated: May 27, 2004 5:20 p.m. by
Harriet Fell
College of Computer Science, Northeastern University
360 Huntington Avenue #WHV-340,
Boston, MA 02115
Internet: fell@ccs.neu.edu
Phone: (617) 373-2198 / Fax: (617) 373-5121
The URL for this document is: http://www.ccs.neu.edu/home/fell/CSU540/exams/CircleProblem.html