The Loft & NURBS Math
Cox-de Boor Algorithm:
1def de_boor(k, i, t, knots):2 # Cox-de Boor recursion for B-Spline basis functions3 if k == 0:4 return 1.0 if knots[i] <= t < knots[i+1] else 0.056 denom1 = knots[i+k] - knots[i]7 denom2 = knots[i+k+1] - knots[i+1]89 val1 = ((t - knots[i]) / denom1 * de_boor(k-1, i, t, knots)) if denom1 > 0 else 0.010 val2 = ((knots[i+k+1] - t) / denom2 * de_boor(k-1, i+1, t, knots)) if denom2 > 0 else 0.01112 return val1 + val21314def evaluate_nurbs(t, control_points, weights, knots):15 # Rational basis blending: sum(N_i * w_i * P_i) / sum(N_i * w_i)16 degree = len(knots) - len(control_points) - 117 num = [0.0, 0.0, 0.0]18 den = 0.019 for i, (pt, w) in enumerate(zip(control_points, weights)):20 basis = de_boor(degree, i, t, knots)21 den += basis * w22 num[0] += basis * w * pt[0]23 num[1] += basis * w * pt[1]24 num[2] += basis * w * pt[2]25 if den == 0.0: return control_points[0]26 return [num[0] / den, num[1] / den, num[2] / den]
Non-Uniform Rational B-Splines (NURBS) are the standard for industrial CAD. They are defined by control points, a knot vector, and weights. The "Rational" part means each control point has a weight, allowing exact representation of conic sections (like perfect circles).
Lofting Parameters:
1# Generate skin surface across multiple profile curves2def generate_loft_mesh(profiles, num_v_segments):3 # Interpolate between matching parameters 'u' on each curve4 mesh_vertices = []5 num_u = len(profiles[0])67 for i in range(num_v_segments):8 v = i / (num_v_segments - 1)9 # Cubic spline or linear interpolation along V direction10 for j in range(num_u):11 pt = interpolate_profile_set(profiles, j, v)12 mesh_vertices.append(pt)1314 return create_mesh(mesh_vertices)
A Loft operation generates a 3D surface by skinning a continuous sheet across multiple 2D cross-sections (profile curves).
Seam Optimization:
1def align_profile_start_points(profiles):2 aligned = [profiles[0]]3 for i in range(1, len(profiles)):4 prev_start = aligned[-1][0]5 curr = profiles[i]67 # Find start point index that minimizes distance to previous start8 best_shift = 09 min_dist = float('inf')10 n = len(curr)11 for shift in range(n):12 d = distance(prev_start, curr[shift])13 if d < min_dist:14 min_dist = d15 best_shift = shift1617 # Cyclic rotation of vertices to align seam18 aligned.append(curr[best_shift:] + curr[:best_shift])19 return aligned
When skinning closed profiles, the start points (seams) must be aligned. If the curves have mismatched start parameters, the skin ruling lines will twist, resulting in a self-intersecting or distorted surface.
Related Concepts
Denavit-Hartenberg parameters, homogeneous matrix chaining, end-effector pose, and workspace envelopes.
Analytical law-of-cosines IK, Jacobian transpose, Cyclic Coordinate Descent (CCD), and FABRIK solvers.
Sweeps, Revolves, and Curve Networks.