def show_angles(self): angles = self.form.get_edges_attribute('a') amin = min(angles) amax = max(angles) adif = amax - amin text = {} color = {} for u, v, attr in self.form.edges_where({'is_edge': True}, True): a = attr['a'] if a > 5: text[u, v] = "{:.1f}".format(a) color[u, v] = i_to_green((a - amin) / adif) artist = FormArtist(self.form, layer=self.settings['form.layer']) artist.clear_edgelabels() artist.draw_edgelabels(text=text, color=color) artist.redraw()
def draw(self, layer=None, clear_layer=True, settings=None): """Draw the form diagram in Rhino. Parameters ---------- layer : str, optional The layer in which the drawing should be contained. clear_layer : bool, optional Clear the layer if ``True``. Default is ``True``. settings : dict, optional A dictionary of settings overwriting the default settings of the artist. """ from compas_tna.rhino import FormArtist artist = FormArtist(self, layer=layer, settings=settings) if clear_layer: artist.clear_layer() artist.draw()
import compas import compas_rhino import compas_tna compas_tna.TEMP = os.path.join(os.path.dirname(__file__), 'tmp') from compas.utilities import i_to_green from compas_tna.diagrams import FormDiagram from compas_tna.diagrams import ForceDiagram from compas_tna.rhino import FormArtist # create diagrams from serialised files form = FormDiagram.from_json('aag_08_final_formdiagram.json') force = ForceDiagram.from_json('aag_08_final_forcediagram.json') # draw the result form.draw(layer='AAG::FormDiagram') force.draw(layer='AAG::ForceDiagram') artist = FormArtist(form, layer='AAG::FormDiagram') artist.clear_reactions() artist.draw_reactions(scale=0.25) artist.draw_forces(scale=0.01) artist.redraw()
def hide_angles(self): artist = FormArtist(self.form, layer=self.settings['form.layer']) artist.clear_edgelabels() artist.redraw()
def hide_reactions(self): artist = FormArtist(self.form, layer=self.settings['form.layer']) artist.clear_reactions() artist.redraw()
def show_forces(self): artist = FormArtist(self.form, layer=self.settings['form.layer']) artist.clear_forces() artist.draw_forces() artist.redraw()
interior = boundaries[1:] form.set_vertices_attribute('is_anchor', True, keys=exterior) form.update_exterior(exterior, feet=1) form.update_interior(interior) # create the force diagram force = ForceDiagram.from_formdiagram(form) # compute equilibrium horizontal(form, force, kmax=20, display=True) vertical_from_formforce(form, force, density=form.init_scale(), kmax=100) # visualise result artist = FormArtist(form, layer='FormDiagram') artist.clear_layer() artist.draw_vertices(keys=list(form.vertices_where({'is_external': False}))) artist.draw_edges(keys=list(form.edges_where({'is_edge': True, 'is_external': False}))) artist.draw_faces(fkeys=list(form.faces_where({'is_loaded': True})), join_faces=True) artist.draw_reactions(scale=1.0) artist.draw_forces(scale=0.05) artist.redraw()
form.draw(layer='AAG::FormDiagram') force.draw(layer='AAG::ForceDiagram') # visualise angle deviations angles = form.get_edges_attribute('a') amin = min(angles) amax = max(angles) adif = amax - amin text = {} color = {} for u, v, attr in form.edges_where({'is_edge': True}, True): a = attr['a'] if a > 5: text[u, v] = "{:.1f}".format(a) color[u, v] = i_to_green((a - amin) / adif) artist = FormArtist(form, layer='AAG::FormDiagram') artist.clear_edgelabels() artist.draw_edgelabels(text=text, color=color) artist.redraw() # serialise the result form.to_json('aag_04_horizontal_formdiagram.json') force.to_json('aag_04_horizontal_forcediagram.json')
form = FormDiagram.from_obj(compas.get('lines.obj')) form.set_vertices_attributes(('is_fixed', 'is_anchor'), (True, True), keys=form.vertices_on_boundary()) form.set_edges_attribute('is_edge', False, keys=form.edges_on_boundary()) k, m, ind = identify_dof(form) for u, v in ind: form.set_edge_attributes((u, v), ('is_ind', 'q'), (True, random.choice(range(1, 5)))) vertical_from_qind(form) artist = FormArtist(form, layer='FormDiagram') artist.clear_layer() artist.draw_vertices( color={key: '#ff0000' for key in form.vertices_where({'is_anchor': True})}) artist.draw_edges( keys=list(form.edges_where({'is_edge': True})), color={(u, v): '#00ff00' for u, v in form.edges_where({'is_ind': True})}) artist.draw_edgelabels( text={(u, v): index for index, (u, v, attr) in enumerate(form.edges_where({'is_edge': True}, True)) if attr['is_ind']}) artist.draw_faces() artist.draw_forces(scale=0.01) artist.draw_reactions(scale=0.1)
def draw(self, layer=None, clear_layer=True, settings=None): from compas_tna.rhino import FormArtist artist = FormArtist(self, layer=layer) if clear_layer: artist.clear_layer() if not settings: settings = {} if settings.get('show.vertices', True): vertexcolor = {} vertexcolor.update({ key: '#00ff00' for key in self.vertices_where({'is_fixed': True}) }) vertexcolor.update({ key: '#0000ff' for key in self.vertices_where({'is_external': True}) }) vertexcolor.update({ key: '#ff0000' for key in self.vertices_where({'is_anchor': True}) }) artist.draw_vertices(color=vertexcolor) if settings.get('show.edges', True): artist.draw_edges(keys=list(self.edges_where({'is_edge': True}))) if settings.get('show.faces', True): artist.draw_faces(keys=list(self.faces_where({'is_loaded': True}))) if settings.get('show.forces', False): artist.draw_forces(scale=settings.get('scale.forces', 0.1)) if settings.get('show.reactions', False): artist.draw_reactions(scale=settings.get('scale.reactions', 0.01)) artist.redraw()
def draw(self, layer=None, clear_layer=True): from compas_tna.rhino import FormArtist artist = FormArtist(self, layer=layer) if clear_layer: artist.clear_layer() vertexcolor = {} vertexcolor.update({ key: '#00ff00' for key in self.vertices_where({'is_fixed': True}) }) vertexcolor.update({ key: '#0000ff' for key in self.vertices_where({'is_external': True}) }) vertexcolor.update({ key: '#ff0000' for key in self.vertices_where({'is_anchor': True}) }) artist.draw_vertices(color=vertexcolor) artist.draw_edges(keys=list(self.edges_where({'is_edge': True}))) artist.draw_faces(keys=list(self.faces_where({'is_loaded': True}))) artist.redraw()