def tangent_array(self, ts): t_min, t_max = self.get_u_bounds() ts[ts < t_min] = t_min ts[ts > t_max] = t_max vs = operations.tangent(self.curve, list(ts), normalize=False) tangents = [t[1] for t in vs] #print(f"ts: {ts}, vs: {tangents}") return np.array(tangents)
curve.knotvector = utilities.generate_knot_vector(curve.degree, len(curve.ctrlpts)) # Set evaluation delta curve.delta = 0.01 # Evaulate curve curve.evaluate() # Draw the control point polygon and the evaluated curve vis_comp = VisPlotly.VisCurve2D() curve.vis = vis_comp curve.render() # Evaluate curve tangent at u = 0.0 curvetan1 = operations.tangent(curve, 0.0, normalize=True) # Evaluate curve tangent at u = 0.2 curvetan2 = operations.tangent(curve, 0.2, normalize=True) # Evaluate curve tangent at u = 0.5 curvetan3 = operations.tangent(curve, 0.5, normalize=True) # Evaluate curve tangent at u = 0.6 curvetan4 = operations.tangent(curve, 0.6, normalize=True) # Evaluate curve tangent at u = 0.8 curvetan5 = operations.tangent(curve, 0.8, normalize=True) # Evaluate curve tangent at u = 1.0 curvetan6 = operations.tangent(curve, 1.0, normalize=True)
def tangent(self, t): p, t = operations.tangent(self.curve, t, normalize=False) return np.array(t)
curve.ctrlpts = exchange.import_txt("ex_curve02.cpt") # Auto-generate knot vector curve.knotvector = utilities.generate_knot_vector(curve.degree, len(curve.ctrlpts)) # Set evaluation delta curve.delta = 0.01 # Evaluate curve curve.evaluate() # Plot the control point polygon and the evaluated curve vis_comp = VisMPL.VisCurve2D() curve.vis = vis_comp curve.render() # Evaluate derivatives at u = 0.6 ders1 = curve.derivatives(0.6, 4) # Change evaluator curve.evaluator = evaluators.CurveEvaluator2() # Evaluate derivatives at u = 0.6 using the new evaluator ders2 = curve.derivatives(0.6, 4) # Compute curve tangent at u = 0.6 curvetan = operations.tangent(curve, 0.6) # Good to have something here to put a breakpoint pass
# Set evaluation delta curve.delta = 0.01 # Evaulate curve curve.evaluate() # # Tangent Vector Evaluation # # Store tangent vectors in a list for plotting curvetan = [] # Evaluate curve tangent at u = 0.0 ct1 = operations.tangent(curve, 0.0, normalize=True) curvetan.append(ct1) # Evaluate curve tangent at u = 0.2 ct2 = operations.tangent(curve, 0.2, normalize=True) curvetan.append(ct2) # Evaluate curve tangent at u = 0.5 ct3 = operations.tangent(curve, 0.5, normalize=True) curvetan.append(ct3) # Evaluate curve tangent at u = 0.6 ct4 = operations.tangent(curve, 0.6, normalize=True) curvetan.append(ct4) # Evaluate curve tangent at u = 0.8
# Set degrees surf.degree_u = 3 surf.degree_v = 3 # Set control points surf.set_ctrlpts( *exchange.import_txt("ex_surface02.cpt", two_dimensional=True)) # Set knot vectors surf.knotvector_u = utilities.generate_knot_vector(surf.degree_u, 6) surf.knotvector_v = utilities.generate_knot_vector(surf.degree_v, 6) # Set evaluation delta surf.delta = 0.025 # Evaluate surface surf.evaluate() # Plot the control point grid and the evaluated surface vis_comp = VisPlotly.VisSurface() surf.vis = vis_comp surf.render() # Evaluate surface tangent and normal at the given u and v uv = [0.2, 0.9] surf_tangent = operations.tangent(surf, uv) surf_normal = operations.normal(surf, uv) # Good to have something here to put a breakpoint pass
surf.knotvector_u = utilities.generate_knot_vector(surf.degree_u, 6) surf.knotvector_v = utilities.generate_knot_vector(surf.degree_v, 6) # Set evaluation delta surf.delta = 0.05 # Evaluate surface surf.evaluate() # Evaluate surface tangent and normal vectors uv_vals = [[0.1, 0.1], [0.65, 0.25], [0.9, 0.7], [0.2, 0.9]] surftans = [[] for _ in range(len(uv_vals))] surfnorms = [[] for _ in range(len(uv_vals))] for idx, uv in enumerate(uv_vals): surftans[idx] = operations.tangent(surf, uv, normalize=True) surfnorms[idx] = operations.normal(surf, uv, normalize=True) # Prepare points for plotting surfpts = np.array(surf.evalpts) tangent_vectors = np.array(surftans) normal_vectors = np.array(surfnorms) # Start plotting of the surface and the control points grid fig = plt.figure(figsize=(10.67, 8), dpi=96) ax = Axes3D(fig) # Plot surface points ax.plot_trisurf(surfpts[:, 0], surfpts[:, 1], surfpts[:, 2],
# Create a B-Spline curve instance curve = BSpline.Curve() # Set up curve curve.degree = 4 curve.ctrlpts = exchange.import_txt("ex_curve3d01.cpt") # Auto-generate knot vector curve.knotvector = utilities.generate_knot_vector(curve.degree, len(curve.ctrlpts)) # Split the curve split_curves = operations.split_curve(curve, 0.3) curves = multi.CurveContainer(split_curves) # Move the 1st curve a little bit far away from the 2nd curve c2tan = operations.tangent(curves[1], 0.0, normalize=True) c2tanvec = [-1 * p for p in c2tan[1]] operations.translate(curves[0], c2tanvec, inplace=True) # Plot the curves using the curve container curves.sample_size = 100 # Plot the control point polygon and the evaluated curve vis_comp = VisPlotly.VisCurve3D() curves.vis = vis_comp curves.render() # Good to have something here to put a breakpoint pass
# Set evaluation delta curve.delta = 0.001 # Evaulate curve curve.evaluate() # # Tangent Vector Evaluation # # Store tangent vectors in a list for plotting curvetan = [] # Evaluate curve tangent at u = 0.0175 ct1 = operations.tangent(curve, 0.0175, normalize=True) curvetan.append(ct1) # Evaluate curve tangent at u = 0.075 ct2 = operations.tangent(curve, 0.075, normalize=True) curvetan.append(ct2) # Evaluate curve tangent at u = 0.375 ct3 = operations.tangent(curve, 0.375, normalize=True) curvetan.append(ct3) # Evaluate curve tangent at u = 0.535 ct4 = operations.tangent(curve, 0.535, normalize=True) curvetan.append(ct4) # Evaluate curve tangent at u = 0.65
# Evaulate curve curve.evaluate() # # Multiple vector evaluation after v3.0.7 # # List of parametric coordinates to be evaluated u_list = (0.0175, 0.075, 0.375, 0.535, 0.65, 0.85, 0.975) # Evaluate tangents, normals and binormals, respectively curvetans = [[] for _ in range(len(u_list))] curvenorms = [[] for _ in range(len(u_list))] curvebinorms = [[] for _ in range(len(u_list))] for idx, u in enumerate(u_list): curvetans[idx] = operations.tangent(curve, u, normalize=True) curvenorms[idx] = operations.normal(curve, u, normalize=True) curvebinorms[idx] = operations.binormal(curve, u, normalize=True) # # Control Points, Curve and Tangent Vector Plotting using Matplotlib # # Arrange control points and evaluated curve points for plotting ctrlpts = np.array(curve.ctrlpts) curvepts = np.array(curve.evalpts) # Convert tangent, normal and binormal vector lists into NumPy arrays ctarr = np.array(curvetans) cnarr = np.array(curvenorms) cbnarr = np.array(curvebinorms)