Post Reply 
(49g 50g) Shoelace algorithm
08-25-2018, 02:02 PM (This post was last modified: 08-25-2018 03:55 PM by Albert Chan.)
Post: #13
RE: ( HP49/50) Shoelace algorithm
Hi, Thomas Klemm. Nice post.

Here is another way, calculations can be done in parallel.
If only x's or y's changed, only 1 side need the update.

Let xr = rotated-left x, yr = rotated-left y. Borrowing your example:
x = [4, 0, -2, -6, -1, 5]
xr= [0, -2, -6, -1, 5, 4]
y = [4, 1, 5, 0, -4, -2]
yr= [1, 5, 0, -4, -2, 4]

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

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

Confirm the numbers ...

xr + x = [4, -2, -8, -7, 4, 9]
yr - y = [-3, 4, -5, -4, 2, 6]
A = 1/2 sum([-12, -8, 40, 28, 8, 54]) = 110/2 = 55

(xr + x)^2 = [16, 4, 64, 49, 16, 81]
x * xr = [0, 0, 12, 6, -5, 20]
xdiff = [16, 4, 52, 43, 21, 61]
6A*Cx = sum(xdiff * (yr - y)) = sum([-48, 16, -260, -172, 42, 366]) = -56
Cx = -56/6/55 = -28/165 ~ -0.1696969697

(yr + y)^2 = [25, 36, 25, 16, 36, 4]
y * yr = [ 4, 5, 0, 0, 8, -8]
ydiff = [21, 31, 25, 16, 28, 12]
xr - x = [-4, -2, -4, 5, 6, -1]
6A*Cy = sum(ydiff * (xr - x)) = sum([-84, -62, -100, 80, 168, -12]) = -10
Cy = -10/6/55 = -1/33 ~ -0.0303030303
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 - Albert Chan - 08-25-2018 02:02 PM



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