Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Possible Duplicate:
How quickly we forget - basic trig. Calculate the area of a polygon

For a program I want to calculate the area of a given polygon. It may have every form, the sides even may cross. Do you can give me pointers to a way to calculate areas for such polygons?

share|improve this question

marked as duplicate by joriki, J. M., Asaf Karagila, t.b., Zev Chonoles Dec 24 '11 at 18:59

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
How is the polygon given? If its boundary is not a simply closed curve you will have to specify what is meant by "area". –  Christian Blatter Sep 22 '11 at 13:42
    
It is given as a closed linestring, but the lines can cross. –  Mnementh Sep 22 '11 at 13:58
    
it would be worth looking at this question: math.stackexchange.com/questions/15739/… –  yasmar Sep 22 '11 at 18:56
1  
See the Wikipedia entry on this topic: Polygon area –  Joseph O'Rourke Sep 22 '11 at 22:58

1 Answer 1

Let us assume that polygon P has vertices (x1,y1), ..., (xn,yn). Then we can represent the area of the polygon as a sum of trapezoids T(1,2)=(x1,y1)-(x1,0)-(x2,0)-(x2,y2), ..., T(n,1), where area can be counted with opposite sign if x2 < x1:

area(P) = area(T(1,2)) + area(T(2,3)) + ... + area(T(n,1))

and obviously

area(T(i,j)) = (xj-xi)*(yj+yi)/2

share|improve this answer
    
Does that really work if the sides are crossing? Like a polygon representing an eight? –  Mnementh Sep 22 '11 at 12:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.