Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. def triangulation(points):
  2. vertices = wrapPoints(points)
  3.  
  4. vertices = sorted(vertices, key=lambda vertex : vertex.y, reverse=True)
  5. divideToChains(vertices)
  6.  
  7. LC, RC = showChains(vertices)
  8.  
  9. stack = []
  10.  
  11. stack.append(vertices[0])
  12. stack.append(vertices[1])
  13.  
  14.  
  15. for vertex in vertices[2:]:
  16. #print("ver: ", vertex.x, " ", vertex.y)
  17. top = stack.pop()
  18. #print("top: ", top.x, " ", top.y)
  19.  
  20. if vertex.chain != top.chain:
  21. top.otherPoints.append(vertex)
  22. vertex.otherPoints.append(top)
  23.  
  24. while stack:
  25. v = stack.pop()
  26.  
  27. if not vertex.preceding == v and not vertex.following == v:
  28. v.otherPoints.append(vertex)
  29. vertex.otherPoints.append(v)
  30.  
  31. stack.append(top)
  32. stack.append(vertex)
  33.  
  34. else:
  35. second = stack.pop()
  36. if vertex.chain == ChainType.LEFT and detSgn(det(vertex, top, second)) == 1:
  37. stack.append(second)
  38. stack.append(top)
  39. stack.append(vertex)
  40. elif vertex.chain == ChainType.RIGHT and detSgn(det(vertex, top, second)) == -1:
  41. stack.append(second)
  42. stack.append(top)
  43. stack.append(vertex)
  44. else:
  45. vertex.otherPoints.append(second)
  46. second.otherPoints.append(vertex)
  47. stack.append(second)
  48. stack.append(vertex)
  49.  
  50. return vertices, LC, RC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement