Initializing 3D Canvas...

The Loft & NURBS Math

4 min read1 page

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).

Cox-de Boor Algorithm:

1. Knot Vector: Non-decreasing sequence of coordinates dividing parameter space. 2. B-Spline Basis: Recursively blends control points to produce smooth local curves. 3. Rational Weighting: Higher weight pulls the curve closer to that control point.
python
1def de_boor(k, i, t, knots):
2 # Cox-de Boor recursion for B-Spline basis functions
3 if k == 0:
4 return 1.0 if knots[i] <= t < knots[i+1] else 0.0
5
6 denom1 = knots[i+k] - knots[i]
7 denom2 = knots[i+k+1] - knots[i+1]
8
9 val1 = ((t - knots[i]) / denom1 * de_boor(k-1, i, t, knots)) if denom1 > 0 else 0.0
10 val2 = ((knots[i+k+1] - t) / denom2 * de_boor(k-1, i+1, t, knots)) if denom2 > 0 else 0.0
11
12 return val1 + val2
13
14def 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) - 1
17 num = [0.0, 0.0, 0.0]
18 den = 0.0
19 for i, (pt, w) in enumerate(zip(control_points, weights)):
20 basis = de_boor(degree, i, t, knots)
21 den += basis * w
22 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]
Middle Control Point Weight
1.00
2 min read1 page

A Loft operation generates a 3D surface by skinning a continuous sheet across multiple 2D cross-sections (profile curves).

Lofting Parameters:

1. Cross-sections (U-direction): The profile curves defining the shape boundaries. 2. Spine (V-direction): The longitudinal direction of interpolation between profiles. 3. Interpolation Style: Can range from tight linear ruled transitions to smooth cubic B-Spline skins.
python
1# Generate skin surface across multiple profile curves
2def generate_loft_mesh(profiles, num_v_segments):
3 # Interpolate between matching parameters 'u' on each curve
4 mesh_vertices = []
5 num_u = len(profiles[0])
6
7 for i in range(num_v_segments):
8 v = i / (num_v_segments - 1)
9 # Cubic spline or linear interpolation along V direction
10 for j in range(num_u):
11 pt = interpolate_profile_set(profiles, j, v)
12 mesh_vertices.append(pt)
13
14 return create_mesh(mesh_vertices)
Middle Profile Scale
1.00
2 min read1 page

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.

Seam Optimization:

1. Mismatched Seams: Different start indices create skewing and twisting. 2. Distance Minimization: Compute the distance between start points of consecutive profiles. 3. Cyclic Rotation: Shift the starting vertex index of the upper profiles to align them with the base profile.
python
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]
6
7 # Find start point index that minimizes distance to previous start
8 best_shift = 0
9 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 = d
15 best_shift = shift
16
17 # Cyclic rotation of vertices to align seam
18 aligned.append(curr[best_shift:] + curr[:best_shift])
19 return aligned
Top Seam Index Twist Offset
0.00