diff options
author | Matt Strapp <matt@mattstrapp.net> | 2021-10-11 20:20:09 -0500 |
---|---|---|
committer | Matt Strapp <matt@mattstrapp.net> | 2021-10-11 20:20:09 -0500 |
commit | 970293e1094fb50ff1cb6d4b314c55415f9e700b (patch) | |
tree | 7ebea32cbffbecf1a4e563740b4e2ad303f046c1 /worksheets | |
parent | Merge branch 'master' of github.umn.edu:umn-csci-4611-f21/repo-strap012 (diff) | |
download | csci4611-submission-w3.0.tar csci4611-submission-w3.0.tar.gz csci4611-submission-w3.0.tar.bz2 csci4611-submission-w3.0.tar.lz csci4611-submission-w3.0.tar.xz csci4611-submission-w3.0.tar.zst csci4611-submission-w3.0.zip |
Do w3submission-w3.0
Diffstat (limited to 'worksheets')
-rw-r--r-- | worksheets/a3_earthquake.md | 34 | ||||
-rw-r--r-- | worksheets/img/square-edited.png | bin | 0 -> 11664 bytes |
2 files changed, 26 insertions, 8 deletions
diff --git a/worksheets/a3_earthquake.md b/worksheets/a3_earthquake.md index e38902f..125df65 100644 --- a/worksheets/a3_earthquake.md +++ b/worksheets/a3_earthquake.md @@ -18,7 +18,7 @@ numbers `{0.0, 1.5, 2.0, 1.3}`, the normalized value would be `v_normalized = These two functions, part of the C++ standard library, will be useful for your first question: -``` +```cpp /* * - `std::min_element()` - return the minimum of a vector * - `std::max_element()` - return the maximum of a vector @@ -32,9 +32,19 @@ first question: 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: -``` +```cpp std::vector<float> normalize_list(std::vector<float> quakeList) { /* --- Fill in your algorithm here --- */ + vector<float> new_vector; + new_vector.resize(quakeList.size()); + float min = std::min_element(quakeList.begin(), quakeList.end()); + float max = std::max_element(quakeList.begin(), quakeList.end()); + float range = max - min; + for (int i = 0; i < quakeList.size(); i++) { + new_vector[i] = (quakeList[i] - min) / range; + } + return new_vector; + } ``` @@ -43,18 +53,20 @@ 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. -``` +```cpp 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 << normalized_quakes[i] << ", "; } std::cout << std::endl; ``` Output: -``` +```cpp /* --- Fill in the expected output here (e.g. "0.0, 0.5, 0.5, 1.0, 0.5, 0.12, 0.6") --- */ +"0.0, 0.30, 0.67, 0.14, 1.0, 0.22" +" ``` ## Q2: Constructing a mesh @@ -72,22 +84,28 @@ Let's practice all these concepts with a simple example of a square. Create you **Replace this image with your drawing:** -![](./img/square.png) +![](./img/square-edited.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): -``` +```cpp std::vector<Point3> squareVertexArray = { /* --- Fill in your `Point3`s here */ + Point3(0.0, 0.0, 0.0), + Point3(1.0, 0.0, 0.0), + Point3(1.0, 1.0, 0.0), + Point3(0.0, 1.0, 0.0) }; ``` 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. -``` +```cpp std::vector<int> squareIndexArray = { /* --- Fill in your first triangle indices --- */ + 0, 1, 3, /* --- Fill in your second triangle indices --- */ + 1, 2, 3 }; ``` diff --git a/worksheets/img/square-edited.png b/worksheets/img/square-edited.png Binary files differnew file mode 100644 index 0000000..87f004f --- /dev/null +++ b/worksheets/img/square-edited.png |