def from_meshgrid(cls, nu=10, nv=10): """Construct a NURBS surface from a mesh grid. Parameters ---------- nu : int, optional Number of control points in the U direction. nv : int, optional Number of control points in the V direction. Returns ------- :class:`compas.geometry.NurbsSurface` """ UU, VV = meshgrid(linspace(0, nu, nu + 1), linspace(0, nv, nv + 1)) points = [] for U, V in zip(UU, VV): row = [] for u, v in zip(U, V): row.append(Point(u, v, 0.0)) points.append(row) return cls.from_points(points=points)
from compas.geometry import Point from compas.geometry import Polyline from compas.utilities import meshgrid, linspace from compas.geometry import NurbsSurface from compas.artists import Artist UU, VV = meshgrid(linspace(0, 8, 9), linspace(0, 5, 6)) Z = 0.5 points = [] for i, (U, V) in enumerate(zip(UU, VV)): row = [] for j, (u, v) in enumerate(zip(U, V)): if i == 0 or i == 5 or j == 0 or j == 8: z = 0.0 elif i < 2 or i > 3: z = -1.0 else: if j < 2 or j > 6: z = -1.0 else: z = Z row.append(Point(u, v, z)) points.append(row) surface = NurbsSurface.from_points(points=points) # ============================================================================== # Visualisation # ==============================================================================
from itertools import combinations from compas.datastructures import Network from compas.utilities import linspace, meshgrid from compas_rhino.artists import NetworkArtist X, Y = meshgrid(linspace(0, 10, 10), linspace(0, 5, 5)) points = [] for z in linspace(0, 3, 3): for xs, ys in zip(X, Y): for x, y in zip(xs, ys): points.append([x, y, z]) network = Network() for point in points: network.add_node(x=point[0], y=point[1], z=point[2]) for a, b in combinations(network.nodes(), 2): if network.node_attribute(a, 'z') != network.node_attribute(b, 'z'): network.add_edge(a, b) artist = NetworkArtist(network, layer="ITA20::Network") artist.clear_layer() artist.draw_nodes() artist.draw_edges()
points1.append(Point(-6, 3, 1)) points1.append(Point(-4, 3, -1)) points1.append(Point(-3, 5, -2)) spline1 = BSplineCurve.from_points(points1) points2 = [] points2.append(Point(-4, 0, 2)) points2.append(Point(-2, 2, 0)) points2.append(Point(2, 3, -1)) points2.append(Point(3, 7, -2)) points2.append(Point(4, 9, -1)) spline2 = BSplineCurve.from_points(points2) surface = BSplineSurface.from_fill(spline1, spline2) U, V = meshgrid(surface.uspace(30), surface.vspace(20), 'ij') frames = [surface.frame_at(u, v) for u, v in zip(flatten(U[1:]), flatten(V))] # ============================================================================== # Viz # ============================================================================== mesh = surface.to_vizmesh() boundary = Polyline( mesh.vertices_attributes('xyz', keys=mesh.vertices_on_boundary())) view = App() view.add(mesh) view.add(boundary, linewidth=2)
Point(1, 2, 2), Point(2, 2, 2), Point(3, 2, 0)], [Point(0, 3, 0), Point(1, 3, 0), Point(2, 3, 0), Point(3, 3, 0)], ] surface = NurbsSurface.from_points(points=points) # ============================================================================== # Frames # ============================================================================== U, V = meshgrid(surface.u_space(), surface.v_space(), 'ij') frames = [surface.frame_at(u, v) for u, v in zip(flatten(U), flatten(V))] # ============================================================================== # Visualisation # ============================================================================== Artist.clear() Artist(surface).draw() for frame in frames: Artist(frame).draw() Artist.redraw()