721
edits
Line 56: | Line 56: | ||
== Example Centroid Calculation == | == Example Centroid Calculation == | ||
[[File:centroid_2points1.png|800px]] | |||
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. | ||
p0 = (1,1), p1= (4,2) | p0 = (1,1), p1= (4,2) | ||
p0 + p1 | c = p0 + p1; | ||
(1,1) + (4,2) = (5,3) | c = (1,1) + (4,2) = (5,3) | ||
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: | ||
centroid = p2 /3 = (5,3) / 2 = (2.5, | centroid = p2 /3 = (5,3) / 2 = (2.5,1.5) | ||
In this case our centroid is (2.5, | 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. | ||
Programming Task | ===Programming Task=== | ||
Extend our Point2D class to have the following functions: | Extend our Point2D class to have the following functions: |