Shoelace formula for polygonal area: Difference between revisions

add RPL - optimized version
(add RPL)
(add RPL - optimized version)
Line 1,791:
|-
|
≪ DUP SIZE → points n
pointsDUP 1 GET OBJ→+ →V2 { 2 1 } RDM
0 2 n3 1PICK SIZE '''FOR''' j
pointsOVER j GET OBJ→ →V2LAST 1 COL+ -1 '''STEP'''GET
OVER RE OVER IM * SWAP RE ROT IM * - +
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 ) ''
append 1st vertice at the end
initialise matrix with (x1, y1)
addsum n= columns0 with; (xj,loop yj)
get 2 vertices
sum += determinant
sum n 2x2 determinants along the matrix
end loop
finalize calculation, clean stack
return area
Line 1,814:
1: 30
</pre>
 
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">
1,150

edits