Solution Notes. COMP 151: Terms Test

Similar documents
EXAMINATIONS 2017 TRIMESTER 2

EXAMINATIONS 2016 TRIMESTER 2

COMP 102 : Test. 2017, Apr 3

Computer Graphics. Lecture 2. Doç. Dr. Mehmet Gokturk

COMP 102: Test August, 2017

To graph the point (r, θ), simply go out r units along the initial ray, then rotate through the angle θ. The point (1, 5π 6. ) is graphed below:

To graph the point (r, θ), simply go out r units along the initial ray, then rotate through the angle θ. The point (1, 5π 6

Model Solutions. COMP 102: Test. 14 August, 2014

Transform 1: Translate, Matrices

COMP 102 : Test. 2017, Apr 3 ** WITH SOLUTIONS **

P1 REVISION EXERCISE: 1

1. Complete these exercises to practice creating user functions in small sketches.

CISC 1600 Lecture 3.1 Introduction to Processing

COMP 102: Test August, 2017

Output Primitives Lecture: 4. Lecture 4

Catholic Central High School

PARAMETRIC EQUATIONS AND POLAR COORDINATES

Part I. There are 5 problems in Part I, each worth 5 points. No partial credit will be given, so be careful. Circle the correct answer.

Multivariable Calculus

Exam 3 SCORE. MA 114 Exam 3 Spring Section and/or TA:

Model Solutions. COMP 102: Test. 18 August, 2016

Review of Trigonometry

CS 130 Final. Fall 2015

Iteration in Programming

AQA GCSE Further Maths Topic Areas

Old 257 Exam #2s for Practice

WJEC LEVEL 2 CERTIFICATE 9550/01 ADDITIONAL MATHEMATICS

Catholic Central High School

Using Methods. Methods that handle events. Mairead Meagher Dr. Siobhán Drohan. Produced by: Department of Computing and Mathematics

The diagram above shows a sketch of the curve C with parametric equations

Glossary of dictionary terms in the AP geometry units

OpenGL Graphics System. 2D Graphics Primitives. Drawing 2D Graphics Primitives. 2D Graphics Primitives. Mathematical 2D Primitives.

CSCI 4620/8626. Coordinate Reference Frames

Unit 3, Lesson 1.3 Special Angles in the Unit Circle

Jim Lambers MAT 169 Fall Semester Lecture 33 Notes

The University of Calgary

Model Solutions. COMP 102: Test 1. 6 April, 2016

1. (10 pts) Order the following three images by how much memory they occupy:

: Find the values of the six trigonometric functions for θ. Special Right Triangles:

CHAPTER 2 REVIEW COORDINATE GEOMETRY MATH Warm-Up: See Solved Homework questions. 2.2 Cartesian coordinate system

12 - THREE DIMENSIONAL GEOMETRY Page 1 ( Answers at the end of all questions ) = 2. ( d ) - 3. ^i - 2. ^j c 3. ( d )

COMPUTER AIDED ENGINEERING DESIGN (BFF2612)

Unit 12 Topics in Analytic Geometry - Classwork

8-1 Simple Trigonometric Equations. Objective: To solve simple Trigonometric Equations and apply them

AP * Calculus Review. Area and Volume

Tópicos de Computação Gráfica Topics in Computer Graphics 10509: Doutoramento em Engenharia Informática. Chap. 2 Rasterization.

FORMULAS to UNDERSTAND & MEMORIZE

Scan Converting Lines

2D Object Definition (1/3)

1 Some easy lines (2, 17) (10, 17) (18, 2) (18, 14) (1, 5) (8, 12) Check with a ruler. Are your lines straight?

CPSC / Scan Conversion

Trigonometric Functions of Any Angle

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

MATH 31A HOMEWORK 9 (DUE 12/6) PARTS (A) AND (B) SECTION 5.4. f(x) = x + 1 x 2 + 9, F (7) = 0

Rasterization: Geometric Primitives

Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 14

INSTRUCTIONS FOR THE USE OF THE SUPER RULE TM

The Straight Line. m is undefined. Use. Show that mab

Goals: Course Unit: Describing Moving Objects Different Ways of Representing Functions Vector-valued Functions, or Parametric Curves

Basics of Computational Geometry

Summer Math Assignments for Students Entering Integrated Math

The base of a solid is the region in the first quadrant bounded above by the line y = 2, below by

MATH EXAM 1 - SPRING 2018 SOLUTION

Math 1313 Prerequisites/Test 1 Review

mith College Computer Science CSC103 How Computers Work Week 7 Fall 2017 Dominique Thiébaut

Walt Whitman High School SUMMER REVIEW PACKET. For students entering AP CALCULUS BC

COMP 102/112 : Test. 2019, Apr 1 ** WITH SOLUTIONS **

Volumes of Solids of Revolution Lecture #6 a

Conic Sections. College Algebra

Int 2 Checklist (Unit 1) Int 2 Checklist (Unit 1) Percentages

Notes on Spherical Geometry

Investigating the Sine and Cosine Functions Part 1

Section 7.2 Volume: The Disk Method

MODULE - 4. e-pg Pathshala

Log1 Contest Round 2 Theta Circles, Parabolas and Polygons. 4 points each

Class #1. introduction, functions, variables, conditionals

MET71 COMPUTER AIDED DESIGN

1. Use the Trapezium Rule with five ordinates to find an approximate value for the integral

Worksheet 3.2: Double Integrals in Polar Coordinates

Chapter 10: Parametric And Polar Curves; Conic Sections

CISC 1600, Lab 3.1: Processing

Lecture 5 2D Transformation

Java Programming: Test 1

Geometry B. The University of Texas at Austin Continuing & Innovative Education K 16 Education Center 1

Kimberly Nguyen Professor Oliehoek Introduction to Programming 8 September 2013

SNAP Centre Workshop. Introduction to Trigonometry

Part I. There are 8 problems in Part I, each worth 5 points. No partial credit will be given, so be careful. Circle the correct answer.

Unit Circle. Project Response Sheet

Birkdale High School - Higher Scheme of Work

Honors Precalculus: Solving equations and inequalities graphically and algebraically. Page 1

Model Solutions. COMP 102: Test March, 2014

Math 144 Activity #4 Connecting the unit circle to the graphs of the trig functions

Calculators ARE NOT Permitted On This Portion Of The Exam 28 Questions - 55 Minutes

Pre-Calculus Guided Notes: Chapter 10 Conics. A circle is

Using Methods. More on writing methods. Dr. Siobhán Drohan Mairead Meagher. Produced by: Department of Computing and Mathematics

Question 1: As you drag the green arrow, what gets graphed? Does it make sense? Explain in words why the resulting graph looks the way it does.

Lesson 27: Angles in Standard Position

Math 2 Coordinate Geometry Part 3 Inequalities & Quadratics

Trigonometry and the Unit Circle. Chapter 4

1 Introduction to Graphics

Transcription:

Family Name:.............................. Other Names:............................. ID Number:............................... Signature.................................. Solution Notes COMP 151: Terms Test 17 th August 2016 Instructions Time allowed: 45 minutes. Answer all the questions. There are four questions and 45 marks in total. Write your answers in the boxes in this test paper and hand in pages 1 10. There is brief Processing documentation on page 11, which you may detach from the test paper. If you think some question is unclear, ask for clarification. This test contributes 10% of your final grade You may use paper translation dictionaries. No other materials are permitted. You may write notes and working on this paper, but make sure your answers are clear. Questions Marks 1. Straight line algorithm [15 2. Graphical output in Processing [10 3. Vectors and dot products [10 4. Specifying objects [10 TOTAL

SPARE PAGE FOR EXTRA ANSWERS Cross out rough working that you do not want marked. Specify the question number for work that you do want marked. COMP 151 (Terms Test) Page 2 of 11

1. Straight line algorithm (15 marks) Write an algorithm for drawing a straight line that uses only integer arithmetic. Assume that the line starts at (x 0, y 0 ) and ends at (x 1, y 1 ). Assume that x 0 < x 1. Assume that the slope of the line is between 0 and 45. Assume that x 0, y 0, x 1, y 1 are all integers. Assume that function drawpixel(x,y) turns on the pixel at integer location (x, y). You may write in Java code, Processing code, or pseudo-code. Minor syntax errors will not be penalised. void drawline( int x0, int y0, int x1, int y1 ) { int dx = (x1 - x0) ; int d2x = 2*dx ; int d2y = 2*(y1 - y0) ; int x = x0 ; int yf = 0 ; int y = y0 ; while (x <= x1) { drawpixel(x,y) x++ ; yf += d2y ; if( yf > dx ) { y++ ; yf -= d2x ; // This is Bresenham s algorithm. There are other ways to do this, // in particular the integer version of the Midpoint algorithm. COMP 151 (Terms Test) Page 3 of 11

SPARE PAGE FOR EXTRA ANSWERS Cross out rough working that you do not want marked. Specify the question number for work that you do want marked. COMP 151 (Terms Test) Page 4 of 11

2. Graphical output in Processing (10 marks) (a) (6 marks) Double loops Sketch what the following code will draw in the Processing window. size( 300, 300 ) ; background( 255 ) ; stroke( 0 ) ; fill( 255 ); for( int i = 0 ; i < 3 ; i++ ) { for( int j = 0 ; j < 3 ; j++ ) { if( i == j ) { ellipse( i*100 + 50, j * 100 + 50, 80, 40 ) ; else { rect( i*100 + 30, j * 100 + 10, 40, 80 ) ; (300 300 Processing window) (Question 2 continued on next page) COMP 151 (Terms Test) Page 5 of 11

(Question 2 continued) (b) (4 marks) Transformations Sketch what the following code will draw in the Processing window. size( 300, 300 ) ; background( 255 ) ; stroke( 0 ) ; fill( 255 ) ; translate( 150, 150 ) ; for( int i = 0 ; i < 8 ; i++ ) { rotate( PI / 4 ) ; ellipse( 100, 0, 20, 50 ) ; (300 300 Processing window) (Question 2 continued on next page) COMP 151 (Terms Test) Page 6 of 11

(Question 2 continued) Extra copies (in case you made a mistake) (spare copy of 300 300 Processing window) (spare copy of 300 300 Processing window) COMP 151 (Terms Test) Page 7 of 11

3. Vectors and dot products (10 marks) (a) (4 marks) Vector algebra You are given two vectors, p =. Evaluate the following expressions. [ 5 2 and q = [ 3 4 Vector addition p + q = [ 8 6 Vector subtraction p q = [ 2 2 Dot product p q = 5 3 + 2 4 = 23 Magnitude q = 32 + 4 2 = 5 (Question 3 continued on next page) COMP 151 (Terms Test) Page 8 of 11

(Question 3 continued) (b) (6 marks) Unit vectors The diagram shows a unit circle (a circle of radius 1) with four unit vectors (vectors of length 1): a, b, c and d. The pair of vectors a and b are at right angles (90 or π/2 radians) to one another, as are each of the pairs b and c, c and d, d and a. Vectors a and c are co-linear (i.e., they lie on the same infinite line). Vectors b and d are co-linear. From the definitions of cosine and sine, we know that the coordinates of a are [ cos θ a =. sin θ What are the coordinates of these other two vectors? b = [ sin θ cos θ c = [ cos θ sin θ What are these two dot products? a b = 0 a c = 1= cos 2 θ sin 2 θ COMP 151 (Terms Test) Page 9 of 11

4. Specifying objects (10 marks) A point in 2D is specified by two numbers: its x-coordinate and its y-coordinate. These are called its parameters. An axis-aligned rectangle, such as generated by Processing s rect() function, requires four parameters, for example, the x- and y-coordinates of its top left corner and its width and height. Give the minimum number of parameters required to specify each of the following graphical objects in 2D and list an example of those parameters. The first two are done for you. Graphical object point, such as generated by Processing s point() function Minimum number of parameters List of parameters 2 x, y (position of the point) axis-aligned rectangle, such as generated by Processing s rect() function 4 top, left, width, height (position of the top left corner and the dimensions [width and height of the rectangle) line segment, such as generated by Processing s line() function 4 (x 0, y 0 ), (x 1, y 1 ): the positions of the end points of the line vector 2 x, y infinitely long line 2* angle of line and perpendicular distance of line from origin* rectangle that is not aligned with the axes 5 centre position (x, y), width, height, rotation angle Bézier cubic spline 8 positions of the four control points: (x 0, y 0 ), (x 1, y 1 ), (x 2, y 2 ), (x 3, y 3 ) * Other plausible answers that get half credit: 2, m and c in y = mx + c (but cannot represent a vertical line) 3, a, b, c in the equation ax + by + c = 0 COMP 151 (Terms Test) Page 10 of 11

Brief Processing documentation void point( float x, float y ) // draw a point at location (x,y) void line( float x1, float y1, float x2, float y2) // draw a line segment from location (x1, y1) to location (x2, y2) void rect( float left, float top, float width, float height ) // draw a rectangle with its top left corner at the indicated position // of size width times height void ellipse( float centerx, float centery, float width, float height ) // draw an ellipse centred at the indicated position // of size width times height void triangle( float x1, float y1, float x2, float y2, float x3, float y3 ) // draw a triangle with vertices at the three points // (x1,y1 ), (x2,y2 ), (x3, y3) void background( float grey ) void stroke( float grey ) void fill( float grey ) // set the colour of the background, stroke or fill to be // a grey value between 0 ( black ) and 255 ( white ) void nostroke() void nofill() // turn off drawing strokes around objects and filling objects, respectively * * * * * * * * * * * * * * * COMP 151 (Terms Test) Page 11 of 11