importcompas_agsfromcompas_ags.diagramsimportFormGraphfromcompas_ags.diagramsimportFormDiagramfromcompas_ags.diagramsimportForceDiagramfromcompas_ags.agsimportgraphstaticsfromcompas_ags.viewersimportViewer# ==============================================================================# Construct the graph of a single panel truss,# including loads and reaction forces.# ==============================================================================graph=FormGraph.from_obj(compas_ags.get("paper/gs_form_force.obj"))form=FormDiagram.from_graph(graph)force=ForceDiagram.from_formdiagram(form)# ==============================================================================# Fix the left and right supports.# ==============================================================================left=next(form.vertices_where({"x":0.0,"y":0.0}))right=next(form.vertices_where({"x":6.0,"y":0.0}))fixed=[left,right]form.vertices_attribute("is_fixed",True,keys=fixed)# ==============================================================================# Set the magnitude of the load.# ==============================================================================form.edge_force(1,-10.0)# ==============================================================================# Update the force densities in the form diagram.# ==============================================================================graphstatics.form_update_q_from_qind(form)# ==============================================================================# Update the geometry of the force diagram.# ==============================================================================graphstatics.force_update_from_form(force,form)# ==============================================================================# Store the original geometries.# ==============================================================================force_key_xyz={key:force.vertex_coordinates(key)forkeyinforce.vertices()}form_lines=[]foru,vinform.edges():form_lines.append({"start":form.vertex_coordinates(u,"xy"),"end":form.vertex_coordinates(v,"xy"),"width":1.0,"color":"#cccccc","style":"--",})force_lines=[]foru,vinforce.edges():force_lines.append({"start":force.vertex_coordinates(u,"xy"),"end":force.vertex_coordinates(v,"xy"),"width":1.0,"color":"#cccccc","style":"--",})# ==============================================================================# Change the position of the "free" node of the force diagram# ==============================================================================force.vertex[4]["x"]-=8.0# ==============================================================================# Update the form diagram accordingly.# ==============================================================================graphstatics.form_update_from_force(form,force,kmax=100)# ==============================================================================# Indicate the movement of the free node in the force diagram with an arrow.# ==============================================================================force_lines.append({"start":force_key_xyz[4],"end":force.vertex_coordinates(4),"color":"#ff0000","width":10.0,"style":"-",})# ==============================================================================# Visualize the result.# ==============================================================================viewer=Viewer(form,force,delay_setup=False,figsize=(12,7.5))viewer.draw_form(lines=form_lines,forces_on=False,vertexlabel={key:keyforkeyinform.vertices()},vertexsize=0.2,vertexcolor={key:"#000000"forkeyinfixed},edgelabel={key:indexforindex,keyinenumerate(form.edges())},)viewer.draw_force(lines=force_lines,vertexlabel={key:keyforkeyinforce.vertices()},vertexsize=0.2)viewer.show()