Post Reply 
(49g 50g) Shoelace algorithm
08-23-2018, 08:23 PM (This post was last modified: 08-24-2018 02:15 PM by John Keith.)
Post: #3
RE: ( HP49/50) Shoelace algorithm
(08-23-2018 03:33 PM)Albert Chan Wrote:  Why is SWAP necessary ?
Does ABS remove the sign of sum anyway ?

Sorry if the question sound stupid, I do not know RPL.
A mini-tutorial of how above code work would be nice ...

Does "DUP 1. 2. SUB +" produce {X1 Y1 X2 Y2...Xn Yn X1 Y1} ?
Is this "flatten" list (pick 4 at a time) the reason for the 2.5X speedup ?

To answer your questions more or less in order:

The SWAP is necessary for each group of coordinates because the answer depends on the order of subtraction. The ABS at end gives a positive answer even if the points are ordered clockwise. EDIT: apparently not, see post below.

The code works exactly the same way as Thomas's code in the linked thread. Most of the speed-up is due to the math being done on the stack rather than by higher level commands such as CROSS. That is one of the trade-offs in RPL even more than in other languages. Stack commands are less readable but much faster.

And yes, the DUP 1. 2. SUB + appends the first pair of coordinates onto the end of the list as the algorithm requires.

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-23-2018 08:23 PM



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