Skip to content

Instantly share code, notes, and snippets.

@invisiblefunnel
Last active May 11, 2018 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save invisiblefunnel/a15627d6492c890fea259048bde5ad43 to your computer and use it in GitHub Desktop.
Save invisiblefunnel/a15627d6492c890fea259048bde5ad43 to your computer and use it in GitHub Desktop.
def segmentize(points, km):
npoints = len(points)
if npoints == 0:
return []
elif npoints == 1:
return [points[0]]
a, b = points[:2]
rest = segmentize(points[2:], km)
if haversine(a, b) > km:
ax, ay = a
bx, by = b
c = ((bx + ax) / 2., (by + ay) / 2.)
left = segmentize([a, c], km)
right = segmentize([c, b], km)
return left + right + rest
else:
return [a, b] + rest
@apburnes
Copy link

👀 ☝️

⚫ ⚫ ⚪ ⚫

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment