Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def is_parallelogram(my_list):
- """
- [(x1, y1), (x2, y2), (x3, y3), (x4, y4)]
- If it is a parallelogram it must satisfy 3 conditions:
- 1. x2 - x1 = x3 - x4 and y2-y1 = y3-y4
- 2. x3 - x1 = x2 - x4 and y3-y1 = y2 - y4
- 3. x3 - x1 = x4 - x2 and y3 - y1 = y4 - y2
- """
- x1, y1, x2, y2, x3, y3, x4, y4 = my_list[0][0], my_list[0][1], my_list[1][0], my_list[1][1], my_list[2][0], my_list[2][1], my_list[3][0], my_list[3][1]
- if (x2-x1 == x3 - x4) and (y2-y1 == y3-y4):
- return True
- elif (x3-x1 == x2-x4) and (y3-y1==y2-y4):
- return True
- elif (x3-x1 == x4-x2) and (y3-y1 == y4-y2):
- return True
- else:
- return False
- print(is_parallelogram([(0, 0), (1, 0), (1, 1), (0, 1)]))
- print(is_parallelogram([(0, 0), (2, 0), (1, 1), (0, 1)]))
- print(is_parallelogram([(0, 0), (1, 1), (1, 4), (0, 3)]))
- print(is_parallelogram([(0, 0), (1, 2), (2, 1), (3, 3)]))
- print(is_parallelogram([(0, 0), (1, 0), (0, 1), (1, 1)]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement