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()
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()
force.vertex[1]['is_param'] = True force.vertex[2]['is_param'] = True force.vertex[3]['is_param'] = True force.vertex[4]['is_param'] = True force.vertex[5]['is_param'] = True force.vertex[6]['is_param'] = True form.vertex[0]['is_fixed'] = True form.vertex[1]['is_fixed'] = True form.vertex[2]['is_fixed'] = True form.vertex[3]['is_fixed'] = True form.vertex[4]['is_fixed'] = True form.vertex[5]['is_fixed'] = True form.vertex[6]['is_fixed'] = True graphstatics.form_update_from_force(form, force) loadpath.optimise_loadpath(form, force) viewer = Viewer(form, force, delay_setup=False) viewer.draw_form(forcescale=5, vertexlabel={key: key for key in form.vertices()}, vertexsize=0.2) viewer.draw_force(vertexlabel={key: key for key in force.vertices()}, vertexsize=0.2) viewer.show()
# -------------------------------------------------------------------------- # End force diagram manipulation # -------------------------------------------------------------------------- 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( lines=force_lines, vertexlabel={key: key for key in force.vertices()}, vertexsize=0.2, edgelabel={uv: index for index, uv in enumerate(force.edges())}) viewer.show()
L = force.edge_length(*force.ordered_edges(form)[1]) for index in index_edges_constant_force: form.edge_attribute(index_edge[index], 'target_force', L) # C. Make edge 4 short (less force) - Try options B and C... # edges_change = [4, 13] # new_length = 5.5 # for edge_change in edges_change: # form.edge_attribute(index_edge[edge_change], 'target_force', new_length) viewer = Viewer(form, force, delay_setup=False) viewer.draw_form( edgelabel={uv: index for index, uv in enumerate(form.edges())}) viewer.draw_force(edgelabel=force_edge_labels) viewer.show() # -------------------------------------------------------------------------- # 4. find force diagram to respect force/geometry constraints and update equilibtium # -------------------------------------------------------------------------- # Identify auto constraints form.identify_constraints() # Reflect all constraints to force diagram force.constraints_from_dual() # Update force diagram given constraints force_update_from_constraints(force)
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()