Area of Irregular Polygon

Geoff Canyon gcanyon at gmail.com
Sat Nov 7 19:56:53 EST 2015


You could speed it up a bit more and simplify a bit like so:

      put line 1 of pPts into oldL
      repeat for each line L in line 2 to -1 of pPts
         add (item 1 of L - item 1 of oldL) * ( item 2 of oldL + item 2 of
L) / 2 to tArea
         put L into oldL
      end repeat


On Sat, Nov 7, 2015 at 7:46 PM, Roger Guay <irog at mac.com> wrote:

> Beautiful, Alex. I was working on this idea myself, but your scripts is so
> much more elegant!
>
> Thanks,
>
> Roger
>
>
>
> > On Nov 7, 2015, at 4:43 PM, Alex Tweedly <alex at tweedly.org> 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
> >
> > -- 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 <scott at 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-bounces at lists.runrev.com on behalf of irog at 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 at 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 at 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 at 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 at 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 at 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 at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



More information about the use-livecode mailing list