def draw_forces(self, color=(255, 0, 0), scale=0.1, tol=0.001): for edge in self.network.edges(): f = self.network.edge_attribute(edge, 'f') l = self.network.edge_length(*edge) # noqa E741 radius = scale * f if radius < tol: continue mp = self.network.edge_midpoint(*edge) direction = self.network.edge_direction(*edge) cylinder = Cylinder(((mp, direction), radius), l) artist = CylinderArtist(cylinder, layer=self.layer, color=color) artist.draw(u=16)
cylinder = Cylinder(circle, 0.7 * height) circle = [[0, 0, 0.7 * height], [0, 0, 1]], 0.1 cone = Cone(circle, 0.3 * height) for node in network.nodes(): a = network.node_attributes(node, 'xyz') for nbr in network.neighbors(node): edge = node, nbr if not network.has_edge(*edge): edge = nbr, node b = network.node_attributes(nbr, 'xyz') force = network.edge_attribute(edge, 'f') direction = normalize_vector(subtract_vectors(b, a)) frame = Frame.from_plane([a, direction]) X = Transformation.from_frame_to_frame(world, frame) S = Scale.from_factors([force, 1, 1]) X = X * S shaft = cylinder.transformed(X) tip = cone.transformed(X) artist = CylinderArtist(shaft, layer=layer, color=(255, 0, 0)) artist.draw(u=16) artist = ConeArtist(tip, layer=layer, color=(255, 0, 0)) artist.draw(u=16)
for frame in frames: artist = FrameArtist(frame, scale=0.3, layer="Frames::{}".format(frame.name)) artist.clear_layer() artist.draw() for a, b in pairwise(frames): line = Line(a.point, b.point) artist = LineArtist(line, layer="Links::{}".format(a.name)) artist.draw() tpl = Cylinder(Circle(Plane(Point(0, 0, 0), Vector(0, 0, 1)), 0.05), 0.2) for frame, axis in zip(frames, axes): point = frame.point normal = Vector(axis.x, axis.y, axis.z) plane = Plane(point, normal) frame = Frame.from_plane(plane) X = Transformation.from_frame(frame) cylinder = tpl.transformed(X) artist = CylinderArtist(cylinder, layer="Axes::{}".format(axis.name)) artist.clear_layer() artist.draw() artist = RobotModelArtist(robot, layer="Robot") artist.clear_layer() artist.update(state, collision=False) artist.draw() compas_rhino.wait()
mesh = Mesh.from_off(compas.get('tubemesh.off')) start = random.choice(list(mesh.edges())) loop = mesh.edge_loop(start) strip = [mesh.edge_faces(*edge) for edge in mesh.edge_strip(start)] strip[:] = list(set(flatten(strip))) edgecolor = {} for edge in loop: edgecolor[edge] = (0, 255, 0) edgecolor[start] = (255, 0, 0) facecolor = {} for face in strip: facecolor[face] = (255, 200, 200) artist = MeshArtist(mesh, layer='Tubemesh') artist.clear_layer() artist.draw_faces(color=facecolor) # artist.draw_edges(color=edgecolor) for edge in edgecolor: o = mesh.edge_midpoint(*edge) n = mesh.edge_direction(*edge) h = mesh.edge_length(*edge) cylinder = Cylinder([(o, n), 0.02], h) artist = CylinderArtist(cylinder, color=(0, 255, 0), layer='Tubemesh') artist.draw(show_vertices=False)
start = random.choice(list(mesh.edges())) loop = mesh.edge_loop(start) strip = [mesh.edge_faces(*edge) for edge in mesh.edge_strip(start)] strip[:] = list(set(flatten(strip))) edgecolor = {} for edge in loop: edgecolor[edge] = (0, 255, 0) edgecolor[start] = (255, 0, 0) facecolor = {} for face in strip: facecolor[face] = (255, 200, 200) artist = MeshArtist(mesh, layer="ITA20::Tubemesh") artist.clear_layer() artist.draw_faces(color=facecolor) # artist.draw_edges(color=edgecolor) for edge in edgecolor: o = mesh.edge_midpoint(*edge) n = mesh.edge_direction(*edge) h = mesh.edge_length(*edge) cylinder = Cylinder([(o, n), 0.02], h) artist = CylinderArtist(cylinder, color=(0, 255, 0), layer="ITA20::Tubemesh") artist.draw(show_vertices=False)
for node in network.nodes(): point = network.node_coordinates(node) for nbr in tree.nearest_neighbors(point, 4, distance_sort=True): if nbr[2] < 1e-6: continue if not network.has_edge(node, nbr[1], directed=False): network.add_edge(node, nbr[1]) start = network.get_any_node() goal = network.get_any_node() path = network.shortest_path(start, goal) edges = [(u, v) if network.has_edge(u, v) else (v, u) for u, v in pairwise(path)] artist = NetworkArtist(network, layer="ITA20::Network") artist.clear_layer() artist.draw_nodes(color={start: (255, 0, 0), goal: (0, 0, 255)}) artist.draw_edges(color={edge: (0, 255, 0) for edge in edges}) for u, v in edges: o = network.edge_midpoint(u, v) n = network.edge_direction(u, v) h = network.edge_length(u, v) cylinder = Cylinder([(o, n), 0.02], h) artist = CylinderArtist(cylinder, color=(0, 255, 0), layer="ITA20::Network") artist.draw(show_vertices=False)
from compas.geometry import Frame from compas.geometry import Plane from compas.geometry import Sphere # Box b1 = Box(Frame.worldXY(), 10, 1, 4) # xsize, ysize, zsize b2 = Box.from_width_height_depth(10, 4, 1) # width=xsize, height=zsize, depth=ysize assert str(b1) == str(b2) print(b1) # Sphere s1 = Sphere([10, 0, 0], 4) print(s1) # Cylinder plane = Plane([20, 0, 0], [0, 0, 1]) circle = Circle(plane, 5) c1 = Cylinder(circle, height=4) print(c1) # Draw! artist = BoxArtist(b1, layer='shapes') artist.draw() artist = SphereArtist(s1, layer='shapes') artist.draw() artist = CylinderArtist(c1, layer='shapes') artist.draw()