Post Reply 
(49g 50g) Shoelace algorithm
02-28-2019, 02:43 PM (This post was last modified: 08-30-2019 10:11 PM by Albert Chan.)
Post: #21
RE: (49g 50g) Shoelace algorithm
(08-25-2018 02:02 PM)Albert Chan Wrote:  Let xr = rotated-left x, yr = rotated-left y ...

2*A = sum((x*yr - xr*y))
= sum(xr*yr - xr*y + x*yr - x*y)
= sum((xr + x)(yr - y))

Just noticed this re-arranged shoelace area formula can proof itself easily:

A = ½ sum((xr + x)(yr - y)) = -½ sum((yr + y)(xr - x))

|A| = \( \large \left| \left[\sum_{i=1}^{n-1}\frac{(y_{i+1}+y_{i})}{2}(x_{i+1}-x_{i}) \right] - \frac{(y_{n}+y_{1})}{2} ( x_{n}-x_{1}) \right| \)

First term is summing all the little trapezoid areas. Last term is area of the base.

Update: polygon area and perimeter implemented in Mathematica

area[v_] := Apply[area, Transpose[v]]; (* v = list of vertices *)
area[x_, y_] := Abs[Dot[RotateLeft[x]+x, RotateLeft[y]-y]] / 2

perimeter[x_,y_] := Plus @@ Abs[MapThread[Complex, {RotateLeft[x]-x, RotateLeft[y]-y}]]
Find all posts by this user
Quote this message in a reply
07-13-2019, 01:20 PM
Post: #22
RE: (49g 50g) Shoelace algorithm
Another interesting (and short!) version by user telemachos in this thread.
Find all posts by this user
Quote this message in a reply
08-24-2019, 01:19 PM
Post: #23
RE: (49g 50g) Shoelace algorithm
At Albert Chan's request, I am posting an HP-48G / HP 50 program for the perimeter of a polygon. Stack diagram is the same as for Thomas's programs for polygon area and centroid:

xs ys -> p

Code:

\<< R\->C DUP HEAD + 2.
  \<< - ABS
  \>> DOSUBS \GSLIST
\>>
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 2 Guest(s)