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()
# the system is statically determinate, thus choosing one edge is enough form.edge_force(0, -30.0) # update force densities of form and force diagrams graphstatics.form_update_q_from_qind(form) graphstatics.force_update_from_form(force, form) # ------------------------------------------------------------------------------ # 3. display force and form diagrams # ------------------------------------------------------------------------------ viewer = Viewer(form, force, delay_setup=False, figsize=(12, 7.5)) left = list(form.vertices_where({'x': 0.0, 'y': 0.0}))[0] right = list(form.vertices_where({'x': 6.0, 'y': 0.0}))[0] viewer.draw_form( vertexsize=0.15, vertexcolor={key: '#000000' for key in (left, right)}, vertexlabel={key: key for key in form.vertices()}, edgelabel={uv: index for index, uv in enumerate(form.edges())}) viewer.draw_force(vertexsize=0.15, vertexlabel={key: key for key in force.vertices()}) viewer.show()
from compas_ags.ags import graphstatics as gs __author__ = [ 'Tom Van Mele', ] __copyright__ = 'Copyright 2016 - Block Research Group, ETH Zurich' __license__ = 'MIT License' __email__ = '*****@*****.**' __all__ = [] form = FormDiagram.from_obj(compas.get('lines.obj')) force = ForceDiagram.from_formdiagram(form) viewer = Viewer(form, force, delay_setup=False) viewer.draw_form( vertexsize=0.15, vertexlabel={key: key for key in form.vertices()}, edgelabel={uv: index for index, uv in enumerate(form.edges())}, external_on=True) viewer.draw_force(vertexsize=0.15, vertexlabel={key: key for key in force.vertices()}) viewer.show()
# add arrow to lines to indicate movement force_lines.append({ 'start': force_key_xyz[1], 'end': force.vertex_coordinates(1), 'color': '#ff0000', 'width': 10.0, 'style': '-', }) # display the orginal 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()}, vertexsize=0.2, vertexcolor={key: '#000000' for key in fixed}) viewer.draw_force(lines=force_lines, vertexlabel={key: key for key in force.vertices()}, vertexsize=0.2) 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()
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()
# # change the depth of the structure # force.vertices_attribute('x', 20, [6, 7, 8, 9, 10, 11]) # fix some of the nodes in the from diagram # to constraint the problem to a single solution form.vertices_attribute('is_fixed', True, [0, 2, 5]) # # update the form diagram # graphstatics.form_update_from_force(form, force) # update the form diagram form.data = graphstatics.form_update_from_force_proxy(form.data, force.data) # ============================================================================== # Visualize # ============================================================================== viewer = Viewer(form, force, delay_setup=False, figsize=(12, 7.5)) viewer.draw_form( vertexsize=0.15, vertexcolor={key: '#000000' for key in (8, 7)}, vertexlabel={key: key for key in form.vertices()}) viewer.draw_force( vertexsize=0.15, vertexlabel={key: key for key in force.vertices()}) viewer.show()