Post Reply 
(49g 50g) Shoelace algorithm
08-25-2018, 01:51 AM
Post: #11
RE: ( HP49/50) Shoelace algorithm
(08-24-2018 02:08 PM)John Keith Wrote:  If you have any suggestions for improving the rest of my area-and-centroid program I'm all ears. Smile

I used these formulas found in Centroid:

\(C_{\mathrm {x} }={\frac {1}{6A}}\sum _{i=0}^{n-1}(x_{i}+x_{i+1})(x_{i}\ y_{i+1}-x_{i+1}\ y_{i})\)

\(C_{\mathrm {y} }={\frac {1}{6A}}\sum _{i=0}^{n-1}(y_{i}+y_{i+1})(x_{i}\ y_{i+1}-x_{i+1}\ y_{i})\)

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

(xs ys -- x y area)
Code:
« DUP TAIL OVER HEAD + ROT
  DUP TAIL OVER HEAD +
  → y v x u
  « x v * u y * -
    x u ADD OVER * ∑LIST
    OVER y v ADD * ∑LIST
    ROT ∑LIST
  »
  ROT OVER 3 * / SWAP
  ROT OVER 3 * / SWAP
  2 /
»

Example

For the cat from this video:

xs: { 4 0 -2 -6 -1 5 }
ys: { 4 1 5 0 -4 -2 }


The result is:

3:       -.169696969697
2:        .030303030303
1:                   55


Cheers
Thomas
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 - Thomas Klemm - 08-25-2018 01:51 AM



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