COS340A Assignment 1 I Pillemer Student# March 25 th 2007 p1/15

Similar documents
Programming with OpenGL Part 3: Three Dimensions

Computer Graphics (Basic OpenGL)

Lecture 3. Understanding of OPenGL programming

Announcements OpenGL. Computer Graphics. Autumn 2009 CS4815

Graphics Programming. August 31, Programming of the Sierpinski gasket. Programming with OpenGL and C/C++

Duc Nguyen CSE 420 Computer Graphics 10/10/2018 Homework 1

Announcements OpenGL. Computer Graphics. Spring CS4815

Introduction to OpenGL: Part 2

Computer Graphics. Making Pictures. Computer Graphics CSC470 1

by modifying the glutinitwindowsize() function you can change the screen size to whatever you please.

Graphics Programming

UNIT 7 LIGHTING AND SHADING. 1. Explain phong lighting model. Indicate the advantages and disadvantages. (Jun2012) 10M

Drawing Primitives. OpenGL basics

COMPUTER GRAPHICS LAB # 3

Cameras (and eye) Ideal Pinhole. Real Pinhole. Real + lens. Depth of field

Lectures OpenGL Introduction

C++ is Fun Part 13 at Turbine/Warner Bros.! Russell Hanson

Graphics Programming. 1. The Sierpinski Gasket. Chapter 2. Introduction:

Programming with OpenGL Part 2: Complete Programs Computer Graphics I, Fall

Using OpenGL with CUDA

Assignment 1. Simple Graphics program using OpenGL

PART-I: Lab for MCS-051 (Advanced Internet Technologies)

To Do. Computer Graphics (Fall 2008) Course Outline. Course Outline. Methodology for Lecture. Demo: Surreal (HW 3)

QUESTION 1 [10] 2 COS340-A October/November 2009

Basic Graphics Programming

Programming with OpenGL Part 1: Background

CS559: Computer Graphics. Lecture 12: OpenGL Transformation Li Zhang Spring 2008

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

Precept 2 Aleksey Boyko February 18, 2011

3D computer graphics: geometric modeling of objects in the computer and rendering them

Computer Graphics: Line Drawing Algorithms

Hierarchical Modeling: Tree of Transformations, Display Lists and Functions, Matrix and Attribute Stacks,

Computer Graphics. OpenGL

Teacher Assistant : Tamir Grossinger Reception hours: by - Building 37 / office -102 Assignments: 4 programing using

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 2: First Program

6. Make use of glviewport() to display two sine curves on the same screen, one on the

CMSC 425: Lecture 4 More about OpenGL and GLUT Tuesday, Feb 5, 2013

Introduction to Computer Graphics with OpenGL/GLUT


Books, OpenGL, GLUT, GLUI, CUDA, OpenCL, OpenCV, PointClouds, and G3D

// double buffering and RGB glutinitdisplaymode(glut_double GLUT_RGBA); // your own initializations

Andrew Yenalavitch Homework 1 CSE Fall 2014

Computer Graphics Course 2005

Drawing and Coordinate Systems

CS559: Computer Graphics. Lecture 12: OpenGL Li Zhang Spring 2008

CS 4204 Computer Graphics

BOUNCING BALL IMRAN IHSAN ASSISTANT PROFESSOR

Programming using OpenGL: A first Introduction

GEOMETRIC OBJECTS AND TRANSFORMATIONS I

Abel J. P. Gomes LAB. 1. INTRODUCTION TO OpenGL

Books, OpenGL, GLUT, CUDA, OpenCL, OpenCV, PointClouds, G3D, and Qt

Transformation Pipeline

Bob s Concise Introduction to Doxygen

521493S Computer Graphics Exercise 2 Solution (Chapters 4-5)

CS380: Computer Graphics Basic OpenGL Structure. Sung-Eui Yoon ( 윤성의 ) Course URL:

Announcement. Homework 1 has been posted in dropbox and course website. Due: 1:15 pm, Monday, September 12

1.2 Basic Graphics Programming

OpenGL Introduction Computer Graphics and Visualization

Interaction Computer Graphics I Lecture 3

2D Drawing Primitives

Basic Graphics Programming

Drawing and Coordinate Systems

11/1/13. Basic Graphics Programming. Teaching Assistant. What is OpenGL. Course Producer. Where is OpenGL used. Graphics library (API)

Lecture 2 CISC440/640 Spring Department of Computer and Information Science

FAKULTI TEKNOLOGI MAKLUMAT DAN KOMUNIKASI BITM INTERACTIVE COMPUTER GRAPHICS LAB SESSION 4. C++ - OpenGL

CS Computer Graphics: OpenGL, Continued

CS Computer Graphics: OpenGL, Continued

Modeling Objects by Polygonal Approximations. Linear and Affine Transformations (Maps)

CSC Graphics Programming. Budditha Hettige Department of Statistics and Computer Science

UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4620/8626 Computer Graphics Spring 2014 Homework Set 1 Suggested Answers

Exercises for Chapter Three You know you've got to exercise your brain just like your muscles. Will Rogers ( )

CS 4731 Lecture 3: Introduction to OpenGL and GLUT: Part II. Emmanuel Agu

Boardworks Ltd KS3 Mathematics. S1 Lines and Angles

Interaction. CSCI 480 Computer Graphics Lecture 3

Computer Graphics (4731) Lecture 4: 2D Graphics Systems (Drawing Polylines, tiling, & Aspect Ratio)

Modeling Transform. Chapter 4 Geometric Transformations. Overview. Instancing. Specify transformation for objects 李同益

CS418 OpenGL & GLUT Programming Tutorial (I) Presented by : Wei-Wen Feng 1/30/2008

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

Display Lists in OpenGL

CS 432 Interactive Computer Graphics

UNIT 4 GEOMETRIC OBJECTS AND TRANSFORMATIONS-1

SOURCES AND URLS BIBLIOGRAPHY AND REFERENCES

Lecture 3 Advanced Computer Graphics (CS & SE )

C OMPUTER G RAPHICS Thursday

CSC 470 Computer Graphics

Graphics Hardware and OpenGL

OpenGL/GLUT Intro. Week 1, Fri Jan 12

Introduction to OpenGL

Reading on the Accumulation Buffer: Motion Blur, Anti-Aliasing, and Depth of Field

Answer Key: Three-Dimensional Cross Sections

Fourier Series. Given a periodic function, x(t), (-T <t <T): + b n sin n t T. a n cos n t T. 2 a 0 + Z T. a n = 1 T. x(t) cos n t T. b n = 1 T.

CS 543 Lecture 1 (Part 3) Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Mrs. Daniel s Geometry Vocab List

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

Meshing and Geometry

RECITATION - 1. Ceng477 Fall

Computer graphics MN1

Introduction to OpenGL

2 Transformations and Homogeneous Coordinates

Input and Interaction. 1. Interaction. Chapter 3. Introduction: - We now turn to the development of interactive graphics programs.

Transcription:

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.