721
edits
Line 55: | Line 55: | ||
<code>p0 + p1 + p2 + p3 ... = sum</code> | <code>p0 + p1 + p2 + p3 ... = sum</code> | ||
* divide the sum by out number of point: | * divide the sum by out number of point: | ||
< | <code>centroid = sum / num_of_points</code> | ||
== Example Centroid Calculation == | == Example Centroid Calculation == | ||
Line 62: | Line 62: | ||
Note: We sum up points simply by adding up their x and y values. E.g. | Note: We sum up points simply by adding up their x and y values. E.g. | ||
<code> | |||
p0 = (1,1), p1= (4,2) | p0 = (1,1), p1= (4,2) | ||
c = p0 + p1; | c = p0 + p1; | ||
c = (1,1) + (4,2) = (5,3) | c = (1,1) + (4,2) = (5,3) | ||
</code> | |||
Dividing the point by a number, means to divide both dimensions by the same number: | Dividing the point by a number, means to divide both dimensions by the same number: | ||
<code> | |||
centroid = p2 /3 = (5,3) / 2 = (2.5,1.5) | centroid = p2 /3 = (5,3) / 2 = (2.5,1.5) | ||
</code> | |||
In this case our centroid is (2.5,1.5). As you can see from the drawing above, the centroid lies exactly in the middle of our two points. | In this case our centroid is (2.5,1.5). As you can see from the drawing above, the centroid lies exactly in the middle of our two points. | ||
Line 91: | Line 91: | ||
Here are the points to calculate the centroid for: | Here are the points to calculate the centroid for: | ||
<code> | |||
Point2D p0(0,0); | Point2D p0(0,0); | ||
Point2D p1(0,1); | Point2D p1(0,1); | ||
Point2D p2(1,0); | Point2D p2(1,0); | ||
Point2D p3(1,1); | Point2D p3(1,1); | ||
</code> | |||
And here is a code template to start coding from: https://repl.it/@abnutzer/Homework-2 | And here is a code template to start coding from: https://repl.it/@abnutzer/Homework-2 | ||
Press the "fork" button to work on your own copy of the code! | Press the "fork" button to work on your own copy of the code! | ||
Later in the class, our points will not be two dimensional anymore, but contain different features of our sounds. E.g. it could be 3D: A dimension for the loudness of the bass, one for the mids and one for the treble. In general the resolution of the spectral data will be much higher and thus a point of 128 dimensions or more can be considered. | Later in the class, our points will not be two dimensional anymore, but contain different features of our sounds. E.g. it could be 3D: A dimension for the loudness of the bass, one for the mids and one for the treble. In general the resolution of the spectral data will be much higher and thus a point of 128 dimensions or more can be considered. |