COS340A Assignment 1 I Pillemer Student# 3257 495 9 March 25 th 2007 p1/15 Assignment 1 I Pillemer Student#: 3257 495 9 COS340A Date submitted: March 25, 2007 Question 1... p2 3 Question 2... p4 Question 3(a)... p5 7 Question 3(b)... p8 p9 Question 4... p10 Question 5(a)... p11 Question 5(b)... p12 Question 5(c)... p13 Question 6... p14 p15
COS340A Assignment 1 I Pillemer Student# 3257 495 9 March 25 th 2007 p2/15 Question 1 (Exercise 1.2 in ICG) In computer graphics, objects such as spheres are usually approximated by simpler objects constructed from flat polygons (polyhedra). Using lines of longitude and latitude, define a set of simple polygons that approximate a sphere centered at the origin. Can you use only quadrilaterals or only triangles? Using lines of longitude, centered around the origin I have approximated a sphere from flat polygons. Every vertex is equidistant from the origin and I have created 15 longitudinal lines and 10 latitudinal lines by which flat polygons are defined. I have used OpenGL to create an image of this sphere approximation. I have also rotated the sphere approximation to create four views of the sphere approximated by these flat polygons defined by 15 lines of longitude and 10 lines of latitude. Figure 1 An investigation of the polygons thus defined provides an graphical answer to the second part of the question; namely can one use only quadrilaterals to form the sphere approximation;
COS340A Assignment 1 I Pillemer Student# 3257 495 9 March 25 th 2007 p3/15 and can one use only triangles to form the sphere approximation. If you look at Figure 1 you will see that most of flat polygons are quadrilaterals; and at the equator these quadrilaterals could almost be called squares. However as one looks at the polygons as they move closer and closer to the poles you can see that the polygons become increasingly skewed until eventually becoming triangles. This is inevitable in any approximation of a sphere using polygons; in which the polygons are being defined by lines of latitude and longitude. Thus graphically it is clear the the area around the poles can not be approximated by flat quadrilaterals; and only by flat triangles. Now that I have shown the reason why a sphere cannot be approximated by quadrilaterals graphically; let me attempt to also prove it logically using reductio ad absurdam. First, let us assume that one can construct an approximated sphere with quadrilaterals. One such quadrilateral must be touching a pole. This quadrilateral must also have a side that is lying against the first latitudinal line. Now a second polygon must necessarily lie next to this polygon and it must also be touching the pole. This means that the sides of the quadrilaterals lying against the pole must necessarily have no width ie must be triangular. However since the polygons sides are being defined by lines of longitude and latitude; two of its sides are being created from the pole by longitudinal lines; and end at the first latitudinal line. Thus the the two quadrilaterals lying side by side at the pole are triangles. This is absurd; therefore my original assumption is incorrect and therefore one cannot construct an approximated sphere defined by lines of longitude and latitude using only flat quadrilaterals. If one used only flat quadrilateral shapes the poles would have to have holes at the poles to account for the fourth side of the quadrilaterals lying side by side. However it is possible for a sphere to be approximated using only flat triangular polygons. I have already shown above that a sphere can be approximated by flat polygons between lines of latitude and longitude and flat triangles between the poles and the first line of latitude from either pole. Now, all quadrilaterals can by having a line drawn from one corner to corner that is not already connected by a line to it; be divided into two flat triangles. Thus it is possible to construct an approximated sphere with polygons defined by lines of longitude and latitude using only flat triangles.
COS340A Assignment 1 I Pillemer Student# 3257 495 9 March 25 th 2007 p4/15 Question 2 (Question 1.7 in ICG) Consider the perspective views of the cube shown in Figure 1.32. The one of the left is called a one point perspective because parallel lines in one direction of the cube along the sides of the top converge to a vanishing point in the image. In contrast, the image on the right is a two point perspective. Characterize the particular relationship between the viewer, or a simple camera, and the cube that determines why one is a two point perspective and the other a one point perspective. In the case of the one point perspective two faces of the cube are parallel to the projection plane from the viewer or simple camera. In the case of of the two point perspective the edges of the cube in one direction are parallel to the projection plane. Now to take this idea a little further, a three point perspective would be necessary if no edges and no faces of the cube were parallel to the viewer. There would now be three vanishing points from the perspective of the viewer; the third one vanishing above or below the horizon towards which the other two vanish. Escher uses a three point perspective in his artwork to curious effect and I have included a small copy of this artwork Ascending and Descending (Figure 2) both because it demonstrates three point perspective; and, for your amusement. Figure 2
COS340A Assignment 1 I Pillemer Student# 3257 495 9 March 25 th 2007 p5/15 Question 3 (a) /* two dimensional Koch snowflake */ /* generated using vector arithmatic */ /* and starting with an equilateral triangle */ #include <GL/glut.h> #include <math.h> #define RECURSION 3 void myinit() /* attributes */ glclearcolor(1.0, 1.0, 1.0, 1.0); /* white background */ glcolor3f(1.0, 0.0, 0.0); /* draw in red */ /* set up viewing */ /* 50.0 x 50.0 camera coordinate window with origin lower left */ glmatrixmode(gl_projection); glloadidentity(); gluortho2d(0.0, 50.0, 0.0, 50.0); glmatrixmode(gl_modelview); void swap(glfloat * a, GLfloat * b) GLfloat temp = *a; *a = *b; *b = temp; void divide_snowflake(glfloat *a, GLfloat *b, int n) int x=0; int y=1; GLfloat t[2][2]; GLfloat slope[2]; GLfloat midpoint[2]; GLfloat snowflake_point[2]; GLfloat y_magnitude;
COS340A Assignment 1 I Pillemer Student# 3257 495 9 March 25 th 2007 p6/15 int j; if (n>0) /* Using Pythagorus */ /* Special triangle has ratio of 1:sqrt(3):2 */ y_magnitude = sqrt(3.0); /* Find a point a third of the way along the line */ for ( j = 0; j < 2; j++) t[0][j] = a[j] +( b[j] a[j]) /3.0; /* Find a point two thirds of the way along the line */ for ( j = 0; j < 2; j++) t[1][j] = a[j] +( b[j] a[j]) /3.0 * 2.0 ; /* Find the midpoint */ for ( j = 0; j < 2; j++) midpoint[j] = a[j] +( b[j] a[j]) / 2.0 ; /* Find the vector for the relative base of the triangle */ for ( j = 0; j < 2; j++) slope[j] = (midpoint[j] t[0][j]); /* vector of slope */ /* I know this is the relative unit vector as this is a case of the special triangle 1:sqrt(3):2 */ swap(&slope[x],&slope[y]); /* normal vector with outward direction is required. In order to find that I am required to swap the dx,dy of the vector and then set the dx to dx.*/ slope[x] = slope[x]; /* Since I am working with the special triangle 1:sqrt(3):2 I know that relatively the magnitude of the vector will be sqrt(3) * the unit vector. I add the vector to the midpoint to locate the x,y position of the tip of the new koch snowflake point. */ for ( j = 0; j < 2; j++) snowflake_point[j] = midpoint[j] + y_magnitude * slope[j]; /* locate point */ /* I now make the recursive calls for all the new lines. */ divide_snowflake(a,t[0],n 1); divide_snowflake(t[0],snowflake_point,n 1); divide_snowflake(snowflake_point,t[1],n 1); divide_snowflake(t[1],b,n 1); else glvertex2fv(a); glvertex2fv(b);
COS340A Assignment 1 I Pillemer Student# 3257 495 9 March 25 th 2007 p7/15 void koch(glfloat *a, GLfloat *b, GLfloat *c, int n) divide_snowflake(a,b,n); divide_snowflake(b,c,n); divide_snowflake(c,a,n); void display() /* determine the vertexes of a equilateral triangle. */ GLfloat side = 30; GLfloat xstart = 10.0; GLfloat ystart = 18.0; GLfloat v[3][2] = xstart,ystart,xstart + side/2.0, ystart + side/2.0*sqrt(3),xstart + side, ystart; glclear(gl_color_buffer_bit); /*clear the window */ glbegin(gl_lines); /* Make the call to draw the snowflake. */ koch(v[0],v[1],v[2],recursion); glend(); glflush(); /* clear buffers */ int main(int argc, char** argv) /* standard GLUT initialization */ glutinit(&argc,argv); glutinitdisplaymode (GLUT_SINGLE GLUT_RGB); /* default, not needed */ glutinitwindowsize(500,500); /* 500 x 500 pixel window */ glutinitwindowposition(0,0); /* place window top left on display */ glutcreatewindow("koch snowflake"); /* window title */ glutdisplayfunc(display); /* display callback invoked when window opened */ myinit(); /* set attributes */ glutmainloop(); /* enter event loop */
COS340A Assignment 1 I Pillemer Student# 3257 495 9 March 25 th 2007 p8/15 (b) Screen Capture for n = 1
COS340A Assignment 1 I Pillemer Student# 3257 495 9 March 25 th 2007 p9/15 Screen Capture for n = 3
COS340A Assignment 1 I Pillemer Student# 3257 495 9 March 25 th 2007 p10/15 Question 4 (Exercise 2.12 in ICG) Devise a test to determine whether a two dimensional polygon is simple. I can determine quite a simple and straight forward test. First I would determine the equation for each line defining the edges of the polygon. I would then proceed to solve, pair wise, these equations and determine all the intersections. I would then be able to conclude if they intersect to form a polygon (ie that there is a polygon at all); and then furthermore to confirm that all the lines intersect outside the vertices. If they intersect within the vertices I will know that the polygon is complex. This is a computationally intensive test but it is assured to work.
COS340A Assignment 1 I Pillemer Student# 3257 495 9 March 25 th 2007 p11/15 Question 5 (Exercise 4.1 in ICG) Show that the following sequences commute: a) A rotation and a uniform scaling b) Two rotations about the same axis c) Two translations. a) Let R be a rotation and S be a uniform scaling. We know that S is a uniform scaling, so S = ti. Therefore RS = R(t,t,t ) = RtI = Rt = tr = tir = (t,t,t)r = SR. It is worth noting that a Rotation and a non uniform scaling does not commute.
COS340A Assignment 1 I Pillemer Student# 3257 495 9 March 25 th 2007 p12/15 b) The trigonometric identities for the sum of two angles are: = + = Now, = ; and similarly = Thus =. = Using the trigonometric identities for the sum of two angles I can simplify this to which equals Now I know that = And similar to the above = Therefore = ; ie Rotations on the same axis commute.
COS340A Assignment 1 I Pillemer Student# 3257 495 9 March 25 th 2007 p13/15 c) = = = Similarly, =. And, = ; hence I can conclude that two translations commute.
COS340A Assignment 1 I Pillemer Student# 3257 495 9 March 25 th 2007 p14/15 Question 6 (Exercise 4.8 in ICG) Derive the shear transformation from the rotation, translation and scaling transformations. I will show that the y shear transformation (and similarly the x shear transformation) can be derived from a rotation, a non uniform scaling and a rotation. First I assume that =. The reason that I assume this; is that I know that a shear transformation does not affect the area of the shape. Thus when I use the non uniform scaling transformation I must make sure that the volume remains the same. This can be done by setting the scaling factor of for and for i.e. the product of the two scaling factors must equal one. Thus whatever the rotation matrices I need; I know that the non uniform scaling matrix must be. By choosing = I make finding suitable rotation matrices simpler. Hence I am now attempting to find suitable transformation for the matrix =. As described above the non uniform scaling matrix of is a necessary transformation matrix in the derivation ensuring the area of the transformed shape remains the same. I now need to rotate the shape so that this non uniform scaling transformation has the effect desired; and then rotate the shape back to the required position in the co ordinate system. My next step is to determine the two rotation matrices. In order to do this I need to decide on a rotation angle.
COS340A Assignment 1 I Pillemer Student# 3257 495 9 March 25 th 2007 p15/15 I choose that such that conversions of and.. This allows me to make use of the trigonometric This allows me to convert the rotation matrix into ; which can be simplified to. Similarly, = = ; which can be simplified to. Furthermore = = ; which can be simplified to. I now try the different rotations until I find rotations that result in the shear matrix. In this manner, using trial and error, it can be seen that = = =. The case is similar with a x shear; it is the transpose. Thus I have derived a rotation, a non uniform scaling and a rotation that is identical to the shear matrix.