Shoelace formula for polygonal area: Difference between revisions
Content added Content deleted
(add RPL) |
(add RPL - optimized version) |
||
Line 1,791: | Line 1,791: | ||
|- |
|- |
||
| |
| |
||
≪ |
|||
≪ DUP SIZE → points n |
|||
DUP 1 GET + |
|||
0 2 3 PICK SIZE '''FOR''' j |
|||
OVER j GET LAST 1 - GET |
|||
OVER RE OVER IM * SWAP RE ROT IM * - + |
|||
0 1 n '''FOR''' j |
|||
'''NEXT''' |
|||
ABS 2 / SWAP DROP |
|||
≫ <span style="color:blue">''''SHOEL''''</span> STO |
|||
| |
| |
||
<span style="color:blue">'''SHOEL'''</span> ''( { (vertices) } → area ) '' |
<span style="color:blue">'''SHOEL'''</span> ''( { (vertices) } → area ) '' |
||
append 1st vertice at the end |
|||
initialise matrix with (x1, y1) |
|||
sum = 0 ; loop |
|||
get 2 vertices |
|||
sum += determinant |
|||
sum n 2x2 determinants along the matrix |
|||
end loop |
|||
finalize calculation, clean stack |
finalize calculation, clean stack |
||
return area |
return area |
||
Line 1,814: | Line 1,814: | ||
1: 30 |
1: 30 |
||
</pre> |
</pre> |
||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
<syntaxhighlight lang="ruby"> |
<syntaxhighlight lang="ruby"> |