Shoelace formula for polygonal area: Difference between revisions

Added solution for Action!
(Added AutoHotkey)
(Added solution for Action!)
Line 63:
<pre>
30
</pre>
 
=={{header|Action!}}==
{{libheader|Action! Tool Kit}}
{{libheader|Action! Real Math}}
<lang Action!>INCLUDE "H6:REALMATH.ACT"
 
PROC Area(INT ARRAY xs,ys BYTE count REAL POINTER res)
BYTE i,next
REAL x1,y1,x2,y2,tmp1,tmp2
 
IntToReal(0,res)
IntToReal(xs(0),x1) IntToReal(ys(0),y1)
FOR i=0 TO count-1
DO
next=i+1
IF next=count THEN
next=0
FI
IntToReal(xs(next),x2) IntToReal(ys(next),y2)
 
RealMult(x1,y2,tmp1)
RealAdd(res,tmp1,tmp2)
RealMult(x2,y1,tmp1)
RealSub(tmp2,tmp1,res)
 
RealAssign(x2,x1) RealAssign(y2,y1)
OD
RealAbs(res,tmp1)
IntToReal(2,tmp2)
RealDiv(tmp1,tmp2,res)
RETURN
 
PROC PrintPolygon(INT ARRAY xs,ys BYTE count)
BYTE i
 
FOR i=0 TO count-1
DO
PrintF("(%I,%I)",xs(i),ys(i))
IF i<count-1 THEN
Print(", ")
ELSE
PutE()
FI
OD
RETURN
 
PROC Test(INT ARRAY xs,ys BYTE count)
REAL res
 
Area(xs,ys,count,res)
Print("Polygon: ")
PrintPolygon(xs,ys,count)
 
Print("Area: ")
PrintRE(res) PutE()
RETURN
 
PROC Main()
INT ARRAY
xs(5)=[3 5 12 9 5],
ys(5)=[4 11 8 5 6]
 
Put(125) PutE() ;clear screen
 
Test(xs,ys,5)
RETURN</lang>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Shoelace_formula_for_polygonal_area.png Screenshot from Atari 8-bit computer]
<pre>
Polygon: (3,4), (5,11), (12,8), (9,5), (5,6)
Area: 30
</pre>
 
Anonymous user