Mathematical Recreations

MathRec Home
Last Month's Topic
Introductory Topic
Older Topics
and Links
Educational Resources
Steve's Personal Page

Area of a Polygon

Given: a polygon defined by points (x1y1) through (xnyn). The polygon is composed of lines between adjacent vertices, and (x1y1) is adjacent to (xnyn). What is the area of the polygon in terms of the coordinates of the vertices?

The Area of a Triangle

The problem is best attacked by dividing the polygon into triangles. There are several ways to determine the area of a triangle, but more importantly, a triangle only has three vertices, so a general formula for the area of the triangle can't be too complicated.

I'm going to present a solution here that does not presuppose a knowledge of vector operations. If you're comfortable with vector operations, then you should probably skip ahead to the vector solution.

Since the location of the triangle doesn't matter, we can always pick one vertex to be at the origin, simply by taking our coordinates to be (0, 0), (x1 - x0), and (x2 - x0). Therefore, we only need to consider the case where x0  =  0. Also, we can always place the leftmost vertex at the origin, so we only need to consider x1 ≥ 0 and x2 ≥ 0.

It's also convenient to choose which vertex to label x1, and which to label x2. The choice that we make is that the line from the origin to (x2y2) lies above the line from the origin to x1y1. This simplifies the derivation of our formula and also the final result.

There are only a few possibilities to consider. An easy one to describe and to visualize is the case where y1 < 0 and y2 > 0. The area of the triangle can be found easily by dividing it in two along the x-axis. Then the area of each half is simply the one-half the base times the height, where the base is the x-intercept of the line between (x1y1) and (x2y2). Designating this x-intercept as xb, we get

(1) xb  
 =  x1 –   x2x1
 =  x2 –   x2x1
 =    x1 y2x2 y1

Using this value of xb, we find that the area of the triangle is

(2) A  =    1
  xb (y2y1)  =    1
  (x1 y2x1 y2)

It's straightforward to determine that Equation (2) still applies for the other cases when y1 and y2 are on the same side of the x-axis, or when either y1 or y2 are equal to zero. There's a nagging little problem, though—clearly Equation (2) can give a negative value for the area. How do we get out of this dilemma? Well, we took care of it when we required that the line from the origin to (x2y2) lies above the line from the origin to (x1y1).

Now that we recognize that switching x1 and x2 results in a negative area, we're ready to consider the general formula for the area of a triangle where one vertex is at the origin. The area is given by Equation (2), as long as the line from the origin to (x2y2) lies counterclockwise relative to the line from the origin to (x1y1).

The Vector Cross Product

The magnitude of a vector is another term for the length of the vector. If we identify the line from the origin to the point (x1y1) as a vector, then the magnitude of that vector is the length √(x12 + y12).

The vector cross product is a very useful tool for attacking this problem. You can look at my vector operations page for an overview, but we are only interested in a special case. The cross product of two vectors is a vector perpendicular to the two vectors and the magnitude of the cross product is the product of the magnitudes of the original vectors times the sine of the angle between them. This means that the magnitude of the cross product is twice the area of the subtended triangle. The direction of the cross product is defined by the right-hand rule. My favorite way to visualize this relationship is to curl the fingers of my right hand. If the direction from the first vector to the second vector is in the direction that my fingers are pointing, then my thumb points in the direction of the cross product.

If the original vectors are in the (xy) plane, then the cross product is in the ± z direction. If the second vector is counterclockwise with respect to the first, then the cross product is in the z direction.

The cross product has a simple formula in Cartesian coordinates. (Cartesian coordinates are just the familar xyz coordinates.)

(3) (x1, y1, z1) × (x2, y2, z2)  =  (y1z2y2z1, z1x2z2x1, x1y2x2y1)

If the original vectors are in the (xy) plane, then

(4) (x1, y1, 0) × (x2, y2, 0)  =  (0, 0, x1y2x2y1)

Dividing the Polygon

Any polygon can be divided into triangles in all sorts of different ways. The trick is to figure out a way to do it that can be generalized. The problem is that a general polygon may look a bit odd. An approach that works well for a regular octagon might not work as well for the outline of a bold letter T. We'll just ignore that problem for now. (It turns out that the problem will magically evaporate later.) If we only consider convex polygons, then we can divide the polygon into triangles by picking a vertex and drawing a line from that vertex to each of the other vertices. Alternatively, we can pick a point inside the polygon and draw lines from that point to each of the vertices. The latter is more general without being more difficult, so we'll consider that case.

Let the origin be inside the polygon and divide the polygon into triangles by drawing lines from the origin to each vertex. Number the vertices in the counterclockwise direction x1, x2, . . . , xn. Let A1 be the area of triangle from the origin to (x1, y1), then (x2, y2) and back to the origin, and similarly for A2, . . . , An.

We have a simple formula for each of these triangles using Equation (2). A very nice result, and we are done! But what about polygons with strange shapes? Do we have to divide them up into convex polygons then pick a point inside each one? No we don't. In fact, this formula works for polygons where the origin is not inside of the polygon and for polygons with very strange shapes. To see why, consider the case where the origin is outside of the polygon.

When the origin was inside the polygon, then going counterclockwise around the polygon was the same as going counterclockwise around the origin. But when the origin is outside of the polygon, then going counterclockwise around the polygon is going counterclockwise around the origin for the far side of the polygon, but it is going clockwise around the origin for the near side of the polygon. When we simply apply our formula to the vertices labeled counterclockwise around the polygon, we get positive areas for the far side of the polygon, but we get negative areas for the near side of the polygon. This is exactly what we need, and subtracting out the triangles to the near side from the triangles to the far side leaves only the area inside the polygon.

If you want a closed formula, then

(5) 1
 i = 1 
  (xiyi) × (xi+1yi+1) ,

where the points are labeled counterclockwise; we define (xn+1yn+1) = (x1y1); and we consider the two-dimensional cross product to be the z-component of the three-dimensional cross product.

Polygons on a Sphere

I have solved this problem, but it is considerably more involved than the planar case. I have not written the solution in HTML format, but I'll present an outline of the method here.

The area of a triangle on the sphere is equal to the sum of the angles of the triangle minus pi. For example, consider one eighth of a sphere with one vertex at the north pole and the other two vertices on the equator, separated by 90 degrees of longitude. Each angle is 90 degrees or π / 2. The area of the triangle is 3π / 2 – π  =  π / 2, which is one eighth of the area of the sphere.

You can develop a closed formula for the area of a triangle with one vertex at θ = 0, but you have to resolve the clockwise/counterclockwise issue a little differently, because you can always have an angle greater than 180 degrees at θ = 0. This is because two points determine two lines on a sphere—one that goes the short way and one that goes the long way. Anyway, after you resolve all of these issues, then you get a formula that is superficially similar to Equation (5), which finds the area of the polygon, but it requires you to know how many times the path went around the pole.

Send all responses to my email address is mathrec at this domain.