COS 426 / Assignment 3


An exercise in drawing circles

Due 11:59 PM, Tuesday, October 24, 1995

This assignment will allow you to explore a variety of different approaches to the drawing of circles. In so doing, we will reinforce the class lectures on scan conversion. As in the previous assignment, we will provide a user interface and you will be asked to plug in your circle drawing algorithms. Once the assignment is completed, you'll be asked to answer some questions about the comparative aesthetics (and speed) of the various drawing methods.

We will consider 4 methods of drawing circles.

  1. This is the standard Bresenham method described in class and in the textbook. It is based on the DDA approach and uses symmetries to consider only points in one octant, plotting each point 8 times symmetrically.

  2. This is an approximation to the circle via a regular polygon of N sides. You will first need to implement Bresenham's algorithm for drawing line segments. Then, you will compute the vertices of a regular N-gon of appropriate radius and center. Finally, these vertices will be joined by line segments to form the polygon that approximates the circle.

  3. This is an approximation to the circle by cubic spline curves. You are to implement the Bezier method discussed in class for drawing a curve from 4 control points. Having done so, you must then find values and derivatives for points around the circle. These data will be used to create sets of control points to be used as input to your Bezier routines. The output of your Bezier routines will then be patched together to form a circle. The user supplies the number of patches, from which you can find the starting and ending point of each patch.

  4. This is an approximation to the circle by sampling. What you are to do is to choose k points in each pixel. For each point, determine if it intersects the circle boundary. Record which fraction of the sample points intersect the boundary. Color the pixel in this fraction. Begin with k = 1 and color pixels either black or white. Then, extend to larger values of k and do gray scale coloring. Typically, you want k to be a perfect square so it's reasonable to choose the sequence 1,4,9, ...
    In order for this method to work, you need to thicken the circle boundary. You can do so testing sample points to see if they are within .5 unit of the boundary (why?). For reasons of efficiency, you will want to identify those pixels that need not be tested and focus your attention on those that might be relevant.


Once you have all the circle routines working, you are required to experiment with them for circles of varying radius. When doing so, notice which routines are faster and which slower. You are to create a file called WhatIveLearned that you submit with your code. This file should contain your conclusions about the tradeoffs in circle drawing.


To see a fully working example program, run this:

/u/cs426/bin/circles

The circle drawing functions are implemented as: Your job will be to write code for these functions. You will also need to fill in code for bresenham_line(int x1, int y1, int x2, int y2), which is used by ngon_circle.

Copy the directory

/u/cs426/Examples/Circles
You'll find files bresenham.c, ngon.c, bezier.c, and sample.c, which contain empty functions that you'll have to fill in. Whenever you see the string WORK HERE, you will have some work to do.

When you type make, you'll be building a program called cirwish. The wish script for cirwish is circles.


Some general issues:

When you're done, please submit: