CS U540 Computer Graphics Sample Exam Problems

     
(Scalable Drawing)

Write a function that takes integer arguments x, y, width, and height and draws the picture shown below. The sky is blue; the cloud is white; the house is red; the window and door are black.

The picture is shown in different positions with different heights. It is also shown twice with a super-imposed grid so that you can tell where the cloud, house, door, and window are within the drawing. Your function should not draw the grid.


(Bresenham Line Algorithm)

Show the values of the decision function and the pixels selected by the Bresenham line algorithm for the line from (3, 2) to (11, 7).

Bresenham's Line Algorithm for |m| < 1

1.  Input the two endpoints and store the left endpoint in (x0, y0).
2.  Load (x0, y0) into the frame buffer; i.e. plot the first point.
3.  Calculate the constants deltax, deltay, 2deltay, and 2deltay - 2deltax, and 
     obtain the starting value for the decision function p0 = 2deltay - deltax.
4.  At each xk along the line, starting at k = 0, perform the following test:
     If pk < 0, the next point to plot is (xk + 1, yk) and pk+1 = pk + 2deltay.
    Otherwise the next point to plot is (xk + 1, yk + 1) and 
	   pk +1 = pk + 2deltay - 2deltax.
5.  Repeat step 4 deltax times.
For the region shown below, assume BoundaryValue = black, FillValue = gray and that SEED_FILL(4, 6) has been called.

kpk   xy
  32
0 4 
1 5 
2 6 
3 7 
4 8 
5 9 
6 10 
7 117


(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.


(Flood or Seed Fill)

Below is a pseudocode for a recursive seed fill.

void SEED_FILL(int x, int y){
	if ((PIXEL_VALUE(x, y) != BoundaryValue)
		 && (PIXEL_VALUE) != FillValue)){
		SET_PIXEL(x, y, FillValue);
		SEED_FILL(x + 1, y);
		SEED_FILL(x - 1, y);
		SEED_FILL(x, y + 1);
		SEED_FILL(x, y - 1);
	}
}
For the region shown below, assume BoundaryValue = black, FillValue = gray and that SEED_FILL(4, 6) has been called.

a. Number the pixels in the order they are set by the SET_PIXEL(x, y, FillValue) call.

b. Show the stack of recursive calls at the time each pixel is set. How deep does the stack get?


(Scan Line Fill)

Given the polygon in the diagram below:

a. Create an Edge Table for the polygon (after preporcessing).

y
7
6
5
4
3
2
1
0

b. For each value of y, tell which edges are in the active edge table.
y-------------------- edges --------------------
7 
6 
5 
4 
3 
2 
1 
0 


(Transformations and Matrices)

a. Starting from the picture above, show the effect of applying this sequence of transforms to the triangle.

b. Starting from the picture above, show the effect of applying this sequence of transforms to the triangle.


(Cohen-Sutherland Line Clipping)

a. If the Cohen-Sutherland Clipping Algorithm is run on the Line PQ and the clipping is done in the order TOP, LEFT, BOTTOM, RIGHT, how many clip boundaries must be investigated and how many changes are made to the endpoints and in what order?

b. What happens if the order is RIGHT, BOTTOM, LEFT, TOP?


(Sutherland-Hodgeman Polygon Clipping)

Show the effects of the Sutherland-Hodgeman clipping algorithm as applied to the polygon ABCDEFGH relative to the window below. Clip in the order LEFT, TOP, RIGHT, BOTTOM and give the list of vertices after each side is processed. Label the new vertices on the picture and show the final, filled polygon by coloring the appropriate regions and stray edges.


(Bezier Curves)

Below are two four-point configurations intended to serve as Bezier arches. In each case, perform the geometric construction (using a ruler) to locate B(1/2) and sketch the entire Bezier curve determined by the arch.

NOTICE the changed places of Q and R.


(Cardinal Splines)

Given the points shown below, use a ruler to find the points to complete the Bezier arch with endpoints B and C for a Cardinal Spline through the points A, B, C, D. (Cardinal splines are the ones we talked about in class.) Explain your work.


(Ray-Tracing)

An infinite cylinder is given by the equation
(x - a)2 + (z - c)2 - R2 = 0

If a ray is given by the parametric equations:
x(t) = x0 + t(x1 - x0)     0 ≤ t ≤ 1
y(t) = y0 + t(y1 - y0)
z(t) = z0 + t(z1 - z0)

What are the coefficients A, B, and C in the quadratic equation used to solve for the intersection of the ray and the cylinder?


(Diffuse Shading)

A sphere of radius 7 has its center at (10, 10, 10). The point, (12, 13, 16), lies on the sphere. A unique light sources is located at (100, 100, 100).

a. Find the unit normal to the sphere at the point (12, 13, 16).

b. Find the unit vector in the direction from the point (12, 13, 16) to a light source at (100, 100, 100).

c. What is the factor for diffuse shading at the point (12, 13, 16)? Show the actual numbers used in the calculation. You do not have to complete the arithmetic.


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/SampleProblems.html