def __init__(self, size, l0=20.): super(PeriodicGraph, self).__init__() self.mutable_edges = [] self.verts = [[ Vertex(coords=i * SquareGraph.X_DIR + j * SquareGraph.Y_DIR) for i in range(size) ] for j in range(size)] self.l0 = l0 for i in range(size): for j in range(size): vertex = self.verts[i][j] self.register_vertex(vertex) # from this vertex we construct the edges of the triangle of which this vertex is the bottom left vUp = self.verts[(i + 1) % size][j] vRight = self.verts[i][(j + 1) % size] # edges that are not on the side are immutable edge = Edge.make_edge(vertex, vUp) self.register_edge(edge) if not (j == 0): self.mutable_edges.append(edge) edge = Edge.make_edge(vertex, vRight) self.register_edge(edge) if not (i == 0): self.mutable_edges.append(edge) edge = Edge.make_edge(vUp, vRight) self.register_edge(edge) self.mutable_edges.append(edge) # From this vertex, we construct the triangle of which it is the bottom left corner self.register_area(Area.make_area(vertex, vUp, vRight)) # When all edges are complete, we create the triangles that point down, # each vertex constructs the triangle of which it is the upper left corner for i in range(size): for j in range(size): vertex = self.verts[i][j] vDown = self.verts[(i - 1) % size][(j + 1) % size] vRight = self.verts[i][(j + 1) % size] self.register_area(Area.make_area(vertex, vDown, vRight)) for vert in self.vertices: vert.coords = vert.coords * l0 self.summary() assert (self.is_complete()) self.periodX = size * l0 * SquareGraph.X_DIR self.periodY = size * l0 * SquareGraph.Y_DIR self.toSq = np.array([self.periodX, self.periodY]).T
if __name__ == "__main__": scale = 50 offset = 60 vs = {"va" : Vertex(coords = np.array([0.37, 0.29], dtype = "float") * scale + offset), "vb" : Vertex(coords = np.array([0.77, 1.45], dtype = "float") * scale + offset), "vc" : Vertex(coords = np.array([2.1, 1.3], dtype = "float") * scale + offset), "vd" : Vertex(coords = np.array([2.1, 0.3], dtype = "float") * scale + offset), "ve" : Vertex(coords = np.array([1.4, 0.], dtype = "float") * scale + offset), "vf" : Vertex(coords = np.array([0.9, 0.1], dtype = "float") * scale + offset), "vg" : Vertex(coords = np.array([0.8, 0.65], dtype = "float") * scale + offset), "vh" : Vertex(coords = np.array([1.5, 1.1], dtype = "float") * scale + offset), "vi" : Vertex(coords = np.array([1.8, 1.1], dtype = "float") * scale + offset)} es = [ Edge.make_edge(vs["va"], vs["vb"]), Edge.make_edge(vs["vb"], vs["vh"]), Edge.make_edge(vs["vh"], vs["vc"]), Edge.make_edge(vs["vc"], vs["vd"]), Edge.make_edge(vs["vd"], vs["ve"]), Edge.make_edge(vs["ve"], vs["vf"]), Edge.make_edge(vs["vf"], vs["va"]), Edge.make_edge(vs["vh"], vs["vi"]), Edge.make_edge(vs["vi"], vs["vc"]), Edge.make_edge(vs["vi"], vs["vd"]), Edge.make_edge(vs["vi"], vs["vg"]), Edge.make_edge(vs["vg"], vs["vh"]), Edge.make_edge(vs["vg"], vs["ve"]), Edge.make_edge(vs["vg"], vs["vf"]), Edge.make_edge(vs["va"], vs["vg"]), Edge.make_edge(vs["vg"], vs["vb"]),