Shoelace formula for polygonal area: Difference between revisions

Line 897:
<pre>Polygonal area by shoelace formula:
[[3,4],[5,11],[12,8],[9,5],[5,6]] -> 30</pre>
 
=={{header|jq}}==
{{trans|Wren}}
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
 
<lang jq># jq's length applied to a number is its absolute value.
def shoelace:
. as $a
| reduce range(0; length-1) as $i (0;
. + $a[$i][0]*$a[$i+1][1] - $a[$i+1][0]*$a[$i][1] )
| (. + $a[-1][0]*$a[0][1] - $a[0][0]*$a[-1][1])|length / 2;
 
[ [3, 4], [5, 11], [12, 8], [9, 5], [5, 6] ]
| "The polygon with vertices at \(.) has an area of \(shoelace)."</lang>
{{out}}
<pre>
The polygon with vertices at [[3,4],[5,11],[12,8],[9,5],[5,6]] has an area of 30.
</pre>
 
 
=={{header|Julia}}==
2,455

edits