Skip to content

Commit

Permalink
"fillet curve" - commented out support for G2 mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
portnov committed Jan 4, 2023
1 parent 8b9b8f2 commit dcf956c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
2 changes: 2 additions & 0 deletions nodes/curve/fillet_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from sverchok.utils.curve.nurbs import SvNurbsCurve
from sverchok.utils.curve.fillet import (
SMOOTH_POSITION, SMOOTH_TANGENT, SMOOTH_ARC, SMOOTH_BIARC, SMOOTH_QUAD, SMOOTH_NORMAL, SMOOTH_CURVATURE,
SMOOTH_G2,
fillet_polyline_from_curve, fillet_nurbs_curve
)
from sverchok.utils.handle_blender_data import keep_enum_reference
Expand Down Expand Up @@ -69,6 +70,7 @@ def get_smooth_modes(self, context):
items.append((SMOOTH_BIARC, "1 - Bi Arc", "Connect segments with Bi Arc, such that tangents are smoothly joined", 2))
#items.append((SMOOTH_NORMAL, "2 - Normals", "Connect segments such that their normals (second derivatives) are smoothly joined", 3))
#items.append((SMOOTH_CURVATURE, "3 - Curvature", "Connect segments such that their curvatures (third derivatives) are smoothly joined", 4))
#items.append((SMOOTH_G2, "G2 - Curvature", "Connect curves such that their tangents, normals and curvatures are continuosly joined", 6))
else:
items.append((SMOOTH_ARC, "1 - Circular Arc", "Connect segments with circular arcs", 5))
return items
Expand Down
41 changes: 25 additions & 16 deletions utils/curve/fillet.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
SMOOTH_QUAD = '1q'
SMOOTH_NORMAL = '2'
SMOOTH_CURVATURE = '3'
SMOOTH_G2 = 'G2'

def calc_single_fillet(smooth, curve1, curve2, t_span, bulge_factor = 0.5, biarc_parameter = 1.0, planar_tolerance = 1e-6):
#t_span = 1.0
def calc_single_fillet(smooth, curve1, curve2, k1, k2, bulge_factor = 0.5, biarc_parameter = 1.0, planar_tolerance = 1e-6):
u1_max = curve1.get_u_bounds()[1]
u2_min = curve2.get_u_bounds()[0]
curve1_end = curve1.evaluate(u1_max)
curve2_begin = curve2.evaluate(u2_min)
tangent1_end = t_span * curve1.get_end_tangent()
tangent2_begin = t_span * curve2.get_start_tangent()
tangent1_end = k1 * curve1.get_end_tangent()
tangent2_begin = k2 * curve2.get_start_tangent()

if smooth == SMOOTH_POSITION:
return SvLine.from_two_points(curve1_end, curve2_begin)
Expand All @@ -58,23 +58,31 @@ def calc_single_fillet(smooth, curve1, curve2, t_span, bulge_factor = 0.5, biarc
biarc_parameter,
planar_tolerance = planar_tolerance)
elif smooth == SMOOTH_NORMAL:
second_1_end = t_span**2 * curve1.second_derivative(u1_max)
second_2_begin = t_span**2 * curve2.second_derivative(u2_min)
#print(f"T: {t_span**2}")
#print(f"E: {curve1_end}, {tangent1_end}, {second_1_end}")
#print(f"B: {curve2_begin}, {tangent2_begin}, {second_2_begin}")
second_1_end = k1**2 * curve1.second_derivative(u1_max)
second_2_begin = k2**2 * curve2.second_derivative(u2_min)
return SvBezierCurve.blend_second_derivatives(
curve1_end, tangent1_end, second_1_end,
curve2_begin, tangent2_begin, second_2_begin)
elif smooth == SMOOTH_CURVATURE:
second_1_end = t_span**2 * curve1.second_derivative(u1_max)
second_2_begin = t_span**2 * curve2.second_derivative(u2_min)
third_1_end = t_span**3 * curve1.third_derivative_array(np.array([u1_max]))[0]
third_2_begin = t_span**3 * curve2.third_derivative_array(np.array([u2_min]))[0]
second_1_end = k1**2 * curve1.second_derivative(u1_max)
second_2_begin = k2**2 * curve2.second_derivative(u2_min)
third_1_end = k1**3 * curve1.third_derivative_array(np.array([u1_max]))[0]
third_2_begin = k2**3 * curve2.third_derivative_array(np.array([u2_min]))[0]

return SvBezierCurve.blend_third_derivatives(
curve1_end, tangent1_end, second_1_end, third_1_end,
curve2_begin, tangent2_begin, second_2_begin, third_2_begin)
elif smooth == 'G2':
normal_1_end = curve1.main_normal(u1_max)
normal_2_begin = curve2.main_normal(u2_min)
curvature_1_end = curve1.curvature(u1_max)
curvature_2_begin = curve2.curvature(u2_min)

return SvBezierCurve.from_tangents_normals_curvatures(
curve1_end, curve2_begin,
tangent1_end, tangent2_begin,
normal_1_end, normal_2_begin,
curvature_1_end, curvature_2_begin)
else:
raise Exception(f"Unsupported smooth level: {smooth}")

Expand All @@ -91,8 +99,9 @@ def cut_ends(curve, cut_offset, cut_start=True, cut_end=True):
u2 = u_max - dt
else:
u2 = u_max
du = u2 - u1
#print(f"cut: {u_min} - {u_max} * cut_offset => {u1} - {u2}")
return dt, curve.cut_segment(u1, u2)
return du, curve.cut_segment(u1, u2)

def limit_filet_radiuses(vertices, radiuses, cyclic=False):
factor = 0.999
Expand Down Expand Up @@ -150,11 +159,11 @@ def fillet_nurbs_curve(curve, smooth, cut_offset,
segments = curve.split_at_fracture_points(tangent_tolerance = tangent_tolerance)
n = len(segments)
cuts = [cut_ends(s, cut_offset, cut_start = (i > 0 or cyclic), cut_end = (i < n-1 or cyclic)) for i, s in enumerate(segments)]
fillets = [calc_single_fillet(smooth, s1, s2, dt1+dt2, bulge_factor, biarc_parameter, planar_tolerance) for (dt1,s1), (dt2,s2) in zip(cuts, cuts[1:])]
fillets = [calc_single_fillet(smooth, s1, s2, dt1, dt2, bulge_factor, biarc_parameter, planar_tolerance) for (dt1,s1), (dt2,s2) in zip(cuts, cuts[1:])]
if cyclic:
dt1, s1 = cuts[-1]
dt2, s2 = cuts[0]
fillet = calc_single_fillet(smooth, s1, s2, dt1+dt2, bulge_factor, biarc_parameter, planar_tolerance)
fillet = calc_single_fillet(smooth, s1, s2, dt1, dt2, bulge_factor, biarc_parameter, planar_tolerance)
fillets.append(fillet)
segments = [cut[1] for cut in cuts]
new_segments = [[segment, fillet] for segment, fillet in zip(segments, fillets)]
Expand Down

0 comments on commit dcf956c

Please sign in to comment.