Polygon's share of its rectangle inconsistent?

Jim Hurley jhurley0305 at sbcglobal.net
Fri Jun 7 11:17:56 EDT 2013


Hi David,

Would it help if you could calculate the area of the polygons?

The following determines the area of any singly connected (the area of a figure 8 is zero) closed polygon:

on mouseUp
   put the points of grc "polygon" into tPoints
   put line 1 of tPoints into tStart
   put the number of lines in tPoints into n
   put 0 into tArea
   repeat with i = 1 to n-1
      put line i+1 of tPoints into tEnd
      put item 1 of tStart - item 1 of tEnd into tWidth
      put (item 2 of tStart + item 2 of tEnd)/2 into tHeight --The average height of this line.
      add tWidth * tHeight to tArea
      put tEnd into tStart
   end repeat
   put  tArea into msg box
end mouseUp

Jim

> 
> Message: 7
> Date: Thu, 6 Jun 2013 19:39:25 -0400
> From: David Epstein <dfepstein at comcast.net>
> To: use-livecode at lists.runrev.com
> Subject: Polygon's share of its rectangle inconsistent?
> Message-ID: <5E916091-0FDE-4C67-9D52-04601757A3AB at comcast.net>
> Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed
> 
> In order to properly adjust the relative area of two dissimilar  
> polygons, I thought I would use a function to determine the fraction  
> of each polygon's rectangle that is covered by the polygon.
> 
> function coverage obLID
>    set the filled of obLID to true
>    put the rect of obLID into r
>    repeat with x = (item 1 of r) to (item 3 of r)
>       repeat with y = (item 2 of r) to (item 4 of r)
>          put x,y into pt
>          if within(obLID,pt) then add 1 to isIn
>          add 1 to all
>       end repeat
>    end repeat
>    return isIn/all
> end coverage
> 
> This seems to work as expected, but I am perplexed by the fact that  
> when I resize an object keeping its proportions constant (drag a  
> corner with the shift key down; or script this) I get a surprising  
> variation in the result.  E.g., a fairly simple shape I tried went  
> from 0.48 coverage up to 0.59 coverage when I shrank its dimensions  
> by about two-thirds.  With tens or hundreds of thousands of pixels  
> being sampled in the calculation, I would not expect this variation.
> 
> Many thanks for any insights or suggestions.
> 
> David Epstein
> *************************





More information about the use-livecode mailing list