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
points 1 GET OBJ→ →V2 { 2 1 } RDM
DUP 1 GET +
n 1 '''FOR''' j
0 2 3 PICK SIZE '''FOR''' j
points j GET OBJ→ →V2 1 COL+ -1 '''STEP'''
OVER j GET LAST 1 - GET
OVER RE OVER IM * SWAP RE ROT IM * - +
0 1 n '''FOR''' j
OVER j DUP n + 2 + SUB DET + '''NEXT'''
'''NEXT'''
ABS 2 / SWAP DROP
ABS 2 / SWAP DROP
≫ <span style="color:blue">''''SHOEL''''</span> STO
≫ <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)
add n columns with (xj, yj)
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">