diff options
Diffstat (limited to '')
-rw-r--r-- | worksheets/a3_earthquake.md | 93 | ||||
-rw-r--r-- | worksheets/img/square.png | bin | 0 -> 10703 bytes | |||
-rw-r--r-- | worksheets/img/square.svg | 158 |
3 files changed, 251 insertions, 0 deletions
diff --git a/worksheets/a3_earthquake.md b/worksheets/a3_earthquake.md new file mode 100644 index 0000000..e38902f --- /dev/null +++ b/worksheets/a3_earthquake.md @@ -0,0 +1,93 @@ +# Assignment 3 (Earthquake) Worksheet + +## Q1: Useful math + +In this assignment, you will be dealing with earthquake data from the United +States Geological Survey. As with any real-world dataset, the data have +real-world units, which may not always match up with units we want to use for +the data visualization. As such, there are a few handy practices commonly used +when constructing visualizations from real-world data; one of the most common +is normalization. + +Normalization is the process of converting a number inside of an +arbitrary range to a floating point number between 0.0 +and 1.0, inclusive. For example, if we have a value `v = 1.5` in the list of +numbers `{0.0, 1.5, 2.0, 1.3}`, the normalized value would be `v_normalized = +0.75`. + +These two functions, part of the C++ standard library, will be useful for your +first question: + +``` +/* + * - `std::min_element()` - return the minimum of a vector + * - `std::max_element()` - return the maximum of a vector + * + * Example usage: + * std::vector<float> quakes = {0.0, 1.5, 2.0, 1.3}; + * float min_magnitude = std::min_element(quakes.begin(), quakes.end()); + */ +``` + +Using the min_element() and max_element() functions, write a routine to normalize +the values in an arbitrary vector (list) and return a new vector: + +``` +std::vector<float> normalize_list(std::vector<float> quakeList) { + /* --- Fill in your algorithm here --- */ +} +``` + +Now, to check that your algorithm works, let's just work out a quick example +by hand. What would the following code print out if you were to run it? +Note, if your math is correct, all of the values printed should be between 0.0 +and 1.0 inclusive. + +``` +std::vector<float> quakes = {0.0, 2.3, 5.1, 1.1, 7.6, 1.7}; +std::vector<float> normalized_quakes = normalize_list(quakes); + +for (int i = 0; i < normalized_quakes.size(); i++) { + std::cout << normalized_quakes[i] << " "; +} +std::cout << std::endl; +``` +Output: +``` +/* --- Fill in the expected output here (e.g. "0.0, 0.5, 0.5, 1.0, 0.5, 0.12, 0.6") --- */ +``` + +## Q2: Constructing a mesh + +For the first two assignments, we were able to use the QuickShapes class to draw pretty much everything we had to draw because everything could be constructed from 3D graphics primitives like cubes, spheres, cones, etc. This assignment will be the first one where we create a custom 3D shape made of triangles and apply a custom texture to it. + +To create a triangle mesh from scratch, you will need to understand how a **Vertex Array** and an **Index Array** are used together to define each triangle that belongs to the mesh. We discuss this in detail in lecture, but here is a brief recap: + +The vertex array will hold the actual 3D coordinates for each vertex of the mesh. Each vertex is a point, so these should be represented as Point3s, and there should be one element in the array for each vertex in the mesh. Then, the index array tells us how to connect these vertices together to form triangles. + +The index array refers to vertices stored in the vertex array by their index in that array. So, if the vertex array is of length n, valid indices would be 0, 1, 2, ... n-1. Since these are all positive integers, the index array is usually stored as an array of unsigned ints. Even though each entry is a single unsigned int, we want to think of the entries as being grouped into sets of 3. (Since it takes 3 vertices to define a single triangle, we should always add indices in groups of 3, and the length of the index array should always be 3 times the number of triangles in the mesh). One final tip to remember is to use counter-clockwise vertex ordering to tell the graphics engine which side of the triangle is the "front" and which side is the "back". Remember, only the front face will show up; the back will be invisible! + +Let's practice all these concepts with a simple example of a square. Create your own copy of the image below (using a piece of paper that you photograph or a drawing program) and label each vertex with an index number +(starting at 0). + +**Replace this image with your drawing:** + +![](./img/square.png) + +Now, write out the square's vertex array, using the familiar `Point3` class +(since it's in the *xy*-plane, assume z = 0 for all points): + +``` +std::vector<Point3> squareVertexArray = { + /* --- Fill in your `Point3`s here */ +}; +``` + +Finally, write out the square's index array based on the indices you defined in the picture above. Make sure your indices are defined in counter-clockwise order so that a 3D camera looking down on your square from some +Z height above will see the front faces of your triangles. + +``` +std::vector<int> squareIndexArray = { + /* --- Fill in your first triangle indices --- */ + /* --- Fill in your second triangle indices --- */ +}; +``` diff --git a/worksheets/img/square.png b/worksheets/img/square.png Binary files differnew file mode 100644 index 0000000..350bee8 --- /dev/null +++ b/worksheets/img/square.png diff --git a/worksheets/img/square.svg b/worksheets/img/square.svg new file mode 100644 index 0000000..4ede5db --- /dev/null +++ b/worksheets/img/square.svg @@ -0,0 +1,158 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="144.24536mm" + height="110.00814mm" + viewBox="0 0 144.24536 110.00814" + version="1.1" + id="svg8" + inkscape:version="0.92.4 5da689c313, 2019-01-14" + sodipodi:docname="square.svg" + inkscape:export-filename="/home/bridger/4611/instructor-repo/worksheets/img/square.png" + inkscape:export-xdpi="100" + inkscape:export-ydpi="100"> + <defs + id="defs2" /> + <sodipodi:namedview + id="base" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + inkscape:pageopacity="0.0" + inkscape:pageshadow="2" + inkscape:zoom="1.4142136" + inkscape:cx="255.00964" + inkscape:cy="176.59249" + inkscape:document-units="mm" + inkscape:current-layer="layer1" + showgrid="false" + inkscape:window-width="1920" + inkscape:window-height="1056" + inkscape:window-x="1920" + inkscape:window-y="0" + inkscape:window-maximized="1" + fit-margin-top="0" + fit-margin-left="0" + fit-margin-right="0" + fit-margin-bottom="0" /> + <metadata + id="metadata5"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title></dc:title> + </cc:Work> + </rdf:RDF> + </metadata> + <g + inkscape:label="Layer 1" + inkscape:groupmode="layer" + id="layer1" + transform="translate(-40.224063,-13.806447)"> + <g + id="g868"> + <circle + r="4.6332159" + cy="42.215618" + cx="83.488472" + id="path815" + style="opacity:1;vector-effect:none;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1.49950945;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> + <circle + style="opacity:1;vector-effect:none;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1.49950945;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" + id="circle817" + cx="139.74791" + cy="42.215618" + r="4.6332159" /> + <circle + r="4.6332159" + cy="98.040352" + cx="139.74791" + id="circle819" + style="opacity:1;vector-effect:none;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1.49950945;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> + <circle + style="opacity:1;vector-effect:none;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1.49950945;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" + id="circle821" + cx="83.488472" + cy="98.040352" + r="4.6332159" /> + <rect + ry="0" + y="42.247353" + x="83.156837" + height="56.52523" + width="56.52523" + id="rect823" + style="opacity:1;vector-effect:none;fill:none;fill-opacity:1;stroke:#000000;stroke-width:1.49950945;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> + <path + inkscape:connector-curvature="0" + id="path844" + d="M 83.156837,42.247351 140.12941,98.124744" + style="opacity:1;vector-effect:none;fill:none;fill-opacity:1;stroke:#000000;stroke-width:1.49950945;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> + </g> + <path + style="fill:none;stroke:#000000;stroke-width:0.24979377px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" + d="M 40.224063,98.498922 H 184.46942" + id="path870" + inkscape:connector-curvature="0" /> + <path + style="fill:none;stroke:#000000;stroke-width:0.2520366px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" + d="M 82.880276,13.806447 V 123.81459" + id="path872" + inkscape:connector-curvature="0" /> + <text + xml:space="preserve" + style="font-style:normal;font-weight:normal;font-size:6.71695948px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.16792399" + x="151.95204" + y="24.46769" + id="text878"><tspan + sodipodi:role="line" + id="tspan876" + x="151.95204" + y="24.46769" + style="stroke-width:0.16792399">xy-plane</tspan></text> + <text + xml:space="preserve" + style="font-style:normal;font-weight:normal;font-size:4.21048069px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.10526202" + x="65.537895" + y="109.44188" + id="text882"><tspan + sodipodi:role="line" + id="tspan880" + x="65.537895" + y="109.44188" + style="stroke-width:0.10526202">(0, 0)</tspan></text> + <text + id="text886" + y="109.44188" + x="133.54187" + style="font-style:normal;font-weight:normal;font-size:4.21048069px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.10526202" + xml:space="preserve"><tspan + style="stroke-width:0.10526202" + y="109.44188" + x="133.54187" + id="tspan884" + sodipodi:role="line">(1, 0)</tspan></text> + <text + id="text890" + y="44.147934" + x="65.537895" + style="font-style:normal;font-weight:normal;font-size:4.21048069px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.10526202" + xml:space="preserve"><tspan + style="stroke-width:0.10526202" + y="44.147934" + x="65.537895" + id="tspan888" + sodipodi:role="line">(0, 1)</tspan></text> + </g> +</svg> |