Shoelace formula for polygonal area: Difference between revisions
Content added Content deleted
(→{{header|Python}}: Tidied, restored a missing argument.) |
(Added XPL0 example.) |
||
Line 1,731: | Line 1,731: | ||
<pre> |
<pre> |
||
The polygon with vertices at [[3, 4], [5, 11], [12, 8], [9, 5], [5, 6]] has an area of 30. |
The polygon with vertices at [[3, 4], [5, 11], [12, 8], [9, 5], [5, 6]] has an area of 30. |
||
</pre> |
|||
=={{header|XPL0}}== |
|||
<lang XPL0>proc real Shoelace(N, X, Y); |
|||
int N, X, Y; |
|||
int S, I; |
|||
[S:= 0; |
|||
for I:= 0 to N-2 do |
|||
S:= S + X(I)*Y(I+1) - X(I+1)*Y(I); |
|||
S:= S + X(I)*Y(0) - X(0)*Y(I); |
|||
return float(abs(S)) / 2.0; |
|||
]; |
|||
RlOut(0, Shoelace(5, [3, 5, 12, 9, 5], [4, 11, 8, 5, 6]))</lang> |
|||
{{out}} |
|||
<pre> |
|||
30.00000 |
|||
</pre> |
</pre> |
||