For this assignment, you are to implement three line drawers and a polygon drawer.

Similar documents
SFU CMPT 361 Computer Graphics Fall 2017 Assignment 2. Assignment due Thursday, October 19, 11:59pm

CS 325 Computer Graphics

CS 130 Final. Fall 2015

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

Geogebra Introductory Activity

SAT Timed Section*: Math

1 Introduction to Graphics

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

Rasterization. CS4620/5620: Lecture 12. Announcements. Turn in HW 1. PPA 1 out. Friday lecture. History of graphics PPA 1 in 4621.

Scan line algorithm. Jacobs University Visualization and Computer Graphics Lab : Graphics and Visualization 272

UNIT -8 IMPLEMENTATION

CS-321 Thursday 12 September 2002 Quiz (3 pts.) What is the purpose of a control grid in a cathode ray tube (CRT)?

Surface shading: lights and rasterization. Computer Graphics CSE 167 Lecture 6

Pipeline and Rasterization. COMP770 Fall 2011

CS 543: Computer Graphics. Rasterization

The graphics pipeline. Pipeline and Rasterization. Primitives. Pipeline

In today s lecture we ll have a look at: A simple technique The mid-point circle algorithm

Rasterization. CS4620 Lecture 13

CSAP Achievement Levels Mathematics Grade 7 March, 2006

Scan Conversion. Drawing Lines Drawing Circles

Lets assume each object has a defined colour. Hence our illumination model is looks unrealistic.

Rasterization. CS 4620 Lecture Kavita Bala w/ prior instructor Steve Marschner. Cornell CS4620 Fall 2015 Lecture 16

(Refer Slide Time: 00:02:00)

Number- Algebra. Problem solving Statistics Investigations

2.1 Basics of Functions and Their Graphs

ACT Math test Plane Geometry Review

ACT SparkNotes Test Prep: Plane Geometry

For this assignment, you are to expand your renderer from assignment 2 with perspective, a polygon clipper, ambient lighting, and obj file reading.

HOTmaths. Early Secondary Comparing Lessons pre and post Feb /01/2011

Computer Graphics : Bresenham Line Drawing Algorithm, Circle Drawing & Polygon Filling

Problem Set 4 Part 1 CMSC 427 Distributed: Thursday, November 1, 2007 Due: Tuesday, November 20, 2007

Someone else might choose to describe the closet by determining how many square tiles it would take to cover the floor. 6 ft.

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

Unit 1, Lesson 1: Moving in the Plane

Polar Coordinates

Number Mulitplication and Number and Place Value Addition and Subtraction Division

New Swannington Primary School 2014 Year 6

Y6 MATHEMATICS TERMLY PATHWAY NUMBER MEASURE GEOMETRY STATISTICS

2D rendering takes a photo of the 2D scene with a virtual camera that selects an axis aligned rectangle from the scene. The photograph is placed into

Institutionen för systemteknik

Are you ready for Beast Academy 4B?

Shading Techniques Denbigh Starkey

Year 6 Mathematics Overview

Day 5: Inscribing and Circumscribing Getting Closer to π: Inscribing and Circumscribing Polygons - Archimedes Method. Goals:

WHOLE NUMBER AND DECIMAL OPERATIONS

Graphics (Output) Primitives. Chapters 3 & 4

Unit 1, Lesson 7: From Parallelograms to Triangles

Appendix E. Plane Geometry

TIMSS 2011 Fourth Grade Mathematics Item Descriptions developed during the TIMSS 2011 Benchmarking

(Refer Slide Time: 9:36)

Computer Graphics (CS 543) Lecture 10: Rasterization and Antialiasing

Curriculum Connections (Fractions): K-8 found at under Planning Supports

Unit 1, Lesson 11: Polygons

First Trimester Second Trimester Third Trimester

Anti-aliased and accelerated ray tracing. University of Texas at Austin CS384G - Computer Graphics

3. Mr. White does not wear white, so he is wearing the blue shirt. 4. Then Mr. Red wears a white shirt.

(Section 6.2: Volumes of Solids of Revolution: Disk / Washer Methods)

CS602 MCQ,s for midterm paper with reference solved by Shahid

Tables for determining National Curriculum Levels from MEP Year 8 Diagnostic Test Results (Standard)

CS 4731/543: Computer Graphics Lecture 7 (Part I): Raster Graphics: Polygons & Antialiasing. Emmanuel Agu

Year 9 Maths Overview

Mathematics Background

Study Guide for Test 2

Name: Tutor s

Area rectangles & parallelograms

Geometry: Semester 2 Practice Final Unofficial Worked Out Solutions by Earl Whitney

The x coordinate tells you how far left or right from center the point is. The y coordinate tells you how far up or down from center the point is.

Intermediate Mathematics League of Eastern Massachusetts

Year 6 Maths Long Term Plan

CS Rasterization. Junqiao Zhao 赵君峤

Overview of Computer Graphics

Rational Numbers: Graphing: The Coordinate Plane

Mathematics Curriculum Objectives Year Six. Trinity Primary

Week 1 Week 2 Week 3 Week 4 Week 5 Week 6 Week 7 Week 8 Week 9 Week 10 Week 11 Week 12 Week 13 Week14. Number- addition subtraction,

CS 4731: Computer Graphics Lecture 21: Raster Graphics: Drawing Lines. Emmanuel Agu

2009 Fall Startup Event Thursday, September 24th, 2009

Middle School Summer Review Packet for Abbott and Orchard Lake Middle School Grade 7

Middle School Summer Review Packet for Abbott and Orchard Lake Middle School Grade 7

2017 Summer Review for Students Entering Pre-Algebra 7 & Pre-Algebra 8

Line Drawing. Introduction to Computer Graphics Torsten Möller / Mike Phillips. Machiraju/Zhang/Möller

Warm-Up 12 Solutions. Peter S. Simon. December 8, 2004

Geometry !!!!! Tri-Folds 3.G.1 - # 1. 4 Mystery Shape 5 Compare & Contrast. 3rd Grade Math. Compare. Name: Date: Contrast

Trigonometry Review Day 1

AQA GCSE Further Maths Topic Areas

Computer Graphics. Attributes of Graphics Primitives. Somsak Walairacht, Computer Engineering, KMITL 1

Input/Output Machines

Year 6.1- Number and Place Value 2 weeks- Autumn 1 Read, write, order and compare numbers up to and determine the value of each digit.

MATH DICTIONARY. Number Sense. Number Families. Operations. Counting (Natural) Numbers The numbers we say when we count. Example: {0, 1, 2, 3, 4 }

Sixth Grade SOL Tracker Name:

Does Not Meet State Standard Meets State Standard

Mathematics: working hard together, achieving together, making every lesson count

Computer Graphics Lecture Notes

YEAR 10- Mathematics Term 1 plan

Mathematics Department Inverclyde Academy

Prentice Hall Algebra Correlated to: ACT College Readiness Standards for Mathematics

4.G.1. Name Date. Geometry. Use the figure below to answer questions Draw an intersecting line through the line below. E H

Syllabus Form 3. Objectives Students will be able to: Mathematics Department. Revision of numbers. Form 3 Syllabus Page 1 of 7

Grade 6 Math Curriculum Sequence School Year

? Which intermediate. Recall: Line drawing algorithm. Programmer specifies (x,y) of end pixels Need algorithm to determine pixels on line path

CIRCLES ON TAKS NAME CLASS PD DUE

Transcription:

SFU CMPT 361 Computer Graphics Fall 2017 Assignment 1 Assignment due Thursday, September 28, by 11:59 pm. For this assignment, you are to implement three line drawers and a polygon drawer. These rendering components should be shown in a program that displays five (or six) pages. Each of the five required pages consists of four panels, which I will call panel 1, panel 2, etc., and are as shown in the following diagram: Panel 1 Panel 2 Panel 3 Panel 4 Each panel should be 300 x 300 pixels, the the white margins and gutters between panels are all 50 pixels wide or tall. Thus, the total display area is 750 x 750 pixels. Use white and black for the backgrounds, as shown above. The first three pages will show the output of your line drawers. On each of these pages, one test is performed using three different renderers (the DDA, Bresenham s, and an antialiased line drawer) as follows: Panel 1: DDA Panel 2: Bresenham s Panel 3: A drawing that alternates between lines with the DDA and Bresenham s. The first line drawn is with the DDA, the second with Bresenham s, the third with the DDA, etc. Panel 4: An antialiased line renderer The antialiased line drawer can use any algorithm you choose. The better the antialiasing, the better your mark. (In other words, a very poor job or a very good job of antialiasing will get noticed and rewarded appropriately.) The antialiasing that I discussed in class, with the correct area computation (see below), is sufficient for getting full marks.

You may code up all eight octants of your line drawers, or you may code up one and transform the coordinates of the endpoints for the other seven quadrants, using the provided AnyOctantLineRenderer mechanism. Treat the repetition in the following tests as a design problem (i.e. eliminate duplication by good design) and not a copy-andpaste problem! Copy-and-paste results in brittle, buggy code. Page 1. The test to display on the first page is the starburst test. Let c be one of the four center points of the panel (be consistent across panels). Draw 90 lines from c, each of length approximately 125 pixels, equally spaced in angle around c. This means one line at 0 degrees, one line at 4 degrees, one at 8 degrees, etc. Parameterize the subroutine you use with c, the length of the lines, and the number of them to draw. (And any other parameters you need.) Do not hardwire constants into your code use final (java) quantities declared at class level. Page 2. The test to display on the second page is the parallelogram test. With x coordinates from left to right in a panel, starting at 0, and y coordinates from top to bottom in the panel, starting at 0, draw the lines: (20, 80+p) to (150, 150+p) For p = 0 to 50. Also draw the lines: (160+p, 270) to (240+p, 40) Again, for p = 0 to 50. Page 3. The test to display on the third page is the random test. Draw 30 random lines (generate the two endpoints uniformly and independently on the interval from 0 to 299 in x and in y) with a random color for each line. (Your line renderers must therefore be capable of handling the color of a line: simply multiply the color s R, G, and B by the pixel coverage (which is 1 for DDA and Bresenham s) and add this to (1 pixel s coverage)*(the color that s already in the pixel). Use the same random endpoints and colors for all four panels. I don t care how you randomly choose the colors. Page 4. On the fourth page, display the following four scenes of filled polygons. In each panel, draw polygons each with a randomly-chosen color. Do no anti-aliasing. The first panel should be like the starburst test, only you are drawing 90 triangles from the center (each with two sides of length approximately 125 pixels, and subtending 4 degrees). The second panel should have 162 (= 2 * 81) triangles. Start by spacing out a 10 by 10 array of points as evenly as possible in the panel (with some margin, please!) Then connect these points in the obvious way to form a regular grid of 9 x 9 = 81 squares. In each square, put in the (min x, min y) to (max x, max y) diagonal to form 162 triangles. Render these triangles. The third panel is like the second, except that before you create the triangles, you randomly shift each point in x and in y. Shift each point once; do not shift it to a different place for each triangle that uses it. Choose the shift for each coordinate from the range [-12, 12]. In the fourth panel, generate 20 random triangles (endpoints chosen randomly and uniformly from [0, 299] in both x and y) and render them. They will overlap; this is okay. Page 5. The fifth page should show the same four scenes of filled polygons as shown on page four. However, each polygon should have a color of full white (or (1, 1, 1) in 0-1 coordinates), and an opacity of some smallish constant, say.14. To write a pixel x, y with color color and opacity opacity, follow the pseudocode: Color oldcolor = getpixel(x, y); Color newcolor = opacity * color + (1-opacity) * oldcolor

SetPixel(x, y, newcolor); Here a Color is an (R, G, B) vector. Be sure to multiply by opacity once per color channel; do not try to multiply opacity by a color packed into a 32-bit integer (as this can sometimes create interesting colored artifacts). Again, do not store opacity in the A or alpha channel. Page 6 (optional). Display any number (up to four) of panels that you think highlight the (positive) attributes of your polygon or line rendering. Do not exceed six pages. The program should switch pages at the press of an on-screen GUI button. The skeleton files provided are already set up to do this. Include a README file with your project that explains what you did, what you didn t do, and what features you are trying to highlight if you include a page 6. You may not use any graphics software (libraries, etc.) that is not provided in the skeleton. You may not call OpenGL or javafx yourself, for instance. You may not obtain code from the web or other outside sources, and you may not share code with any other students. Note 1: color is represented by red (R), green (G), and blue (B) values. Each of R, G, and B is called a color channel. Abstractly, and oftentimes in the middle of a renderer, the color values are in the range [0, 1] with 0 being none and 1 being the most intense value of this color we can make. Concretely, down in the hardware, most graphics hardware uses 8 bits for each of these three color values. This leads to some programs representing each of the colors with an integer value from 0 to 255. You are expected to be able to quickly switch between thinking of each channel between 0 and 1, and thinking of each channel between 0 and 255. To convert from one to the other is simply to multiply or divide by 255. The libraries that we are using represent the colors with 8 bits per channel. These three channels are all packed into one 32bit integer with the blue value (0-255) in the bottom 8 bits, the green in the next lowest 8 bits, and the red in the next lowest. This leaves the 8 most significant bits unused. Well, rather than leave them unused, those 8 bits are often used for an alpha (or opacity) value, which represents how much of the pixel in question is covered by the object in that pixel. Since one hexadecimal digit represents 4 bits, we can think of the color being represented (little-endian) as AARRGGBB which means two digits of alpha, two digits of red, two digits of green, and two digits of blue (in that order, from most significant bit to least significant bit). For example, a color ff104077 means that the alpha value is ff 16 (= 255 10 ), the red value is 10 16 (= 16 10 ), the green value is 40 16 (= 64 10 ), and the blue value is 77 16 = (119 10 ). To pack and unpack R, G, and B values from a color represented this way, some bit manipulation is necessary. For instance (here I m using the prefix 0x for hexadecimal numbers): color = (0xff << 24) + ((r & 0xff) << 16) + ((g & 0xff) << 8) + (b & 0xff); The bitwise-and operations in the above can be omitted if you know for sure that r, g, and b are integers between 0 and 255, inclusive. The above calculation puts 255 (i.e., 0xff) into the alpha bits. You should do this for all of your colors. One of the libraries I have provided requires it.

The above statement constructs an ARGB color from r, g, and b. Going the other way also requires bit-shifts and masking, but I ll leave you to determine how to do that. Note 2: the antialiasing I discussed in class requires that you find the area inside the intersection of a slab with a circle, based on the distance from the edge of the slab to the center of the circle. In other words, if you know d in the following diagram, you must find the area of the lightly-shaded part. Circle represents a pixel Slab (rectangle) represents the model of the line being drawn. d Popular choices for r, the radius of the circle representing the pixel, are 0.5 and sqrt(2). (These give cicles barely contained in, and barely containing, the square for the pixel.) The area of the full circle is πr 2. Thus the fraction of the pixel that is covered is (the area of the lightly-shaded part above) / πr 2. The area of the lightly-shaded part above is (πr 2 (the white area in the circle)), so the fraction of the pixel that is covered is (πr 2 (the white area in the circle) ) / πr 2, Or 1 (the white area in the circle) / πr 2. (*) The white area in the circle can be divided into two parts: a triangle and a pie wedge. See the diagram below, where everything has been rotated so that the segment of distance d is vertical:

r θ d From here, things should be easy for you. The triangle shown has twice the area of the right triangle with hypotenuse r and one side d. The other side of that triangle must be sqrt(r 2 d 2 ), so the right triangle has area (d sqrt(r 2 d 2 ) ) / 2, and the large one has area d sqrt(r 2 d 2 ). One can determine θ because cos θ = d/r. The angle of the pie wedge is 2π - 2θ. The area of the pie wedge is thus (area of entire circle) = πr 2 = (1 ) πr 2 And the area of the entire white part is thus We substitute this into the equation (*) for the fraction of the pixel that is covered, and we get: 1 πr 2 You should be able to do the algebra from there. Don t forget that cos θ = d/r, or θ = cos -1 d/r. Appearance of completed assignment: the following images show approximately what the first five pages of your output should be. Random perturbations and colors will differ.