aboutsummaryrefslogtreecommitdiffstats
path: root/worksheets/a3_earthquake.md
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--worksheets/a3_earthquake.md34
1 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
};
```