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

  • Thread starter Thread starter cavalieregi
  • Start date Start date
  • Tags Tags
    advanced Area
AI Thread Summary
To calculate the area of a polygon using coordinates, one effective method is to divide the shape into triangles, using a common vertex. The area can be computed with the formula involving the cross product of vectors formed by the vertices. This approach accounts for the orientation of the shape, ensuring that the area remains positive regardless of the direction of the vertices. An example illustrates this method with a simple square, demonstrating the calculation step-by-step. This technique is useful for programming assignments and can handle polygons with negative coordinates as well.
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: 110
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.
 
Suppose ,instead of the usual x,y coordinate system with an I basis vector along the x -axis and a corresponding j basis vector along the y-axis we instead have a different pair of basis vectors ,call them e and f along their respective axes. I have seen that this is an important subject in maths My question is what physical applications does such a model apply to? I am asking here because I have devoted quite a lot of time in the past to understanding convectors and the dual...
Insights auto threads is broken atm, so I'm manually creating these for new Insight articles. In Dirac’s Principles of Quantum Mechanics published in 1930 he introduced a “convenient notation” he referred to as a “delta function” which he treated as a continuum analog to the discrete Kronecker delta. The Kronecker delta is simply the indexed components of the identity operator in matrix algebra Source: https://www.physicsforums.com/insights/what-exactly-is-diracs-delta-function/ by...
Back
Top