(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 ? 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 |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 8 Guest(s)