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 <[email protected]>
LiveCode Open Source Team

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

_______________________________________________
use-livecode mailing list
[email protected]
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to