Math question: How to compute the area of polygons
Jim Hurley
jhurley at infostations.com
Fri Mar 21 09:25:00 EST 2003
>
> > Ben Rubinstein | Email: benr_mc at cogapp.com
>> Cognitive Applications Ltd | Phone: +44 (0)1273-821600
>> http://www.cogapp.com | Fax : +44 (0)1273-728866
>>
>
>Here is a little routine I have written that will accurately calculate the
>area of irregular polygons so long as there are no crossed lines. You can
>have irregular shapes as funky as you like and this will work -- provided
>there are no lines which cross.
>
>The math behind this is fascinating.
>
>Area returned is in pixels. If you wish to use units as square cm, square
>inches, etc. it can be appropriately adjusted.
>
>function IrPolyArea i
> put the points of graphic i into k
> put 0,0 into n
> repeat for each line i in k
> add item 1 of i*item 2 of n-item 2 of i *item 1 of n to tsum
> put i into n
> end repeat
> return abs(tsum/2)
>end IrPolyArea
>
>Raymond E. Griffith
>
Ray,
This is really slick. I had to change the notation as follows before
I could decipher your clever algorithm:
on function IrPolyArea i
put the points of graphic i into tPoints
put 0,0 into tPreviousLine
repeat for each line tLine in tPoints
add item 1 of tLine *item 2 of tPreviousLine - item 2 of tLine
*item 1 of tPreviousLine to tsum
put tLine into tPreviousLine
end repeat
return abs(tsum/2)
end IrPolyArea
Jim
More information about the use-livecode
mailing list