Anonymous user
Shoelace formula for polygonal area: Difference between revisions
Shoelace formula for polygonal area (view source)
Revision as of 07:55, 18 September 2021
, 2 years ago→{{header|Python}}: Sectioned.
(→{{header|jq}}: fix markdown) |
(→{{header|Python}}: Sectioned.) |
||
Line 1,332:
=={{header|Python}}==
===Python: Explicit===
<lang python>>>> def area_by_shoelace(x, y):
"Assumes x,y points go around the polygon in one direction"
Line 1,342 ⟶ 1,343:
30.0
>>>
</lang>
===Python: numpy
<lang python>
# Even simpler:
# In python we can take an advantage of that x[-1] refers to the last element in an array, same as x[N-1].
Line 1,363 ⟶ 1,368:
# x=x-x[0];y=y-y[0]
# before applying the Shoelace formula.
</lang>
===Python: Haskell translation===
Or, defined in terms of '''reduce''' and '''cycle''':
{{Trans|Haskell}}
|