Math question: How to compute the area of polygons
Jim Hurley
jhurley at infostations.com
Tue Mar 18 15:28:29 EST 2003
>
>Message: 6
>Date: Tue, 18 Mar 2003 10:06:57 +0100
>Subject: Math question: How to compute the area of polygons
>From: malte.brill at t-online.de (Malte Brill)
>To: <use-revolution at lists.runrev.com>
>Reply-To: use-revolution at lists.runrev.com
>
>Hi List,
>
>
>this one goes out to the math experts.
>How does one compute the area ( I hope it is the correct Term for
>flaecheninhalt in german) of a polygon with n sides.
>
>(That would get me started.)
>
>I want to extract all lines of 2 polygons by analysing their points,
>evaluate the area of each of them with some magic formula I don´t know ;-)
>and to figure out the area of the smallest polygon surrounding both of them.
>
>Any help will be greatly apprecheated!
>
>Regards,
>
>Malte
>
Hi Malte,
I'm not quite sure what you have in mind. Are these "regular"
polygons? But the following might help get you started.
Put a list of points (x,y coordinates) which defined the polygon
into field 1. The run the following:
on mouseUp
put field 1 into tList
put 0 into area
put line 1 of tList into pOld
repeat with i = 1 to the number of lines in tList
put line i of tList into pNew
add thisToArea(pNew,pOld) to area
put pNew into pOld
end repeat
put area
end mouseUp
function thisToArea ptNew,ptOld
put item 1 of ptNew into xNew
put item 2 of ptNew into yNew
put item 1 of ptOld into xOld
put item 2 of ptOld into yOld
return -(xNew - xOld)*(yNew + yOld)/2
end thisToArea
The area will be found in the message box. For example if field 1
contains the following:
0,0
100,0
100,100
0,100
0,0
The area should be 10,000
Depending on what you have in mind, this might be much easier using
Turtle Graphics.
Hope this gets you going.
Jim
More information about the use-livecode
mailing list