All you needed to do was triangulate the polygon, such as you did, and add the signed areas of the constituent triangles together. Any area excedents and deficits will cancel each other out.

For instance, say you have a quadrilateral. To compute its area you would simply adds these 2 signed areas:

A(1,2,3) + A(1,3,4)

For a pentagon you would add

A(1,2,3) + A(1,3,4) + A(1,4,5)

For a hexagon of points 7 through 12, the area would be:

(x9(y8-y10) + x10(y9-y11) + x11(y10-y12) + x12(y11-y7) + x7(y12-y8) + x8(y7-y9))/2

And so on for however many sides. Elegant, isn’t it?

This would always give you the correct result regardless whether the given polygon is convex or not, as long as the vertices are numbered consecutively. It won’t work for computing the inner area of self intersecting polygons, though, which is what brought me here after a google search.

It would give you the inside areas minus the areas of the aberrant regions, depending on which you consider to be the inside areas.

]]>I am trying to figure out how to calculate the number of hecka lines(no two lines parallel no two lines concurrent) if they interesect 2926 times in a plane.

any ideas on how to solve this?

thanks

]]>I actually found this page while looking for a solution for the three-dimensional case (finding the volume of a closed 3-dimensional mesh defined by a set of triangles), which I later found here. The solution and the proof is here:

http://www.math.niu.edu/~rusin/known-math/95/volume.poly

My guess (to which I arrived at through some serious hand-waving) is that it can be generalized into n dimensions as:

forall (t in boundary elements) sum(det(t’s vertices)) / n!

]]>If edge vertices are x1,y1 and x2,y2. The area of one trapezoid is: 0.5(X2Y2-X1Y1+X2Y1-X1Y2). The first two terms cancel out as you move around a closed polygon. Hence you are left with summation of 0.5(X2Y1-X1Y2) which is what the original author got (except for the sign).

At first glance it also appears that it should work for self intersecting poylgons too.

]]>Firstly, the assumption you quote in your last paragraph is equivalent to the existence of a triangulation for any polygon, so I think one can safely assume it.

Next, instead of “star-shaped”, choose and fix ANY point in the plane, which we use to join to each vertex. If it helps, you could even put the point in “general position”, so that no two vertices are in the same line with this point. (It’s not needed for the proof.)

How does this not matter in the guessing of the formula? As you say, guess the area of a triangle, formed by joining to – and now sum this cyclically over i. The point is that the area is just the determinant with rows , and if you look at the coefficients of a,b, then they cancel out in the cyclic sum! So you are left with exactly the sum of the cross-term differences.

And finally, given that you are assuming the existence of a triangulation, you do not need to say “by induction” in proving it, once you know the guess. The moment you sum up “correctly” over any such triangulation,

(i) the areas outside the polygon cancel each other off, since they do so for every sub-summation over a triangle contained in the triangulation, and

(ii) once you sum up correctly, the triangles formed by “inside edges” also cancel each other off, being counted once each in opposite directions.

So you are left with exactly what you need – and it equals the sum of the cross-term differences.

]]>It might be worth mentioning that there is a relatively easy way to check if the points are ordered in a counter-clockwise way even if they were not given as such. It’s described for instance in “Introduction to Algorithms”.

It is probably not too hard to check whether the polygon is simple either, though off the top of my head I don’t see if one can do it in linear time.

The formula kind of makes sense I guess. Here’s another way to obtain it:

If you imagine that the polygon is star-shaped, then there is a center O such that the segments joining each vertex with O are fully contained in the polygon, Then, if we imagine that the coordinate axes are centered at O, then we can join the O to each vertex, and compute the areas of the resulting triangles. The area of the triangle formed by points i and i+1 would be half the length of the cross-products , which is exactly what your formula says.

In fact, one can do an induction to get it in the general case (once the answer is known of course, or guessed by the reasoning above). Notice that if are consecutive points, and they are such that the triangle they form is contained in the polygon, then we can join with a straight line, and break the polygon into two polygons, one the triangle, and the other the polygon arising after omitting . Notice that the above formulas applied to the two polygons and then added give us exactly the formula for the big polygon, since they will have the term appearing with opposite signs, and everything else as it should be. Hence by induction that would tell us that the formula does indeed express the area of the polygon, once we know it for triangles.

All that remains now would be to show that in any polygon there should be at least three consecutive points such that the triangle they form is contained in the polygon. It is clear from the pictures, but I’m not yet 100% sure how to prove it, though I feel it should follow from the methods that tell us about the correct orientation of the vertices.

]]>