def data(self, data): points = [[Point.from_data(point) for point in row] for row in data['points']] weights = data['weights'] u_knots = data['u_knots'] v_knots = data['v_knots'] u_mults = data['u_mults'] v_mults = data['v_mults'] u_degree = data['u_degree'] v_degree = data['v_degree'] is_u_periodic = data['is_u_periodic'] is_v_periodic = data['is_v_periodic'] self.rhino_surface = NurbsSurface.from_parameters( points, weights, u_knots, v_knots, u_mults, v_mults, u_degree, v_degree, is_u_periodic, is_v_periodic)
def to_compas(self): """Convert the surface to a COMPAS surface. Returns ------- :class:`compas_rhino.geometry.RhinoNurbsSurface` Raises ------ :class:`ConversionError` If the surface BRep contains more than one face. """ from compas.geometry import NurbsSurface brep = Rhino.Geometry.Brep.TryConvertBrep(self.geometry) surface = NurbsSurface() if brep.Surfaces.Count > 1: raise ConversionError( 'Conversion of a BRep with multiple underlying surface is currently not supported.' ) for geometry in brep.Surfaces: surface.rhino_surface = geometry break return surface
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 # ============================================================================== Artist.clear() for row in surface.points: Artist(Polyline(row)).draw() for col in zip(*list(surface.points)): Artist(Polyline(col)).draw() Artist(surface).draw()
Point(3, 0, 0)], [Point(0, 1, 0), Point(1, 1, 2), Point(2, 1, 2), Point(3, 1, 0)], [Point(0, 2, 0), 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) # ============================================================================== # JSON Data # ============================================================================== string = surface.to_jsonstring(pretty=True) print(string) other = NurbsSurface.from_jsonstring(string) # print(surface == other) # ============================================================================== # Visualisation
from compas.geometry import Polyline from compas_view2.app import App points1 = [ Point(0, -10, 0), Point(1, -8, 0), Point(-1, -6, 0), Point(0, -4, 0) ] points2 = [Point(5, -10, 0), Point(4, -8, 0), Point(6, -6, 0), Point(5, -4, 0)] nurbscurve1 = NurbsCurve.from_interpolation(points1) nurbscurve2 = NurbsCurve.from_interpolation(points2) nurbssurface_2curves = NurbsSurface.from_fill(nurbscurve1, nurbscurve2) points3 = [Point(0, 0, 0), Point(1, 2, 0), Point(-1, 4, 0), Point(0, 6, 0)] points4 = [Point(0, 6, 0), Point(3, 6, -1), Point(5, 6, 0)] points5 = [Point(5, 6, 0), Point(4, 2, 0), Point(5, 0, 0)] points6 = [Point(5, 0, 0), Point(2, -1, 1), Point(0, 0, 0)] nurbscurve3 = NurbsCurve.from_interpolation(points3) nurbscurve4 = NurbsCurve.from_interpolation(points4) nurbscurve5 = NurbsCurve.from_interpolation(points5) nurbscurve6 = NurbsCurve.from_interpolation(points6) nurbssurface_4curves = NurbsSurface.from_fill(nurbscurve3, nurbscurve4, nurbscurve5, nurbscurve6,
import random from compas.geometry import Polyline from compas.geometry import NurbsSurface from compas.artists import Artist U = 10 V = 20 surface = NurbsSurface.from_meshgrid(nu=U, nv=V) # ============================================================================== # Update # ============================================================================== for u in range(1, U): for v in range(1, V): point = surface.points[u, v] point.z = random.choice([+1, -1]) * random.random() surface.points[u, v] = point # ============================================================================== # Visualisation # ============================================================================== Artist.clear() for row in surface.points: Artist(Polyline(row)).draw() for col in zip(* list(surface.points)):
weights = [ [1.0, 1.0, 1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0, 1.0, 1.0], ] surface = NurbsSurface.from_parameters( points=points, weights=weights, u_knots=[ 1.0, 1 + 1 / 9, 1 + 2 / 9, 1 + 3 / 9, 1 + 4 / 9, 1 + 5 / 9, 1 + 6 / 9, 1 + 7 / 9, 1 + 8 / 9, 2.0 ], v_knots=[0.0, 1 / 9, 2 / 9, 3 / 9, 4 / 9, 5 / 9, 6 / 9, 7 / 9, 8 / 9, 1.0], u_mults=[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], v_mults=[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], u_degree=3, v_degree=3, ) # ============================================================================== # Visualisation # ============================================================================== Artist.clear() for row in surface.points: Artist(Polyline(row)).draw()