def bevel_curve(path, profile, taper, taper_samples=10, taper_refine=20, profile_samples=10): taper_t_min, taper_t_max = taper.get_u_bounds() profile_t_min, profile_t_max = profile.get_u_bounds() taper_start = taper.evaluate(taper_t_min) taper_end = taper.evaluate(taper_t_max) z_min = taper_start[2] z_max = taper_end[2] field = SvBendAlongCurveField(path, SvBendAlongCurveField.HOUSEHOLDER, scale_all=False, axis=2, t_min=z_min, t_max=z_max, length_mode='L') taper_ts = np.linspace(taper_t_min, taper_t_max, num=taper_samples) taper_pts = taper.evaluate_array(taper_ts) taper_pts = taper_pts[:, 0], taper_pts[:, 1], taper_pts[:, 2] taper_rhos, _, taper_zs = to_cylindrical_np(taper_pts) profile_start_rho = to_cylindrical(profile.evaluate(profile_t_min))[0] taper_start_rho, taper_start_angle, _ = to_cylindrical( taper.evaluate(taper_t_min)) profiles = [ place_profile(profile, z, scale) for z, scale in zip(taper_zs, taper_rhos / profile_start_rho) ] profiles = [bend_curve(field, profile) for profile in profiles] profile_ts = np.linspace(profile_t_min, profile_t_max, num=profile_samples, endpoint=True) profile_pts = profile.evaluate_array(profile_ts) profile_pts = profile_pts[:, 0], profile_pts[:, 1], profile_pts[:, 2] profile_rhos, profile_angles, _ = to_cylindrical_np(profile_pts, mode='radians') taper = refine_curve(taper, taper_refine) tapers = [ rotate_curve(taper, angle - taper_start_angle, scale) for angle, scale in zip(profile_angles, profile_rhos / profile_start_rho) ] tapers = [bend_curve(field, taper) for taper in tapers] #intersections = [[taper.evaluate(t) for t in taper_ts] for taper in tapers] intersections = [[taper.evaluate(t) for taper in tapers] for t in taper_ts] return tapers, profiles, gordon_surface(tapers, profiles, intersections)[-1]
def cylindrical(x, y, z, V): rho, phi, z = to_cylindrical((x, y, z), mode='radians') variables.update(dict(rho=rho, phi=phi, z=z, V=V)) r = safe_eval_compiled(compiled, variables) if not isinstance(r, np.ndarray): r = np.full_like(x, r) return r
def cylindrical_in(x, y, z, V): rho, phi, z = to_cylindrical((x, y, z), mode='radians') variables.update(dict(rho=rho, phi=phi, z=z, V=V)) v1 = safe_eval_compiled(compiled1, variables) v2 = safe_eval_compiled(compiled2, variables) v3 = safe_eval_compiled(compiled3, variables) return out_coordinates(v1, v2, v3)
def evaluate(self, x, y, z): result = self.vfield.evaluate(x, y, z) if self.coords == 'XYZ': return result[self.axis] elif self.coords == 'CYL': rho, phi, z = to_cylindrical(tuple(result), mode='radians') return [rho, phi, z][self.axis] else: # SPH rho, phi, theta = to_spherical(tuple(result), mode='radians') return [rho, phi, theta][self.axis]
def evaluate_grid(self, xs, ys, zs): results = self.vfield.evaluate_grid(xs, ys, zs) if self.coords == 'XYZ': return results[self.axis] elif self.coords == 'CYL': vectors = np.stack(results).T vectors = np.apply_along_axis(lambda v: np.array(to_cylindrical(tuple(v), mode='radians')), 1, vectors) return vectors[:, self.axis] else: # SPH vectors = np.stack(results).T vectors = np.apply_along_axis(lambda v: np.array(to_spherical(tuple(v), mode='radians')), 1, vectors) return vectors[:, self.axis]
def cylindrical_in(x, y, z, V): rho, phi, z = to_cylindrical((x, y, z), mode='radians') variables.update(dict(rho=rho, phi=phi, z=z, V=V)) v1 = safe_eval_compiled(compiled1, variables, allowed_names=safe_names_np) v2 = safe_eval_compiled(compiled2, variables, allowed_names=safe_names_np) v3 = safe_eval_compiled(compiled3, variables, allowed_names=safe_names_np) if not isinstance(v1, np.ndarray): v1 = np.full_like(x, v1) if not isinstance(v2, np.ndarray): v2 = np.full_like(x, v2) if not isinstance(v3, np.ndarray): v3 = np.full_like(x, v3) return out_coordinates(v1, v2, v3)
def key(item): v = matrix @ (Vector(item[:3]) - center) rho, phi, z = to_cylindrical(v) return (phi, z, rho)
def cylindrical(x, y, z, V): rho, phi, z = to_cylindrical((x, y, z), mode='radians') variables.update(dict(rho=rho, phi=phi, z=z, V=V)) return safe_eval_compiled(compiled, variables)
def nurbs_bevel_curve_gordon(path, profile, taper, algorithm=SvBendAlongCurveField.HOUSEHOLDER, scale_all=False, path_axis=2, path_length_mode='T', path_length_resolution=50, up_axis=None, taper_samples=10, taper_refine=20, profile_samples=10): if profile.is_rational(): raise Exception( "Rational profile curves are not supported by Gordon algorithm") if taper.is_rational(): raise Exception( "Rational taper curves are not supported by Gordon algorithm") taper_t_min, taper_t_max = taper.get_u_bounds() profile_t_min, profile_t_max = profile.get_u_bounds() taper_start = taper.evaluate(taper_t_min) taper_end = taper.evaluate(taper_t_max) z_min = taper_start[path_axis] z_max = taper_end[path_axis] field = SvBendAlongCurveField(path, algorithm, scale_all=scale_all, axis=path_axis, t_min=z_min, t_max=z_max, length_mode=path_length_mode, resolution=path_length_resolution, up_axis=up_axis) if path_length_mode == 'T': taper_ts = np.linspace(taper_t_min, taper_t_max, num=taper_samples) else: solver = SvCurveLengthSolver(taper) solver.prepare('SPL', path_length_resolution) total_length = solver.get_total_length() input_lengths = np.linspace(0.0, total_length, num=taper_samples) taper_ts = solver.solve(input_lengths) taper_pts = taper.evaluate_array(taper_ts) taper_pts = taper_pts[:, 0], taper_pts[:, 1], taper_pts[:, 2] taper_rhos, _, taper_zs = to_cylindrical_np(taper_pts) profile_start_rho = to_cylindrical(profile.evaluate(profile_t_min))[0] taper_start_rho, taper_start_angle, _ = to_cylindrical( taper.evaluate(taper_t_min)) profiles = [ place_profile_z(profile, z, scale) for z, scale in zip(taper_zs, taper_rhos / profile_start_rho) ] profiles = [bend_curve(field, profile) for profile in profiles] profiles = [profile.reverse() for profile in profiles] profile_ts = np.linspace(profile_t_min, profile_t_max, num=profile_samples, endpoint=True) profile_pts = profile.evaluate_array(profile_ts) profile_pts = profile_pts[:, 0], profile_pts[:, 1], profile_pts[:, 2] profile_rhos, profile_angles, _ = to_cylindrical_np(profile_pts, mode='radians') if path_length_mode == 'L': solver = SvCurveLengthSolver(taper) solver.prepare('SPL', path_length_resolution) else: solver = None taper = refine_curve(taper, taper_refine, solver=solver) tapers = [ rotate_curve_z(taper, angle - taper_start_angle, scale) for angle, scale in zip(profile_angles, profile_rhos / profile_start_rho) ] tapers = [bend_curve(field, taper) for taper in tapers] #intersections = [[taper.evaluate(t) for t in taper_ts] for taper in tapers] intersections = [[taper.evaluate(t) for taper in tapers] for t in taper_ts] return gordon_surface(tapers, profiles, intersections)[-1]
def cylindrical(v, mode): return to_cylindrical(v, mode)