Computer Graphics CSC418/2504F, Fall 1999: Assignment 1

Due date: in class, 8 Oct. 1999.

Solutions

Marking:
Questions Marker Hours (in SF 4301)
1-4 Steve La Thursday Oct 21, 3pm
5-6 Ryan Meredith-Jones Tuesday Oct 19, 1pm

The marking scheme for questions 5 & 6 available online.

  1. Raster Displays:
    1. [1 mark] Consider a non-interlaced raster monitor with h scan lines, and w pixels per scan line, a refresh rate of r frames per second, horizontal retrace time of th, and vertical retrace time time of tv. What fraction of the frame time is spent retracing the electron beam?
    2. [1 mark] A monitor is 8 inches high and 10 inches wide, and displays 100 pixels/inch. The frame buffer refreshing it uses 24 bits/pixel. What is the byte offset in the frame buffer of the pixel with screen coordinates (x,y)?


  2. Clipping:
    1. [3 marks] Assuming a rectangular clipping window, with XL=0, XR=100, YB=0, YT=100, use the Sutherland-Hodgman algorithm to clip the following polygon against the B,R,T and L sides of the window:

      i 1 2 3 4 5 6
      xi 10 60 60 120 60 40
      yi 70 -20 40 20 120 70

      Show the intermediate states of the polygon.

    2. [2 marks] The Sutherland-Hodgman algorithm assumes the clipping window is convex. Give an example where the algorithm fails with a non-convex clipping window.


  3. Transformations: Assuming two-dimensional transformations, show that the following pairs of operations do or do not commute:
    1. [2 marks] Two rotations commute.
    2. [2 marks] A rotation and a uniform scaling (sx=sy) commute.
    3. [1 mark] A rotation and a non-uniform scaling do not commute.


  4. Reflections: Assume a two-dimensional space.
    1. [1 mark] Give the homogeneous (3 x 3) matrix representing a reflection about the x axis.
    2. [2 marks] Give the matrix for a reflection about a line which passes through the origin and makes an angle a with the x-axis (Hint: how do we rotate around non-origin points?).
    3. [2 marks] Given an n by n raster of pixels such that pixel a[x][y] is displayed at (x,y), write a code fragment to reflect the pixels about the line x=y.
    4. [2 marks] Reflect the same raster about the line x+y=n-1.


  5. Scan Conversion: Write programs to determine whether a point is inside a polygon. For simplicity, assume the test point is the origin (0,0). The programs should output the word "inside" or "outside", and should expect the following inputs:
    1. n, the number of vertices in the polygon.
    2. n pairs of numbers, each pair being the coordinates of a polygon vertex.

    1. [4 marks] Use the Jordan Curve theorem: The test point is inside the curve iff an infinite ray from the point crosses the boundary an odd number of times. For simplicity, let the ray be the positive x-axis.
      NOTE: some printed handouts incorrectly read even, not odd.

    2. [4 marks] Use the non-zero winding number rule: The winding number counts the number of times the polygon edges wind around the point. A polygon winds once if the sum of the angles subtended by its edges is 360 degrees. CCW edges subtend positive angles, CW edges negative. A point is defined to be inside if the winding number is non-zero. Suggestion: use the atan2 function.

      Can you avoid trigonometric functions? (not easy).

    3. [1 mark] Will the two programs give the same results? (Hand in your written answer with questions 1 to 4).

    Submit your commented code using one of the following.

         submit -N a1q5 csc418h jordan.cpp winding.cpp
         submit -N a1q5 csc2504h jordan.cpp winding.cpp
    


  6. [6 marks] OpenGL: Use the openGL library to create an interesting scene. Procedures for drawing objects such as a teapot, cone, torus, and sphere are already provided for you. However, you are also encouraged to construct your own objects from polygons. For example, surfaces of revolution are easy to construct (consult your TA). A prize will be given for the best scene. Marking will consider use of transformations, colour, and originality. Template code can be found at:
    http://www.dgp.toronto.edu/~ah/csc418/fall_1999/tut/glscene

    In order to save your image, type 's' while the keyboard focus is on the graphics window. This will save the current image as the file 'scene.ppm'. Use xv (Unix) or xnview (Windows) in order to convert your image to the more economical gif format.

    Submit your commented code and image using one of the following.

         submit -N a1q6 csc418h scene.cpp scene.gif
         submit -N a1q6 csc2504h scene.cpp scene.gif
    

    Several excellent scenes were submitted. Look here for the winning scene, and honorable mentions.