def meshes_to_network(meshes): network = Network() network.update_default_node_attributes(mesh=None, vkey=None, fkey=None) network.update_default_edge_attributes(mesh=None, fkey=None) for i, mesh in enumerate(meshes): for vkey in mesh.vertices(): x, y, z = mesh.vertex_coordinates(vkey) network.add_node(x=x, y=y, z=z, mesh=i, vkey=vkey) for u, v in mesh.edges(): u1 = next(network.nodes_where({"vkey": u, "mesh": i})) v1 = next(network.nodes_where({"vkey": v, "mesh": i})) network.add_edge(u1, v1, mesh=i) return network
d = network.add_node(x=0, y=10, z=10, is_anchor=True) e = network.add_node(x=5, y=5, z=0) network.add_edge(a, e, q=random.randint(1, 10)) network.add_edge(b, e, q=random.randint(1, 10)) network.add_edge(c, e, q=random.randint(1, 10)) network.add_edge(d, e, q=random.randint(1, 10)) # numerical data n = network.number_of_nodes() node_index = {node: index for index, node in enumerate(network.nodes())} fixed = list(network.nodes_where({'is_anchor': True})) free = list(network.nodes_where({'is_anchor': False})) fixed[:] = [node_index[node] for node in fixed] free[:] = [node_index[node] for node in free] edges = [(node_index[u], node_index[v]) for u, v in network.edges()] X = network.nodes_attributes('xyz') R = network.nodes_attributes(['rx', 'ry', 'rz']) P = network.nodes_attributes(['px', 'py', 'pz']) Q = network.edges_attribute('q') # compute equilibrium X, Q, F, L, R = dr(X, edges, fixed, P, Q)
# compute all residuals in the new geometry for node in network.nodes(): r = compute_residual(network, node) network.node_attributes(node, ['rx', 'ry', 'rz'], r) # visualize the geometry layer = "ITA20::L5::FormFinding" artist = NetworkArtist(network, layer=layer) artist.draw_nodes(color={ node: (255, 0, 0) for node in network.nodes_where({'is_anchor': True}) }) artist.draw_edges() # visualize the reaction forces lines = [] for node in network.nodes_where({'is_anchor': True}): start = network.node_attributes(node, 'xyz') residual = network.node_attributes(node, ['rx', 'ry', 'rz']) end = subtract_vectors(start, residual) color = (0, 255, 0) lines.append({'start': start, 'end': end, 'arrow': 'end', 'color': color}) compas_rhino.draw_lines(lines, layer=layer)
c = network.add_node(x=10, y=10, z=0, is_anchor=True) d = network.add_node(x=0, y=10, z=10, is_anchor=True) e = network.add_node(x=5, y=5, z=0) network.add_edge(a, e) network.add_edge(b, e) network.add_edge(c, e) network.add_edge(d, e) # visualize the geometry layer = "ITA20::L5::FormFinding" artist = NetworkArtist(network, layer=layer) node_color = {node: (255, 0, 0) for node in network.nodes_where({'is_anchor': True})} artist.draw_nodes(color=node_color) artist.draw_edges() # visualize the forces height = 1.0 world = Frame.worldXY() circle = [[0, 0, 0.5 * 0.7 * height], [0, 0, 1]], 0.05 cylinder = Cylinder(circle, 0.7 * height) circle = [[0, 0, 0.7 * height], [0, 0, 1]], 0.1 cone = Cone(circle, 0.3 * height)