Post Reply 
(49g 50g) Shoelace algorithm
08-24-2018, 02:08 PM (This post was last modified: 08-24-2018 02:09 PM by John Keith.)
Post: #7
RE: ( HP49/50) Shoelace algorithm
(08-24-2018 03:56 AM)Thomas Klemm Wrote:  Alternatively we can use

\(A=\frac{1}{2}\sum_{i=1}^{n}x_{i}(y_{i+1}-y_{i-1})\)

where \(y_{n+1}=y_{1}\) and \(y_{0}=y_{n}\).

(xs ys -- area)
Code:
« DUP TAIL OVER HEAD + SWAP
  REVLIST DUP TAIL SWAP HEAD + REVLIST
  - * ∑LIST 2 /
»

The coordinates of the polygon have to be entered as two separate lists xs and ys.
There might be better ways to rotate the elements of ys left and right.

Kind regards
Thomas

Excellent program, smaller and faster than mine. Smile It also runs on the 48g.

The ListExt Library command LRLLD is the equivalent of DUP TAIL SWAP HEAD + but ListExt is HP49/50 only.

HEAD is very slow and I try to avoid it whenever possible. Though much longer, 1. DUP SUB EVAL is about three times as fast as HEAD!

If you have any suggestions for improving the rest of my area-and-centroid program I'm all ears. Smile

John
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(49g 50g) Shoelace algorithm - John Keith - 08-23-2018, 02:20 PM
RE: ( HP49/50) Shoelace algorithm - John Keith - 08-24-2018 02:08 PM



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