Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def triangulation(points):
- vertices = wrapPoints(points)
- vertices = sorted(vertices, key=lambda vertex : vertex.y, reverse=True)
- divideToChains(vertices)
- LC, RC = showChains(vertices)
- stack = []
- stack.append(vertices[0])
- stack.append(vertices[1])
- for vertex in vertices[2:]:
- #print("ver: ", vertex.x, " ", vertex.y)
- top = stack.pop()
- #print("top: ", top.x, " ", top.y)
- if vertex.chain != top.chain:
- top.otherPoints.append(vertex)
- vertex.otherPoints.append(top)
- while stack:
- v = stack.pop()
- if not vertex.preceding == v and not vertex.following == v:
- v.otherPoints.append(vertex)
- vertex.otherPoints.append(v)
- stack.append(top)
- stack.append(vertex)
- else:
- second = stack.pop()
- if vertex.chain == ChainType.LEFT and detSgn(det(vertex, top, second)) == 1:
- stack.append(second)
- stack.append(top)
- stack.append(vertex)
- elif vertex.chain == ChainType.RIGHT and detSgn(det(vertex, top, second)) == -1:
- stack.append(second)
- stack.append(top)
- stack.append(vertex)
- else:
- vertex.otherPoints.append(second)
- second.otherPoints.append(vertex)
- stack.append(second)
- stack.append(vertex)
- return vertices, LC, RC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement