How Can You Calculate the Area of a Polygon Using Coordinates?

  • Context: MHB 
  • Thread starter Thread starter cavalieregi
  • Start date Start date
  • Tags Tags
    advanced Area
Click For Summary

Discussion Overview

The discussion revolves around calculating the area of a polygon using its vertex coordinates, specifically focusing on methods applicable in programming contexts. Participants explore mathematical approaches to estimate the area without a defined function for the shape, considering the use of triangles and vector operations.

Discussion Character

  • Exploratory
  • Mathematical reasoning
  • Technical explanation

Main Points Raised

  • One participant describes the setup of coordinates for a polygon and expresses uncertainty about calculating the area without a function, suggesting the use of triangles.
  • Another participant proposes a formula involving the cross product of vectors to calculate the area by dividing the polygon into triangles, emphasizing that the orientation of the shape affects the sign of the area.
  • A request for an example involving an intersecting polygon is made, indicating a need for clarification on applying the proposed formula.
  • A follow-up example is provided using a simple square polygon, demonstrating the application of the area formula and correcting an earlier omission of a factor in the formula.

Areas of Agreement / Disagreement

Participants generally agree on the use of triangles and vector operations to calculate the area, but there remains uncertainty regarding the application of the formula to more complex shapes, such as intersecting polygons.

Contextual Notes

Some participants note the importance of orientation in determining the sign of the area, and there is an acknowledgment of the need for examples to clarify the application of the discussed methods.

cavalieregi
Messages
41
Reaction score
0
I have been given various corners which are x and y coordinates for a shape. The coordinates are listed in a vector e.g. xpoints = [x1, x2, x3, …, xn, x1] and ypoints = [y1, y2, y3, …, yn, y1] so that corner 1 would be (x1,y2) and corner n would be (xn, yn). I have listed the first point last so that I can calculate the distance between each point in the shape when using the distance equation. These distances added up will give the perimeter. These points could be anything. The lines made between each point are straight. I was wondering is there a way where I could calculate the total area roughly. I don’t think I could integrate it as I don’t have a function for the shape. I was thinking maybe since all of the lines are straight maybe triangles could be used? Note this is for a programming assignment but is there a mathematical method anyone could think of which I could use to approach this. The picture shows examples of possible areas. Also note the points can be negative to. Also is there any way some could think of only calculating the shaded area. See picture for reference. It include possible shapes.

View attachment 2163
 

Attachments

  • Capture.JPG
    Capture.JPG
    60 KB · Views: 122
Mathematics news on Phys.org
cavalieregi said:
I have been given various corners which are x and y coordinates for a shape. The coordinates are listed in a vector e.g. xpoints = [x1, x2, x3, …, xn, x1] and ypoints = [y1, y2, y3, …, yn, y1] so that corner 1 would be (x1,y2) and corner n would be (xn, yn). I have listed the first point last so that I can calculate the distance between each point in the shape when using the distance equation. These distances added up will give the perimeter. These points could be anything. The lines made between each point are straight. I was wondering is there a way where I could calculate the total area roughly. I don’t think I could integrate it as I don’t have a function for the shape. I was thinking maybe since all of the lines are straight maybe triangles could be used? Note this is for a programming assignment but is there a mathematical method anyone could think of which I could use to approach this. The picture shows examples of possible areas. Also note the points can be negative to. Also is there any way some could think of only calculating the shaded area. See picture for reference. It include possible shapes.

Hi cavalieregi! Welcome to MHB! :)

Yes. There is a formula to calculate the area.

We can divide the area in a series of triangles.
Suppose $\mathbf p_i$ is the vector pointing to point i, which has coordinates (xi,yi).

Then the first triangle is between $\mathbf p_1$ , $\mathbf p_2$ and $\mathbf p_3$. The second triangle is between $\mathbf p_1$, $\mathbf p_3$ and $\mathbf p_4$, and so on. That is, all triangles have $\mathbf p_1$ as a common point.

The formula is:
$$\text{Area} = \frac 1 2 \left| \sum_{k=2}^{n-1} (\mathbf p_k - \mathbf p_1) \times (\mathbf p_{k+1} - \mathbf p_1)\right|$$

The operator $\times$ indicates the cross product between vectors.
In this case the cross product between the 2 vectors (a,b) and (c,d) can be represented as (ad - bc).

Calculating it like this, means that a hole such as you have, will indeed not be counted.
More specifically, a shape that is oriented counterclockwise is counted positive, while a shape that is oriented clockwise is counted negative.
Taking the absolute value of the result ensures you get a positive area.
 
Thanks for that could you please give me an example with a small intersecting polygon. I don't know how I would apply this formula to any area. Thanks.
 
cavalieregi said:
Thanks for that could you please give me an example with a small intersecting polygon. I don't know how I would apply this formula to any area. Thanks.

Let's start with a simple polygon.
Say ((1,1), (2,1), (2,2), (1,2)), which is a square of size 1, which is oriented counterclockwise (aka positive).

Btw, I forgot a factor 1/2, which I've added to my original post just now.

The (new) formula says that:
\begin{aligned}\text{Area}
&= \frac 1 2 \left|\ \Big((2,1) - (1,1)\Big) \times \Big((2,2) - (1,1)\Big) + \Big((2,2) - (1,1)\Big) \times \Big((1,2) - (1,1)\Big)\ \right| \\
&= \frac 1 2 \left|\ (1,0) \times (1,1) + (1,1) \times (0,1)\ \right| \\
&= \frac 1 2 \left|\ (1\cdot 1 - 0 \cdot 1) + (1 \cdot 1 - 1 \cdot 0)\ \right| \\
&= 1\end{aligned}

Note that the symbol $\times$ in this context denotes the so called cross product of vectors as opposed to normal multiplication.
 

Similar threads

  • · Replies 10 ·
Replies
10
Views
2K
Replies
1
Views
2K
Replies
8
Views
6K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
2
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 20 ·
Replies
20
Views
4K
  • · Replies 2 ·
Replies
2
Views
5K
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K