Home | | Syllabus | | Assignments | | Documentation

    Solution to Assignment 2


    Problem 1: Mapping from Clipping Rect to ViewPort

    Consider the following figure:

    To make all the points along a horizontal line in the clipping window map onto all the points in the viewport, we must have the relationship:

    a/b = c/d

    Where,

      a = (x - x_min)

      b = (x_max - x_min)

      c = xs - u

      d = w

    Therefore:

    (x - x_min)/(x_max - x_min) = (xs - u)/w.

    Solving algebraically for xs, we have:

    xs = u + w*(x - x_min) / (x_max - x_min)

    We can solve for the vertical mapping similarly:

    ys = v + h*(y - y_min) / (y_max - y_min)


    Problem 2: Alquerque

    There are many ways to solve this problem. Here is one solution with the referee included:

    C code for solution to alquerque problem


    Home | | Syllabus | | Assignments | | Documentation


    Constance Royden--croyden@mathcs.holycross.edu
    Computer Science 384
    Date Created: August 17, 1999
    Last Modified: October 1, 2003
    Page Expires: August 17, 2004