Area of Irregular Polygon

Peter TB Brett peter.brett at livecode.com
Mon Nov 9 05:18:43 EST 2015


On 08/11/2015 00:43, Alex Tweedly wrote:
> Actually, you should shorten the maths - makes it a bit more efficient
>
>
> function getArea pPts
>     if line 1 of pPts <> line -1 of pPts then return 0
>     put 0 into tArea
>     put empty into oldL
>     repeat for each line L in pPts
>        if oldL is not empty then
>           --         put item 1 of L - item 1 of oldL into dx
>           --         put item 2 of oldL + (item 2 of L - item 2 of oldL)
> / 2 into avgY
>           --         put dx * avgY into thisArea
>           --         add thisArea to tArea
>           add (item 1 of L - item 1 of oldL) * ( item 2 of oldL + item 2
> of L) / 2 to tArea
>        end if
>        put L into oldL
>     end repeat
>     return abs(tArea)
>
> end getArea

Hi Alex,

It seems to me that this algorithm assumes that the polygon is convex, 
and it will add area that should be subtracted if the polygon isn't 
convex.  Am I correct?  Is there any way to include a test for convexity?

                                  Peter

-- 
Dr Peter Brett <peter.brett at livecode.com>
LiveCode Open Source Team

LiveCode on reddit: https://reddit.com/r/livecode




More information about the use-livecode mailing list