Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | None | 0 0
  1. def eq(a, b):
  2.         return abs(a - b) < 1e-6
  3.  
  4. def dist(a, b):
  5.         return ((a[0] - b[0])**2 + (a[1] - b[1])**2)**.5
  6.  
  7. def parallel(a, b, c, d):
  8.         p = [i - j for (i, j) in zip(a, c)]
  9.         q = [i - j for (i, j) in zip(b, d)]
  10.         return eq(p[0], q[0]) and eq(p[1], q[1])
  11.  
  12. def cross_product(a, b, c):
  13.         p = [i - j for (i, j) in zip(a, b)]
  14.         q = [i - j for (i, j) in zip(c, b)]
  15.         return p[0] * q[1] - p[1] * q[0]
  16.  
  17. def isParallelogram(coords):
  18.         return parallel(coords[0], coords[1], coords[3], coords[2]) and parallel(coords[1], coords[2], coords[0], coords[3]) and not eq(cross_product(coords[1], coords[0], coords[2]), 0)
  19.  
  20. def check(coords):
  21.         for i in permutations(range(4)):
  22.                 if isParallelogram([x[1] for x in sorted(zip(i, coords))]):
  23.                         print(' '.join(list(map(str, i))))
  24.                         return
  25.         print(0)
  26.  
  27. n = int(input())
  28. for i in range(n):
  29.         data = list(map(int, input().split()))
  30.         coords = [data[i: i + 2] for i in range(0, 7, 2)]
  31.         check(coords)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement