def color_interfaces(self, mode=0): """""" if mode == 0: return if mode == 1: color_compression = self.settings['color.force:compression'] color_tension = self.settings['color.force:tension'] resultants = [] for key in self.assembly.edges(): forces = self.assembly.edge_attribute(key, 'interface_forces') if not forces: resultants.append(0) continue R = 0 for force in forces: c = force['c_np'] t = force['c_nn'] f = c - t R += f resultants.append(R) Rmax = max(resultants) Rmin = min(resultants) print(Rmax) print(Rmin) for index, key in enumerate(self.assembly.edges()): u, v = key name = "{}.interface.{}-{}".format(self.assembly.name, u, v) guids = compas_rhino.get_objects(name=name) if not guids: continue guid = guids[0] R = resultants[index] color = i_to_blue((R - Rmin) / (Rmax - Rmin)) compas_rhino.rs.ObjectColor(guid, color)
def get_force_colors_uv(volmesh, network, gradient=False, tol=0.001): """Returns a dictionary of (u,v)-color pairs. Blue means compression, and red means tension. """ c_dict = {} f_dict = get_force_mags(volmesh, network) f_range = sorted(f_dict.values()) c_forces = [x for x in f_range if x < 0] t_forces = [x for x in f_range if x > 0] for edge in f_dict: force = f_dict[edge] if force < 0: # if compression color = (0, 0, 255) if gradient: min_c = abs(c_forces[-1]) max_c = abs(c_forces[0]) color = i_to_blue((abs(force) - min_c) / (max_c - min_c)) if force > 0: # if tension color = (255, 0, 0) if gradient: min_t = t_forces[0] max_t = t_forces[-1] color = i_to_red((force - min_t) / (max_t - min_t)) if force == 0 or force < tol: # if close to zero color = (255, 255, 255) c_dict[edge] = color return c_dict
def callback(cell, args): current_area = cell.face_area(fkey) color = i_to_blue(abs(current_area - target_area) / target_area) conduit.face_colordict = {fkey: color} time.sleep(0.05) conduit.redraw()
# mesh = Mesh.from_obj(compas.get('faces.obj')) # mesh_quads_to_triangles(mesh) # mesh = Mesh.from_polyhedron(12) # mesh_quads_to_triangles(mesh) index_key = mesh.index_key() sources = [0] d = mesh_geodesic_distances(mesh, sources, m=1.0).tolist() dmin = min(d) dmax = max(d) drange = dmax - dmin plotter = MeshPlotter(mesh, figsize=(10, 7)) facecolor = {key: i_to_blue(1 - (d[i] - dmin) / drange) for i, key in enumerate(mesh.vertices())} for i in sources: facecolor[index_key[i]] = '#ff0000' plotter.draw_vertices( facecolor=facecolor, radius=0.05 ) # plotter.draw_edges() plotter.draw_faces() plotter.show()
arrows = [{ 'start': cablenet.vertex_coordinates(start[0]), 'end': cablenet.vertex_coordinates(start[1]), 'color': (1.0, 0.0, 0.0) }] for u, v in parallel: if u not in start and v not in start: arrows.append({ 'start': cablenet.vertex_coordinates(u), 'end': cablenet.vertex_coordinates(v), 'color': (0.0, 0.0, 0.0) }) facecolor = { key: i_to_blue(index / len(faces)) for index, key in enumerate(faces) } plotter = MeshPlotter(cablenet, figsize=(10, 7)) plotter.defaults['vertex.radius'] = 0.04 plotter.defaults['edge.width'] = 0.5 plotter.draw_edges(width={key: 3.0 for edges in cables for key in edges}) plotter.draw_vertices(radius={key: 0.06 for key in chain}, facecolor=vertexcolor) plotter.draw_arrows2(arrows) plotter.draw_faces(facecolor=facecolor, keys=faces, text={key: str(index) for index, key in enumerate(faces)})
attr['y'] = y attr['z'] = z # mesh = Mesh.from_obj(compas.get('faces.obj')) # mesh_quads_to_triangles(mesh) # mesh = Mesh.from_polyhedron(12) # mesh_quads_to_triangles(mesh) index_key = mesh.index_key() sources = [0] d = mesh_geodesic_distances(mesh, sources, m=1.0).tolist() dmin = min(d) dmax = max(d) drange = dmax - dmin facecolor = { key: i_to_blue(1 - (d[i] - dmin) / drange) for i, key in enumerate(mesh.vertices()) } for i in sources: facecolor[index_key[i]] = '#ff0000' plotter = MeshPlotter(mesh, figsize=(6, 4)) plotter.draw_vertices(facecolor=facecolor, radius=0.5) plotter.draw_faces() plotter.show()
def color_interfaces(self, mode=0): """Color the interfaces with shades of blue and red according to the forces at the corners. Parameters ---------- mode : int, optional Mode to switch between normal forces(0) and frictions(1) Default is 0. Notes ----- * Currently only normal forces are taken into account. * Gradients should go from blue to red over white. * White marks the neutral line (the axis of rotational equilibrium). * ... Examples -------- .. code-block:: python pass """ if mode == 0: # redraw the faces with a discretisation that makes sense for the neutral axis # color the drawn meshes for u, v, attr in self.assembly.edges(True): if not attr['interface_forces']: continue name = "{}.interface.{}-{}".format(self.assembly.name, u, v) guids = compas_rhino.get_objects(name=name) if not guids: continue guid = guids[0] forces = [ f['c_np'] - f['c_nn'] for f in attr['interface_forces'] ] fmin = min(forces) fmax = max(forces) fmax = max(abs(fmin), fmax) colors = [] p = len(attr['interface_points']) for i in range(p): f = forces[i] if f > 0.0: color = i_to_blue(f / fmax) elif f < 0.0: color = i_to_red(-f / fmax) else: color = (255, 255, 255) colors.append(color) # this is obviously not correct # just a visual reminder if p > 4: colors.append((255, 255, 255)) compas_rhino.set_mesh_vertex_colors(guid, colors) elif mode == 1: for u, v, attr in self.assembly.edges(True): if attr['interface_forces'] is None: continue name = "{}.interface.{}-{}".format(self.assembly.name, u, v) guids = compas_rhino.get_objects(name=name) if not guids: continue guid = guids[0] iu, iv = attr['interface_uvw'][0], attr['interface_uvw'][1] forces = [ length_vector( add_vectors(scale_vector(iu, f['c_u']), scale_vector(iv, f['c_v']))) for f in attr['interface_forces'] ] fmin = min(forces) fmax = max(forces) fmax = max(abs(fmin), fmax) fmax = max(fmax, self.defaults['range.friction']) colors = [] p = len(attr['interface_points']) for i in range(p): f = forces[i] if f > 0.0: color = i_to_red(f / fmax) else: color = (255, 255, 255) colors.append(color) # this is obviously not correct # just a visual reminder if p > 4: colors.append((255, 255, 255)) compas_rhino.set_mesh_vertex_colors(guid, colors) else: print("please choose mode 0 or 1")