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() Artist.redraw()
from compas.geometry import Point from compas.geometry import Line from compas.geometry import NurbsCurve from compas.artists import Artist from compas.colors import Color line = Line(Point(0, 0, 0), Point(3, 3, 0)) curve = NurbsCurve.from_line(line) # ============================================================================== # Visualisation # ============================================================================== Artist.clear() Artist(curve).draw(color=Color.green()) for point in curve.points: Artist(point).draw() Artist.redraw()
from compas.geometry import Point from compas.geometry import Polyline from compas.geometry import NurbsCurve from compas.artists import Artist from compas.colors import Color points = [Point(0, 0, 0), Point(3, 6, 0), Point(6, -3, 3), Point(10, 0, 0)] curve = NurbsCurve.from_points(points) # ============================================================================== # Visualisation # ============================================================================== Artist.clear() Artist(curve).draw(color=Color.green()) Artist(Polyline(curve.points)).draw(show_points=True) Artist.redraw()
# curve6 = NurbsCurve.from_parameters( # points=points, # weights=[1.0, 1.0, 1.0, 1.0], # knots=[0.0, 0.5, 1.0], # multiplicities=[3, 1, 3], # degree=2 # ) # ============================================================================== # Visualisation # ============================================================================== Artist.clear() Artist(Polyline(bezier.points)).draw() Artist(Polyline(bezier.locus())).draw() Artist(Polyline(curve1.points)).draw(show_points=True) color = Color.red() Artist(curve1).draw(color=color) Artist(curve2).draw(color=color.lightened(factor=20)) Artist(curve3).draw(color=color.lightened(factor=40)) Artist(curve4).draw(color=color.lightened(factor=60)) Artist(curve5).draw(color=color.lightened(factor=80)) # Artist(curve6).draw(color=color.lightened(factor=50)) Artist.redraw()
# ============================================================================== # JSON Data # ============================================================================== string = surface.to_jsonstring(pretty=True) print(string) other = NurbsSurface.from_jsonstring(string) # print(surface == other) # ============================================================================== # Visualisation # ============================================================================== Artist.clear() u = surface.u_isocurve(0.5 * sum(surface.u_domain)) v = surface.v_isocurve(0.5 * sum(surface.v_domain)) Artist(Polyline(u.locus())).draw() Artist(Polyline(v.locus())).draw() # for curve in surface.boundary(): # Artist(Polyline(curve.locus())).draw() Artist(other).draw() Artist.redraw()
degree=2) curve2 = NurbsCurve.from_parameters(points=points, weights=[1.0, 2.0, 1.0], knots=[0.0, 1.0], multiplicities=[3, 3], degree=2) curve3 = NurbsCurve.from_parameters(points=points, weights=[1.0, 1.0, 1.0], knots=[0.0, 1.0, 2.0, 3.0, 4.0, 5.0], multiplicities=[1, 1, 1, 1, 1, 1], degree=2) # ============================================================================== # Visualisation # ============================================================================== Artist.clear() Artist(Polyline(bezier.points)).draw() Artist(Polyline(bezier.locus())).draw(show_points=True) Artist(Polyline(curve1.points)).draw(show_points=True) Artist(curve1).draw(color=Color.black()) Artist(curve2).draw(color=Color.pink()) Artist(curve3).draw(color=Color.azure()) Artist.redraw()
head_link = model.add_link('head', visual_meshes=[head, beak]) neck_joint_origin = Frame([0, 0, 4], [1, 0, 0], [0, 1, 0]) model.add_joint('neck_joint', Joint.FIXED, torso_link, head_link, origin=neck_joint_origin) tail = Sphere([0, 0, 0], 1) tail_link = model.add_link('tail', visual_meshes=[tail]) tail_joint_origin = Frame([0, 0, -4], [1, 0, 0], [0, 1, 0]) model.add_joint('tail_joint', Joint.FIXED, torso_link, tail_link, origin=tail_joint_origin) hat = Cylinder(Circle(Plane([0, 0, 0], [0, 0, 1]), .8), 1.5) brim = Cylinder(Circle(Plane([0, 0, -1.5 / 2], [0, 0, 1]), 1.4), .1) hat_link = model.add_link('hat', visual_meshes=[hat, brim]) hat_joint_origin = Frame([0, 0, 1 - .3 + 1.5 / 2], [1, 0, 0], [0, 1, 0]) model.add_joint('hat_joint', Joint.FIXED, head_link, hat_link, origin=hat_joint_origin) artist = Artist(model, layer='COMPAS::Example Robot') artist.clear_layer() artist.draw_visual()
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()
from compas.geometry import Point from compas.geometry import NurbsCurve from compas.artists import Artist from compas.colors import Color points = [Point(0, 0, 0), Point(3, 0, 2), Point(6, 0, -3), Point(8, 0, 0)] curve = NurbsCurve.from_interpolation(points) projection_point = Point(2, -1, 0) closest_point, t = curve.closest_point(projection_point, return_parameter=True) print(curve.point_at(t) == closest_point) # ============================================================================== # Visualisation # ============================================================================== Artist.clear() Artist(curve, color=Color.from_hex('#0092D2')).draw() Artist(projection_point).draw() Artist(closest_point).draw() Artist.redraw()
[Point(0, 3, 0), Point(1, 3, 0), Point(2, 3, 0), Point(3, 3, 0), Point(4, 3, 0)], ] surface = NurbsSurface.from_points(points=points) # ============================================================================== # Isocurves # ============================================================================== u_curves = [] for u in surface.u_space(): u_curves.append(surface.u_isocurve(u)) v_curves = [] for v in surface.v_space(): v_curves.append(surface.v_isocurve(v)) # ============================================================================== # Visualisation # ============================================================================== Artist.clear() for curve in u_curves: Artist(Polyline(curve.locus())).draw() for curve in v_curves: Artist(Polyline(curve.locus())).draw() Artist.redraw()