How to resolve the algorithm Shoelace formula for polygonal area step by step in the F# programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Shoelace formula for polygonal area step by step in the F# programming language
Table of Contents
Problem Statement
Given the n + 1 vertices x[0], y[0] .. x[N], y[N] of a simple polygon described in a clockwise direction, then the polygon's area can be calculated by: (Where abs returns the absolute value) Write a function/method/routine to use the the Shoelace formula to calculate the area of the polygon described by the ordered points:
Show the answer here, on this page.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Shoelace formula for polygonal area step by step in the F# programming language
Source code in the fsharp programming language
// Shoelace formula for area of polygon. Nigel Galloway: April 11th., 2018
let fN(n::g) = abs(List.pairwise(n::g@[n])|>List.fold(fun n ((nα,gα),(nβ,gβ))->n+(nα*gβ)-(gα*nβ)) 0.0)/2.0
printfn "%f" (fN [(3.0,4.0); (5.0,11.0); (12.0,8.0); (9.0,5.0); (5.0,6.0)])
You may also check:How to resolve the algorithm Algebraic data types step by step in the Scala programming language
You may also check:How to resolve the algorithm Address of a variable step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Integer comparison step by step in the Phixmonti programming language
You may also check:How to resolve the algorithm Arbitrary-precision integers (included) step by step in the Go programming language
You may also check:How to resolve the algorithm Comments step by step in the Isabelle programming language