示例#1
0
def view_form_force(form, force, forcescale=0.5, edge_label=True):
    if edge_label:
        form_edge_label = {uv: index for index, uv in enumerate(form.edges())}
        force_edge_label = force_edge_labels
    else:
        form_edge_label = None
        force_edge_label = None

    viewer = Viewer(form, force, delay_setup=False)
    viewer.draw_form(edgelabel=form_edge_label,
                     forces_on=True,
                     forcescale=forcescale,
                     vertexcolor={key: '#000000' for key in form.vertices_where({'is_fixed': True})})
    viewer.draw_force(edgelabel=force_edge_label)
    viewer.show()
def show(i):
    c = 10
    c += 1
    nsi = ns[i] * c
    # store lines representing the current null space mode
    form_lines = []
    for u, v in form.edges():
        form_lines.append({
            'start':
            [x + y for x, y in zip(form.vertex_coordinates(u, 'xy'), nsi[u])],
            'end':
            [x + y for x, y in zip(form.vertex_coordinates(v, 'xy'), nsi[v])],
            'width':
            1.0,
            'color':
            '#cccccc',
            'style':
            '--'
        })

    form_lines = form_lines + constraint_lines
    # display the original configuration
    # and the configuration after modifying the force diagram

    viewer = Viewer(form, force, delay_setup=False)
    viewer.draw_form(
        lines=form_lines,
        forces_on=False,
        vertexlabel={key: key
                     for key in form.vertices()},
        external_on=False,
        vertexsize=0.2,
        vertexcolor={key: '#000000'
                     for key in fixed},
        edgelabel={uv: index
                   for index, uv in enumerate(form.edges())})

    viewer.draw_force(
        vertexlabel={key: key
                     for key in force.vertices()},
        vertexsize=0.2,
        edgelabel={uv: index
                   for index, uv in enumerate(force.edges())})

    viewer.show()
form = FormDiagram.from_obj(FILE)
force = ForceDiagram.from_formdiagram(form)

# 2. set the fixed points

for key, attr in form.vertices_where({'vertex_degree': 1}, True):
    attr['is_fixed'] = True

# 3. identify independent edges and assign random values

k, m, ind = graphstatics.form_identify_dof(form)

for u, v in ind:
    form.set_edge_attributes((u, v), ('is_ind', 'q'),
                             (True, random.choice(range(2, 20))))

# 4. update diagrams

graphstatics.form_update_q_from_qind(form)
graphstatics.force_update_from_form(force, form)

# 5. visualise

viewer = Viewer(form, force, delay_setup=False)

viewer.draw_form(vertexsize=0.15, external_on=False)

viewer.draw_force(vertexsize=0.15, )

viewer.show()
def show_constraints(form, force):
    viewer = Viewer(form, force, delay_setup=False)
    viewer.draw_form(vertexlabel={key: key for key in form.vertices()},
                    edgelabel={uv: index for index, uv in enumerate(form.edges())},
                    vertexsize=0.2,
                    forces_on=False,
                    vertexcolor={key: '#FF0000' for key in form.vertices_where({'is_fixed_x': True})})
    viewer.draw_force(vertexcolor={key: '#FF0000' for key in force.vertices_where({'is_fixed_x': True})})
    viewer.show()

    viewer = Viewer(form, force, delay_setup=False)
    viewer.draw_form(vertexlabel={key: key for key in form.vertices()},
                    edgelabel={uv: index for index, uv in enumerate(form.edges())},
                    vertexsize=0.2,
                    forces_on=False,
                    vertexcolor={key: '#0000FF' for key in form.vertices_where({'is_fixed_y': True})})
    viewer.draw_force(vertexcolor={key: '#0000FF' for key in force.vertices_where({'is_fixed_y': True})})
    viewer.show()

    viewer = Viewer(form, force, delay_setup=False)
    viewer.draw_form(vertexlabel={key: key for key in form.vertices()},
                    edgelabel={uv: str(form.edge_attribute(uv, 'target_vector')) for uv in form.edges()},
                    vertexsize=0.2,
                    # forces_on=False,
                    vertexcolor={key: '#000000' for key in form.vertices_where({'is_fixed': True})})
    viewer.draw_force(vertexcolor={key: '#000000' for key in force.vertices_where({'is_fixed': True})},
                    edgelabel={uv: str(force.edge_attribute(uv, 'target_vector')) for uv in force.edges()})
    viewer.show()

    viewer = Viewer(form, force, delay_setup=False)
    viewer.draw_form(vertexlabel={key: key for key in form.vertices()},
                    edgelabel={uv: str(form.edge_attribute(uv, 'target_force')) for uv in form.edges()},
                    vertexsize=0.2,
                    # forces_on=False,
                    vertexcolor={key: '#000000' for key in form.vertices_where({'is_fixed': True})})
    viewer.draw_force(vertexcolor={key: '#000000' for key in force.vertices_where({'is_fixed': True})},
                    edgelabel={uv: str(force.dual_edgelength(uv)) for uv in force.edges()})
    viewer.show()
with open(FILE, 'r') as f:
    data = json.load(f)

    form = FormDiagram.from_data(data['data']['form'])
    force = ForceDiagram.from_data(data['data']['force'])
    form.dual = force
    force.dual = form

graphstatics.form_update_from_force(form, force, kmax=100)

# ==============================================================================
# Visualize
# ==============================================================================

viewer = Viewer(form, force, delay_setup=False, figsize=(12, 7.5))

viewer.draw_form(vertexsize=0.15,
                 vertexcolor={
                     key: '#000000'
                     for key in form.vertices_where({'is_fixed': True})
                 },
                 vertexlabel={key: key
                              for key in form.vertices()})

viewer.draw_force(vertexsize=0.15,
                  vertexlabel={key: key
                               for key in force.vertices()})

viewer.show()