Anonymous user
Shoelace formula for polygonal area: Difference between revisions
Shoelace formula for polygonal area (view source)
Revision as of 04:05, 13 October 2019
, 4 years ago→{{header|REXX}}: changed whitespace and comments, simplified code, elided use of temporary variables.
m (→{{header|REXX}}: changed whitespace and comments, simplified code, elided use of temporary variables.) |
|||
Line 1,046:
===endpoints as exceptions===
<lang rexx>/*REXX program uses a Shoelace formula to calculate the area of an N-sided polygon. */
parse arg pts; $polygon = 'polygon area of
if pts='' then pts= '(3,4),(5,11),(12,8),(9,5),(5,6)' /*Not specified? Use default. */
do
parse var @ '(' x.
end /*
A=
do j=1 for
jm=j-1; if jm==0 then jm=
A=A + x.j * (y.jp - y.jm) /*compute a part of the area. */
end /*j*/
say
▲say 'polygon area of ' n " points: " pts ' is ───► ' A /*stick a fork in it, we're done*/</lang>
{{out|output|text= when using the default input:}}
<pre>
Line 1,068 ⟶ 1,067:
When calculating the area for many polygons (or where the number of polygon sides is large), this method would be faster.
<lang rexx>/*REXX program uses a Shoelace formula to calculate the area of an N-sided polygon.
parse arg pts; $polygon = 'polygon area of
if pts='' then pts=
do
parse var @ '(' x.
end /*n*/
say
▲say 'polygon area of ' n " points: " pts ' is ───► ' A /*stick a fork in it, we're done*/</lang>
{{out|output|text= is the same as the 1<sup>st</sup> REXX version.}} <br><br>
|