def letter_o(): outer = curve2d.full_circle(radius=10.0) operations.translate(outer, (2, 0), inplace=True) inner = curve2d.full_circle(radius=8.0) operations.translate(inner, (2, 0), inplace=True) letter = Multi.MultiCurve() letter.add([outer, inner]) return letter
def letter_i(): base = NURBS.Curve() base.degree = 3 base.ctrlptsw = [[1, 20, 1], [0, 10, 0.5], [0, 19, 1], [0, 10, 1], [0, 1, 1], [0, 0, 0.5], [1, 0, 1], [1, 0, 0.5], [2, 1, 1], [2, 10, 1], [2, 19, 1], [1, 10, 0.5], [1, 20, 1]] base.knotvector = utilities.generate_knot_vector(base.degree, len(base.ctrlpts)) hat = curve2d.full_circle(radius=1) operations.translate(hat, (1, 22), inplace=True) letter = Multi.MultiCurve() letter.add([base, hat]) return letter
curve = BSpline.Curve() # Set up the curve curve.degree = 3 curve.ctrlpts = exchange.import_txt("ex_curve02.cpt") # Auto-generate knot vector curve.knotvector = utilities.generate_knot_vector(curve.degree, len(curve.ctrlpts)) # Split the curve curve1, curve2 = operations.split_curve(curve, 0.2) # Move the 1st curve a little bit far away from the 2nd curve c2tan = curve2.tangent(0.0, normalize=True) c2tanvec = [-1 * p for p in c2tan[1]] operations.translate(curve1, c2tanvec, inplace=True) # Plot the curves using the curve container curves = multi.CurveContainer() curves.sample_size = 40 curves.add(curve1) curves.add(curve2) vis_comp = VisMPL.VisCurve2D() curves.vis = vis_comp curves.render() # Good to have something here to put a breakpoint pass
# Create a B-Spline curve instance curve = BSpline.Curve() # Set degree curve.degree = 1 # Set control points curve.ctrlpts = [[1.1, 1.1], [0.24, 1.1], [0.24, 1.1], [0.24, 0.49], [0.24, 0.49], [1.1, 0.49], [1.1, 0.49], [1.1, 1.1]] # Auto-generate knot vector curve.knotvector = knotvector.generate(curve.degree, curve.ctrlpts_size) # Translate original curve to generate 1st trim curve trim_curve1 = operations.translate(curve, (0.25, 0.25)) # Translate original curve to generate 2nd trim curve trim_curve2 = operations.translate(curve, (-0.75, -0.75)) # Generate a NURBS full circle from 9 control points circle = curve2d.full_circle(radius=0.15) # Translate circle operations.translate(circle, (0.5, 0.5), inplace=True) # Set evaluation deltas trim_curve1.delta = 0.01 trim_curve2.delta = 0.01 circle.delta = 0.01
# Set up the curve curve.degree = 3 curve.ctrlpts = exchange.import_txt("ex_curve02.cpt") # Auto-generate knot vector curve.knotvector = utilities.generate_knot_vector(curve.degree, len(curve.ctrlpts)) # Decompose the curve into Bezier curve segments bezier = operations.decompose_curve(curve) # Move the curves a little bit away from each other (for display purposes only) c2tan1 = bezier[1].tangent(0.0, normalize=True) c2tanvec1 = [-1 * p for p in c2tan1[1]] operations.translate(bezier[0], c2tanvec1, inplace=True) c2tan2 = bezier[1].tangent(1.0, normalize=True) c2tanvec2 = [1 * p for p in c2tan2[1]] operations.translate(bezier[2], c2tanvec2, inplace=True) # Set sample size of the Bezier curves bezier.sample_size = 20 # Plot the Bezier curves vis_comp = VisMPL.VisCurve2D() bezier.vis = vis_comp bezier.render() # Good to have something here to put a breakpoint pass
# Set degrees surf.degree_u = 1 surf.degree_v = 2 # Set control points surf.set_ctrlpts( *exchange.import_txt("ex_cylinder.cptw", two_dimensional=True)) # Set knot vector surf.knotvector_u = [0, 0, 1, 1] surf.knotvector_v = [0, 0, 0, 0.25, 0.25, 0.5, 0.5, 0.75, 0.75, 1, 1, 1] # Decompose the surface surf_list = operations.decompose_surface(surf) surfaces = multi.SurfaceContainer(surf_list) # Translate one of the surface patch operations.translate(surfaces[1], (-0.25, 0.25, 0), inplace=True) # Set number of samples for all split surfaces surfaces.sample_size = 50 # Plot the control point grid and the evaluated surface vis_comp = VisMPL.VisSurfWireframe() surfaces.vis = vis_comp surfaces.render() # Good to have something here to put a breakpoint pass
surf = BSpline.Surface() # Set degrees surf.degree_u = 3 surf.degree_v = 3 # Set control points surf.set_ctrlpts( *exchange.import_txt("ex_surface01.cpt", two_dimensional=True)) # Set knot vectors surf.knotvector_u = [0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 3.0, 3.0, 3.0] surf.knotvector_v = [0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 3.0, 3.0, 3.0] # Split the surface in V-direction surfaces = operations.split_surface_v(surf, t=0.5) # Translate one of the surfaces by a vector operations.translate(surfaces[0], (0, -2.5, 0), inplace=True) # Set number of samples for all split surfaces surfaces.sample_size = 20 # Plot the control point grid and the evaluated surface vis_comp = VisMPL.VisSurface() surfaces.vis = vis_comp surfaces.render() # Good to have something here to put a breakpoint pass
# Fix file path os.chdir(os.path.dirname(os.path.realpath(__file__))) # Create a NURBS curve instance (full circle) curve = NURBS.Curve() # Set up curve curve.degree = 2 curve.ctrlptsw = exchange.import_txt("ex_curve04.cptw") # Use a specialized knot vector curve.knotvector = [0, 0, 0, 0.25, 0.25, 0.5, 0.5, 0.75, 0.75, 1, 1, 1] # Convert to a 3D curve curve3d = operations.add_dimension(curve) # Translate curve to z = 5 operations.translate(curve3d, (0, 0, 5)) # Set evaluation delta curve3d.delta = 0.01 # Plot the control point polygon and the evaluated curve vis_config = VisMPL.VisConfig(ctrlpts=True) vis_comp = VisMPL.VisCurve3D(vis_config) curve3d.vis = vis_comp curve3d.render() # Good to have something here to put a breakpoint pass
surf.degree_u = 3 surf.degree_v = 3 # Set control points surf.set_ctrlpts(*exchange.import_txt("ex_surface01.cpt", two_dimensional=True)) # Set knot vectors surf.knotvector_u = [0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 3.0, 3.0, 3.0] surf.knotvector_v = [0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 3.0, 3.0, 3.0] # Split the surface surface_list1 = operations.split_surface_u(surf, param=0.25) surfaces1 = multi.SurfaceContainer(surface_list1) # Translate one of the split surfaces operations.translate(surfaces1[0], (0, 0, 5), inplace=True) # Split the other split surface surface_list2 = operations.split_surface_v(surfaces1[1], param=0.75) surfaces = multi.SurfaceContainer(surface_list2) surfaces.add(surfaces1[0]) # Set number of samples for all split surfaces surfaces.sample_size = 20 # Plot the control point grid and the evaluated surface vis_comp = VisMPL.VisSurfTriangle() surfaces.vis = vis_comp surfaces.render() # Good to have something here to put a breakpoint
from geomdl_exp import letters from geomdl import operations from geomdl.visualization import VisMPL # Generate letters i = letters.letter_i() o = letters.letter_o() operations.translate(o, [15, 10], inplace=True) # Add letters to a single container cont = i + o cont.delta = 0.005 # Create configuration vis_config = VisMPL.VisConfig(ctrlpts=False, legend=False, axes=False, figure_size=[10, 9]) vis_comp = VisMPL.VisCurve2D(config=vis_config) # Render letters cont.vis = vis_comp cont.render()
from geomdl import knotvector # Fix file path os.chdir(os.path.dirname(os.path.realpath(__file__))) # Create a planar BSpline surface (surface 1) surf1 = BSpline.Surface() surf1.degree = (1, 1) surf1.ctrlpts_size_u = 2 surf1.ctrlpts_size_v = 2 surf1.ctrlpts = ((0, 0, 0), (0, 1, 0), (1, 0, 0), (1, 1, 0)) surf1.knotvector = ((0, 0, 1, 1), (0, 0, 1, 1)) # Create another surface from the initial one (surface 2) surf2 = operations.rotate(surf1, 90, axis=1) operations.translate(surf2, (0.5, 0, 1), inplace=True) # Create another surface from the initial one (surface 3) surf3 = operations.rotate(surf1, 45, axis=0) operations.translate(surf3, (1, 0.25, 0.5), inplace=True) # Create trim curves trim1 = BSpline.Curve() trim1.degree = 1 trim1.ctrlpts = ((1, 0), (0.95, 0.5), (1, 1), (0, 1), (0.05, 0.5), (0, 0), (1, 0)) trim1.knotvector = knotvector.generate(trim1.degree, trim1.ctrlpts_size) trim1.delta = 0.001 trim1.opt = ['reversed', 1] # operations.scale(trim1, 0.5, inplace=True)