示例#1
0
# 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)

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)
示例#2
0
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]

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()