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

-- Alex.

On 08/11/2015 00:09, Alex Tweedly wrote:
Roger,

try this (I've done some minimal testing, so do please check it ...)
it assumes the polygon is closed

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
      end if
      put L into oldL
   end repeat
   return abs(tArea)
end getArea

NB you could shorten it, but I left each math step separate to make it easier to debug / check

-- Alex.

On 07/11/2015 22:29, Roger Guay wrote:
Thanks very much, Scott. I do have a long points list that I would have to manipulate even before apply this technique. I’m not looking forward to that, but I may have to go this route.

Cheers,

Roger


On Nov 7, 2015, at 12:05 PM, Scott Rossi <sc...@tactilemedia.com> wrote:

It looks like this could translate to LC if you have the point locations
of your polygon:

https://www.mathsisfun.com/geometry/area-irregular-polygons.html


Regards,

Scott Rossi
Creative Director
Tactile Media, UX/UI Design




On 11/7/15, 2:01 PM, "use-livecode on behalf of Roger Guay"
<use-livecode-boun...@lists.runrev.com on behalf of i...@mac.com> wrote:

Can anyone think of an easy way of getting the area of an Irregular
polygon?

Thanks,

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


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


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


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

Reply via email to