Skip to content

Instantly share code, notes, and snippets.

@jszaday
Created January 30, 2019 16:20
Show Gist options
  • Save jszaday/dedd66d1dbb409a26dd1ca8996471285 to your computer and use it in GitHub Desktop.
Save jszaday/dedd66d1dbb409a26dd1ca8996471285 to your computer and use it in GitHub Desktop.
# xys = [ [3.307892425, 39.69470909],
# [12.13809951, 49.46848102],
# [2.169050363, 26.02860435],
# [2.860301106, 22.88240885],
# [2.171773728, 26.06128474],
# [2.860659084, 22.88527267],
# [3.307550518, 39.69060621],
# [12.27431946, 50.02364157] ]
xys = [ [0.714329297, 11.782296],
[1.524101764, 27.17021336],
[0.737747626, 12.16853918],
[0.924299843, 15.13350661],
[0.159854532, 11.68186231],
[1.922945953, 32.53483024],
[0.162243284, 11.85663534],
[1.843049017, 33.07933865] ]
itns = [ xy[1] / xy[0] for xy in xys ]
tol = 0.1
clusters = {}
for i, itn in enumerate(itns):
stored = False
for othr in clusters:
if abs(1 - itn / othr) <= tol:
clusters[othr].append(xys[i])
stored = True
break
if not stored:
clusters[round(itn)] = [ xys[i] ]
print(clusters)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment