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) for node in network.nodes(): a = network.node_attributes(node, 'xyz') for nbr in network.neighbors(node): edge = node, nbr if not network.has_edge(*edge): edge = nbr, node b = network.node_attributes(nbr, 'xyz') force = network.edge_attribute(edge, 'f') direction = normalize_vector(subtract_vectors(b, a)) frame = Frame.from_plane([a, direction]) X = Transformation.from_frame_to_frame(world, frame) S = Scale.from_factors([force, 1, 1]) X = X * S shaft = cylinder.transformed(X) tip = cone.transformed(X) artist = CylinderArtist(shaft, layer=layer, color=(255, 0, 0)) artist.draw(u=16) artist = ConeArtist(tip, layer=layer, color=(255, 0, 0)) artist.draw(u=16)
fixed[:] = [node_index[node] for node in fixed] free[:] = [node_index[node] for node in free] X = network.nodes_attributes('xyz') R = network.nodes_attributes(['rx', 'ry', 'rz']) i_nbrs = { node_index[node]: [node_index[nbr] for nbr in network.neighbors(node)] for node in network.nodes() } ij_force = {} for u, v in network.edges(): i = node_index[u] j = node_index[v] force = network.edge_attribute((u, v), 'f') ij_force[i, j] = force ij_force[j, i] = force # initialize update_R() # run iterations tol = 0.01 kmax = 100 for k in range(kmax): if k % 10 == 0: if sum(length_vector(R[i]) for i in free) < tol: