Feedback for these lessons is very much welcome. If you like or hate something about a lesson let us know, either on GitHub, via Mail or just tell us in person ;)
x
A02 - Polygon Area calculation
Calculate the area of a polyon given with a set of points (2D) to represent its vertices.1
Step 1
Create two int
arrays. One for all x and the other for all y coordinates. Fill those with values.
Step 2
Create an method (it need to be static
2) that take two arrays as input parameter und calculate a float value as area.
Step 3
Go through all points in the two input arrays and calculate the area of the polygon3. Use a while
or do while
loop to achieve this.
If you need to make the solution absolut use the Abs-Method4.
Hint: That calculation uses pairs of points (with the left or right neighbour). So you need to use the pair from the last to the first point or the other way round too.
Step 4
Show the solution in the console and verify that it worked correctly.