i have a polygon with a set of known vertices but i keep getting negative numbers for my areas. i was wondering what i am doing wrong?

i looked up the formula here. (http://en.wikipedia.org/wiki/Polygon) where it talks about in the middle about getting the area and the centroid and in this case i want to find A.
the point A is what i want to find. the first set of points happens to be:

as you can see by the points this polygon going clockwise, therefore it is possible to get a negative number(this is referred to in the wiki article) but i wanted to be sure that i got the correct answer and am doing this correctly.

answer = -0.2. can anyone confirm? and then thus taking the absolute value would give a final answer of 0.2. thanks all for the help!

Rosario Leonardi

08-28-2008, 05:56 PM

Quoting your link:

The vertices must be ordered clockwise or counterclockwise; if they are ordered clockwise the area will be negative but correct in absolute value.
It also state that the formula work if the polygon is not overlapping.
http://img409.imageshack.us/img409/7538/polygonareazr5.jpg (http://imageshack.us)
Notice that your polygon have a double point (A = E)
BTW The area of this polygon is (OC*AB)/2 = 10^-6

cutting_crew

08-28-2008, 09:00 PM

Quoting your link:

The vertices must be ordered clockwise or counterclockwise; if they are ordered clockwise the area will be negative but correct in absolute value.
It also state that the formula work if the polygon is not overlapping.
http://img409.imageshack.us/img409/7538/polygonareazr5.jpg (http://imageshack.us)
Notice that your polygon have a double point (A = E)
BTW The area of this polygon is (OC*AB)/2 = 10^-6

yes but the first and last point are always duplicates for the purpose of closing the polygon. if you draw out each line segment you would see that this is possible. also as far as i can read this is part of the formula that is requires for calculation concave polygons.

someone else might be able to correct me on that.

Rosario Leonardi

08-29-2008, 07:59 AM

Yep you are right* :)
I write a simple C++ program to try the formula and it works, the result is
-1.00016 e-6

If I invert the order of the point (counter clockwhise) I get a positive value
9.96806e-007
The errors are caused by floating approximation, this algorithm work with large number to produce small result, this lead to a non-irrelevant cancellation error.

You can reduce the approximation error translating all the point near the origin.