Home | | Syllabus | |
Assignments | | Lecture Notes | |
Documentation
Assignment 3Due: Thursday, September 28NOTE: The first midterm exam will be given on Tuesday, October 3. The exam will include problems on geometric transformations, so it is important that you complete this assignment on time to gain practice working with such transformations.
Problem 1: In this problem, you will use WebGL and matrix functions provided by the textbook (in MV.js) for implementing geometric transformations to construct a given design. Specifically, you will make use of the MV.js functions, translate(dx, dy, dz), rotate(angle, vx, vy, vz), and scalem(sx, sy, sz) to create the pattern shown below. Note: Do not use the shear transformation. This makes the task much harder! Note: There is a bug in the MV.js code provided by the authors of the book. If you downloaded your Common folder from the author's site, it may still have this bug. If you downloaded your Common folder from the course website, the bug has been fixed and you don't need to do anything further. If you downloaded from the author's website, you can re-download the zip files for the CommonWindows.zip or CommonLinux.zip (that also works on Macs) from the course documentation page. Recall that the translate(dx, dy, dz) function creates a translation matrix that, when multiplied with the model matrix, will translate all vertices in a direction and distance given by the vector (dx, dy, dz). rotate(angle, vx, vy, vz) creates a matrix that rotates the vertices by the specified angle (in degrees!) about an axis of rotation specified by the vector components vx, vy and vz. Finally, scalem(x, y, z) generates a matrix that 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:
Choose the dimensions of each petal of the flower so that it looks as similar as possible to the flower shown above. There are two strict requirements. First, the center vertex of each petal must be positioned at the point (0, 0) in the clipping rectangle. Second, the diamonds that are inside the squares located around the outside must fit exactly in the square. In other words, you must calculate the side length of the diamond relative to the side length of the square so that each vertex of the diamond falls on the border of the square at the center of the square side. You must begin with the following matrix definitions: For the canvas size, use: <canvas id="gl-canvas" width="500" height="500"> The viewport should also be 500 x 500 pixels. You must define only four vertices in your code, given as follows: var vertices = [ ]; //This should be a global variable ... var x=-0.1; //Lower left corner var y=-0.1; var side = 0.2; vertices.push(vec2(x, y)); vertices.push(vec2(x+side, y)); vertices.push(vec2(x+side, y+side)); vertices.push(vec2(x, y+side)); These vertices produce a version of the following square:
Without redefining any of these vertices or adding any more vertices, use the transformation matrices (translation, rotation and scale, but not shear) to transform the square and 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. Hand in a printout of your code, and upload the files containing the JavaScript code and your html code (named flower.js, and flower.html) to Canvas.
Problem 2: Creating a New Transformation In the description of scaling on page 159 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 reflection 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:
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). Derive these equations using the following method:
Hand in:
Make sure to show all your work.
Turning in this assignment
Home | | Syllabus | | Assignments | | Lecture Notes | | Documentation
Constance Royden--croyden@holycross.edu.edu
|