def draw_forces(self, scale=None, color=None): self.clear_forces() lines = [] color = color or self.form.attributes['color.force'] scale = scale or self.form.attributes['scale.force'] tol = self.form.attributes['tol.force'] tol2 = tol**2 for u, v, attr in self.form.edges_where( { 'is_edge': True, 'is_external': False }, True): sp, ep = self.form.edge_coordinates(u, v) radius = scale * attr['f'] if radius**2 < tol2: continue lines.append({ 'start': sp, 'end': ep, 'radius': radius, 'color': color, 'name': "{}.force.{}-{}".format(self.form.name, u, v) }) compas_rhino.xdraw_cylinders(lines, layer=self.layer, clear=False, redraw=False)
def network_draw_axial_forces(network, scale=0.1, layer=None, clear_layer=False): cylinders = [] for u, v, attr in network.edges(True): if attr['f'] > 0.0: cylinders.append({ 'start' : network.vertex_coordinates(u), 'end' : network.vertex_coordinates(v), 'radius': scale * 3.14159 * attr['f'] ** 2, 'name' : '{}.axial.{}-{}'.format(network.name, u, v), 'color' : (255, 0, 0), }) guids = compas_rhino.get_objects(name='{}.axial.*'.format(network.name)) compas_rhino.delete_objects(guids) compas_rhino.xdraw_cylinders(cylinders, layer=layer, clear=clear_layer)
def _draw_cylinders(self, cylinders): compas_rhino.xdraw_cylinders(cylinders, layer=self.cablenet.layer, clear=False, redraw=True, cap=True)
def display_network_axial_forces(network, display=True, layer=None, clear_layer=False, scale=1.0, attr_name='f', color_tension=(255, 0, 0), color_compression=(0, 0, 255)): """Display the axial forces in the edges of a network. Parameters: network (compas.datastructures.network.Network): The network object. display (bool): Optional. If ``True``, display the axial forces. If ``False``, don't display the axial forces. Default is ``True``. layer (str): Optional. The layer to draw in. Default is ``None``. clear_layer (bool): Optional. Flag for clearing the layer. Default is ``False``. scale (float): Optional. The scale of the forces. Default is ``1.0``. attr_name (str): Optional. The name of the edge attribute storing the force value. Default is ``'f'``. color_tension (tuple): Optional. The color to use for tension forces. Default is ``(255, 0, 0)``. color_compression (tuple): Optional. The color to use for compression forces. Default is ``(0, 0, 255)``. Example: .. code-block:: python import random import compas import compas_rhino as compas_rhino from compas.datastructures.network import Network network = Network.from_obj(compas.get_data('lines.obj')) for u, v, attr in network.edges(True): attr['f'] = random.choice([-1.0, 1.0]) * random.randint(1, 10) compas_compas_rhino.display_network_axial_forces(network) See Also: * :func:`display_network_reaction_forces` * :func:`display_network_residual_forces` * :func:`display_network_selfweight` """ tol = compas_rhino.get_tolerance() objects = compas_rhino.get_objects(name='{0}.force:axial.*'.format(network.attributes['name'])) compas_rhino.delete_objects(objects) if not display: return lines = [] for u, v, attr in network.edges(True): start = network.vertex_coordinates(u) end = network.vertex_coordinates(v) force = attr['f'] color = color_tension if force > 0.0 else color_compression radius = scale * ((force ** 2) ** 0.5 / 3.14159) ** 0.5 name = '{0}.force:axial.{1}-{2}'.format(network.attributes['name'], u, v) if radius < tol: continue lines.append({ 'start' : start, 'end' : end, 'name' : name, 'color' : color, 'radius': radius, }) compas_rhino.xdraw_cylinders(lines, layer=layer, clear=clear_layer)