Crazy polygon

A polygon P P with n n sides can be represented by a tuple P = ( P 0 , P 1 , , P n 1 ) P = (P_0, P_1, \dots, P_{n-1}) that contains the vertices P i = ( x i , y i ) R 2 P_i = (x_i, y_i) \in \mathbb{R}^2 of the polygon as elements. Successive points in the tuple are connected by an edge. In addition, last point P n 1 P_ {n-1} is connected to the first point P 0 P_0 .

How large is the area of the polygon shown on the right?

This simple polygon is represented by the following tuple of vertices:

1
2
3
polygon = ((0,0),(1.5,1),(2,-0.5),(2,1.5),(0.5,2),(2.5,2.5),
           (3,-2),(3.5,-1),(3,0),(3.5,0.5),(4,-0.5),(3.5,2),
           (3,1),(3.5,3),(3,4),(1,2.5),(0,3.5),(-1,3),(0,2))


The answer is 9.625.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Markus Michelmann
May 22, 2018

Relevant wiki: Irregular Polygons

The area of a polygon with vertices ( x i , y i ) (x_i,y_i) , i = 1 , , n 1 i = 1, \dots, n-1 is given by the formula A = i = 0 n 1 A i = 1 2 i = 0 n 1 ( x i 1 y i x i y j 1 ) A = \sum_{i = 0}^{n-1} A_i = \frac{1}{2} \sum_{i=0}^{n-1} (x_{i-1} \cdot y_i - x_i \cdot y_{j-1}) where ( x 1 , y 1 ) = ( x n 1 , y n 1 ) (x_{-1},y_{-1}) = (x_{n-1},y_{n-1}) . Each summand of this equation corresponds to the area of a single triangle, which is formed by the points P i 1 P_{i-1} , P i P_i and the origin O = ( 0 , 0 ) O = (0,0) . This triangular area is calculated with the determinant A i = 1 2 x i 1 y i 1 x i y i = 1 2 ( x i 1 y i x i y j 1 ) A_i = \frac{1}{2} \left| \begin{array}{cc} x_{i-1} & y_{i-1} \\ x_i & y_i \end{array} \right| = \frac{1}{2} (x_{i-1} \cdot y_i - x_i \cdot y_{j-1}) Note, that some of summands A i A_i are negative and corrospond to an area outside of the polygon, that has to be subtracted.

The following python program calculates the area for the given polygon:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
polygon = ((0,0),(1.5,1),(2,-0.5),(2,1.5),(0.5,2),(2.5,2.5),
           (3,-2),(3.5,-1),(3,0),(3.5,0.5),(4,-0.5),(3.5,2),
           (3,1),(3.5,3),(3,4),(1,2.5),(0,3.5),(-1,3),(0,2))

def area(p):
    result = 0
    A = p[-1]
    for B in p:
        result = result + 0.5*(A[0]*B[1] - B[0]*A[1])
        A = B
    return result

print(area(polygon))

How do you derive the formula for the area of a polygon with given vertices?

Tom Finet - 2 years, 12 months ago

Log in to reply

It is easier to illustrate this formula in a single triangle. Draw a single triangle with the points A = ( a x , a y ) A = (a_x, a_y) , B = ( b x , b y ) B = (b_x, b_y) and C = ( c x , c y ) C = (c_x, c_y) . The triangular area can be represented as the enclosed area of two functions f ( x ) f (x) and g ( x ) g (x) . Let's assume that the function g ( x ) g (x) is the line A B AB and the function f ( x ) f (x) is composed of the lines A C AC and C B CB . The triangle area then results as the integral I = ( f ( x ) g ( x ) ) d x I = \int (f (x) - g (x)) dx . The integrals can be easily calculated since only trapezoidal shapes need to be considered I = f ( x ) d x g ( x ) d x = 1 2 ( a y + c y ) ( c x a x ) + 1 2 ( c y + b y ) ( b x c x ) 1 2 ( a y + b y ) ( b x a x ) = 1 2 ( ( c x a y c y a x ) + ( b x c y b y c x ) + ( a x b y a y b x ) ) \begin{aligned} I &= \int f (x) dx - \int g (x) dx \\ &= \frac{1}{2} (a_y + c_y) (c_x - a_x) + \frac{1}{2} (c_y + b_y) (b_x - c_x) - \frac{1}{2} (a_y + b_y) (b_x - a_x) \\ &= \frac{1}{2} ((c_x a_y - c_y a_x) + (b_x c_y - b_y c_x) + (a_x b_y - a_y b_x) ) \end{aligned} That's already the formula for the polygon for the case n = 3. For the general case, we just have to show two things:

  • The formula applies, no matter how the triangle is oriented in the xy plane.
  • The formula also holds if we combine two triangles (polygons) into one larger polygon.

If you can understand German, this video might be helpful. Just jump to the minute 44 in the video.

Markus Michelmann - 2 years, 12 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...