Shoelace formula for polygonal area: Difference between revisions

add RPL
No edit summary
(add RPL)
Line 1,785:
</pre>
 
=={{header|RPL}}==
{| class="wikitable"
! RPL code
! Comment
|-
|
≪ DUP SIZE → points n
≪ points 1 GET OBJ→ →V2 { 2 1 } RDM
n 1 '''FOR''' j
points j GET OBJ→ →V2 1 COL+ -1 '''STEP'''
0 1 n '''FOR''' j
OVER j DUP n + 2 + SUB DET + '''NEXT'''
ABS 2 / SWAP DROP
≫ ≫ <span style="color:blue">''''SHOEL''''</span> STO
|
<span style="color:blue">'''SHOEL'''</span> ''( { (vertices) } → area ) ''
initialise matrix with (x1, y1)
add n columns with (xj, yj)
sum n 2x2 determinants along the matrix
finalize calculation, clean stack
return area
|}
{(3,4) (5,11) (12,8) (9,5) (5,6)} <span style="color:blue">'''SHOEL'''</span>
{{out}}
<pre>
1: 30
</pre>
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">
1,150

edits