How to resolve the algorithm Shoelace formula for polygonal area step by step in the Arturo 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 Arturo 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 Arturo programming language

Source code in the arturo programming language

define :point [x,y][]

shoelace: function [pts][
    [leftSum, rightSum]: 0

    loop 0..dec size pts 'i [
        j: (i + 1) % size pts
        'leftSum + pts\[i]\x * pts\[j]\y
        'rightSum + pts\[j]\x * pts\[i]\y
    ]
    return 0.5 * abs leftSum - rightSum
]

points: @[
    to :point [3.0, 4.0]
    to :point [5.0, 11.0]
    to :point [12.0, 8.0]
    to :point [9.0, 5.0]
    to :point [5.0, 6.0]
]

print shoelace points


  

You may also check:How to resolve the algorithm Conway's Game of Life step by step in the SQL programming language
You may also check:How to resolve the algorithm Draw a pixel step by step in the Julia programming language
You may also check:How to resolve the algorithm Multifactorial step by step in the C++ programming language
You may also check:How to resolve the algorithm Colour bars/Display step by step in the Ring programming language
You may also check:How to resolve the algorithm Dutch national flag problem step by step in the J programming language