CSCI 384 Computer Graphics

    College of the Holy Cross, Fall 2003

    Home | | Syllabus | | Assignments | | Documentation

    Assignment 3

    Due: Thursday, October 2, in class


    NOTE: The first midterm exam will be given on Tuesday, October 7. The exam will include problems on geometric transformations, so it is important that you complete this assignment to gain practice working with such transformations. Also, I will be posting the formal solutions to this assignment on the course webpage on on Friday, October 3, so you must submit your assignment by 12:00 p.m. Friday, October 3 for any credit. Any assignments turned in after this time will not be accepted.


    Problem 1:

    In this problem, you will use openGL functions for implementing geometric transformations to construct a given design. Specifically, you will make use of the openGL functions, glTranslatef(dx, dy, dz), glRotatef(angle, vx, vy, vz), and glScalef(sx, sy, sz) to create the pattern shown below. Recall that glTranslate multiplies the model matrix by a translation matrix that will translate all vertices in a direction and distance given by the vector (dx, dy, dz). glRotate rotates the vertices by the specified angle (in degrees!) about an axis of rotation specified by the vector components vx, vy and vz. Finally, glScalef scales the vertices by the factors sx, sy and sz (in the x, y and z directions, respectively).

    Your task is to apply these transformations a square to create (approximately) the following pattern:

    You must begin with the following matrix definitions:

      For the projection matrix use the following:
      	glMatrixMode(GL_PROJECTION);
      	glLoadIdentity();
      	gluOrtho2D(-250.0, 250.0, -250.0, 250.0);
      	glMatrixMode(GL_MODELVIEW);
      

      For the Window size, use: glutInitWindowSize(500,500);

      If you specify a viewport, it should also be 500 x 500 pixels.

    You must define only four vertices in your code, given as follows:

    	typedef GLfloat point2[2];
    	point2 vertices[4];
    
    	GLfloat x=-1.0, y=-1.0;
    	GLfloat side = 2.0;
    	
    	vertices[0][0] = x;
    	vertices[0][1] = y;
    	vertices[1][0] = x + side;
    	vertices[1][1] = y;
    	vertices[2][0] = x + side;
    	vertices[2][1] = y + side;
    	vertices[3][0] = x;
    	vertices[3][1] = y + side;
    

    These vertices produce a very small version of the following square:

    Without redefining any of these vertices, use the transformation functions of openGL to create the pattern. To get started, try to figure out how to create each of the petals from transforming the square. Decide what transformations you would use to create the following:

    Once you have the individual pieces, you need to transform and draw them in the proper orientations and positions. Try to make your code as compact as possible-- in particular, use loops to create parts of the design at different orientations. Because you will be creating multiple squares and transforming each of them in a slightly different way, you should remember to use glPushMatrix() and glPopMatrix() before and after each transformation and drawing. Hand in a printout of your code, and drop off the file containing the c code (named <username>_transform.c) on the K drive.


    Problem 2: Creating a New Transformation

    In the description of scaling on page 166 of the textbook, it notes that a reflection is just a scaling by a negative factor, alpha. Thus, if we want to reflect a 2-D image across the x axis, we would scale the y coordinate by a factor of -1. Thus, we could produce a scaling matrix, S(1, -1, 1).

    On pages 201-203 of the Hearn and Baker text "Computer Graphics, C version" (Prentice Hall, 1997), there is a description of reflections of coordinates around different axes. On the top of page 203, the authors state:

    "Reflections about any line y = mx+b in the xy plane can be accomplished with a combination of translate-rotate-reflect transformations. In general, we first translate the line so that it passes through the origin. Then we can rotate the line onto one of the coordinate axes and reflect about that axis. Finally, we restore the line to its original position with the inverse rotation and translation transformations."

    Your task in this problem is to compute a matrix, T, to reflect about an arbitrary line given by y = mx + b. The elements in the reflect matrix should be based on the quantities m and b (from the equation of the line). Before you start, you will need to answer the following questions: What translation can be used to shift the line so that it passes through the origin? What angle of rotation can be used to rotate the line so that it is aligned with one of the coordinate axes (hint: you can use the slope of the line to derive this angle)? How does a reflection about one of the coordinate axes alter the coordinates of the points? On paper, derive a set of equations that specify the new coordinates x', y', z' in terms of the old coordinates x, y and z that would result from applying the following five transformation steps: (1) translation that shifts the axis (line) of reflection to the origin, (2) rotation that aligns this axis of refection with one of the coordinate axes (either x or y), (3) reflection of the points around this coordinate axis, (4) reverse rotation used in step (2), and (5) reverse translation used in step (1). Determine the Transformation matrices for each of these steps. Multiply them together (make sure you put them in the correct order) to determine a single 4 x 4 matrix that can be multiplied by the point (x,y,z,1) to yield the new point (x', y', z', 1) that is a reflection of the original point about the line.

    Based on this matrix, write out the equations x' and y' in terms that depend on x, y, m, and b. (Note that z' = z, since we are dealing with just the 2D reflection). Be sure to simplify the expressions by noting, for example, that

      cos(-a) = cos(a)
      sin(-a) = - sin(a).

    Hand in your written derivation of the equations for generating the new coordinates. Make sure to show all your work.


    Turning in this assignment

    Turn in a hardcopy of the C code for problem 1 and the derivation of the reflect matrix T for problem 2. This is due in class, Thursday, October 2.

    In addition, email a copy of the file, named "<username>_transform.c", containing your C code to me at croyden@mathcs.holycross.edu. The subject line should read "Graphics Assignment 3".


    Home | | Syllabus | | Assignments | | Documentation


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