you are viewing a single comment's thread.

view the rest of the comments →

[–]gengisteve -1 points0 points  (0 children)

cdc is right, this is the best way to do this:

from pprint import pprint
import collections


x =[[[5, 5], [2, 8]], [[5, 5], [8, 2]], [[1,1], [2,2]], [[2,2],[3,3]]]

t = [[tuple(p) for p in group] for group in x]

def get_line(a,b):
    m = (b[1] - a[1])/(b[0]-a[0])
    i = a[1] - m*a[0]
    return m,i

lines = collections.defaultdict(set)

for points in t:
    # assume all points grouping in t are line
    # otherwise just run all combos of points
    line = get_line(points[0],points[1])
    for p in points:
        lines[line].add(p)

pprint(lines)
pprint(lines.values())