Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Here is a brain-bending task for the daring.
- It's based on an idea I'd like to solve:
- how to write a script to recognise constellations of stars from photographs.
- I've simplified that concept down to constellations having 3 stars of different colours.
- # a, b, c and d represent 4 triangles plotted on graph paper
- # One triangle has been plotted three times, from different points of view and at different magnifications
- # A fourth, different, triangle has been plotted once.
- # The tuples contain the x, y co-ordinates of the 3 points of a triangle.
- # In each triangle, the 3 points have different colours and
- # for all triangles, the points are listed in the same colour order.
- '''
- # Can you write a script to determine which is the odd one out?
- a = [(3.0, 6.0), (3.0, 3.0), (7.0, 3.0)]
- b = [(4.4, 3.2), (4.4, 5.0), (2.0, 5.0)]
- c = [(3.0, 5.2), (5.4, 5.2), (5.4, 2.0)]
- d = [(4.0, 1.0), (5.5, 1.0), (5.5, 3.0)]
- triangles = [a, b, c, d]
- new_triangles = []
- for triangle in triangles:
- new_triangles.append(triangle + [triangle[0]])
- new_triangles.append(new_triangles[0] + [new_triangles[0][0]])
- P1 = []
- P2 = []
- P3 = []
- for triangle in new_triangles:
- P1.append(triangle[0])
- P2.append(triangle[1])
- P3.append(triangle[2])
- import matplotlib.pyplot as plt
- points = [P1, P2, P3]
- colors = ['red', 'green', 'blue']
- # plot each group of points with the same colour
- for point,color in zip(points, colors):
- Xs = [x[0] for x in point]
- Ys = [x[1] for x in point]
- # plot the points only not the line
- plt.scatter(Xs, Ys, c=color, marker='o')
- # plot the line between the points for the triangles
- for triangle in new_triangles:
- Xs = [x[0] for x in triangle]
- Ys = [x[1] for x in triangle]
- plt.plot(Xs, Ys, c='grey')
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement