Beispiel #1
0
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]
Beispiel #2
0
 def cylindrical(x, y, z, V):
     rho, phi, z = to_cylindrical_np((x, y, z), mode='radians')
     variables.update(dict(rho=rho, phi=phi, z=z, V=V))
     r = safe_eval_compiled(compiled, variables, allowed_names = safe_names_np)
     if not isinstance(r, np.ndarray):
         r = np.full_like(x, r)
     return r
Beispiel #3
0
def rotate_curve_z(curve, angle, scale):
    control_points = np.copy(curve.get_control_points())
    control_points = control_points[:, 0], control_points[:,
                                                          1], control_points[:,
                                                                             2]
    rhos, phis, zs = to_cylindrical_np(control_points, mode='radians')
    xs, ys, zs = from_cylindrical_np(rhos * scale,
                                     phis + angle,
                                     zs,
                                     mode='radians')
    control_points = np.stack((xs, ys, zs)).T
    return curve.copy(control_points=control_points)
 def cylindrical_in(x, y, z, V):
     rho, phi, z = to_cylindrical_np((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)
Beispiel #5
0
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]