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 static2) 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.

  1. You can find the solution to this task Here.

  2. We discuss static in a different lesson. So be patient ;)

  3. Wikipedia site for polygon area calculation.

  4. MSDN site for Math.Abs()