Advertisement
kingbode

Untitled

Aug 3rd, 2022
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.79 KB | None | 0 0
  1. '''
  2.  
  3. Here is a brain-bending task for the daring.
  4. It's based on an idea I'd like to solve:
  5.  
  6. how to write a script to recognise constellations of stars from photographs.
  7.  
  8. I've simplified that concept down to constellations having 3 stars of different colours.
  9.  
  10. # a, b, c and d represent 4 triangles plotted on graph paper
  11. # One triangle has been plotted three times, from different points of view and at different magnifications
  12. # A fourth, different, triangle has been plotted once.
  13. # The tuples contain the x, y co-ordinates of the 3 points of a triangle.
  14. # In each triangle, the 3 points have different colours and
  15. # for all triangles, the points are listed in the same colour order.
  16.  
  17.  
  18. '''
  19.  
  20. # Can you write a script to determine which is the odd one out?
  21.  
  22. a = [(3.0, 6.0), (3.0, 3.0), (7.0, 3.0)]
  23. b = [(4.4, 3.2), (4.4, 5.0), (2.0, 5.0)]
  24. c = [(3.0, 5.2), (5.4, 5.2), (5.4, 2.0)]
  25. d = [(4.0, 1.0), (5.5, 1.0), (5.5, 3.0)]
  26.  
  27. triangles = [a, b, c, d]
  28.  
  29. new_triangles = []
  30. for triangle in triangles:
  31.     new_triangles.append(triangle + [triangle[0]])
  32. new_triangles.append(new_triangles[0] + [new_triangles[0][0]])
  33.  
  34. P1 = []
  35. P2 = []
  36. P3 = []
  37.  
  38. for triangle in new_triangles:
  39.     P1.append(triangle[0])
  40.     P2.append(triangle[1])
  41.     P3.append(triangle[2])
  42.  
  43. import matplotlib.pyplot as plt
  44.  
  45. points = [P1, P2, P3]
  46. colors = ['red', 'green', 'blue']
  47. # plot each group of points with the same colour
  48. for point,color in zip(points, colors):
  49.     Xs = [x[0] for x in point]
  50.     Ys = [x[1] for x in point]
  51.     # plot the points only not the line
  52.     plt.scatter(Xs, Ys, c=color, marker='o')
  53.  
  54. # plot the line between the points for the triangles
  55. for triangle in new_triangles:
  56.     Xs = [x[0] for x in triangle]
  57.     Ys = [x[1] for x in triangle]
  58.     plt.plot(Xs, Ys, c='grey')
  59.  
  60.  
  61. plt.show()
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement