Planar Slicing & Layering
Planar Mesh Slicing (Contour Generation): Slicing is the fundamental gateway of 3D printing (FDM, SLA, SLS). An arbitrary triangular mesh model is intersected by horizontal cutting planes at height $z = k \cdot \Delta z$. Each triangle intersecting the plane produces an isolated line segment. Graph chaining stitches segments end-to-end into closed, winding-oriented perimeter polygons.
Slicing Contour Pipeline:
1def intersect_triangle_plane(v0, v1, v2, z_slice):2 """3 Computes intersection segment between a 3D triangle and a horizontal slicing plane Z = z_slice.4 Returns None if triangle does not cross plane, or a 2-point line segment [P1, P2].5 """6 vertices = [v0, v1, v2]7 dists = [v[2] - z_slice for v in vertices]89 # Check if all vertices lie on one side10 if (dists[0] > 0 and dists[1] > 0 and dists[2] > 0) or \11 (dists[0] < 0 and dists[1] < 0 and dists[2] < 0):12 return None1314 pts = []15 edges = [(0, 1), (1, 2), (2, 0)]16 for i, j in edges:17 d_i, d_j = dists[i], dists[j]18 # Edge crosses slicing plane19 if (d_i > 0 and d_j < 0) or (d_i < 0 and d_j > 0):20 t = abs(d_i) / (abs(d_i) + abs(d_j))21 p_interp = vertices[i] + t * (vertices[j] - vertices[i])22 pts.append(p_interp)2324 return pts if len(pts) == 2 else None
Adaptive Layer Slicing (Cusp Height Optimization): Constant layer thickness forces a harsh trade-off between print time and surface fidelity. Adaptive slicing calculates the layer height dynamically: steep vertical walls slice at maximum speed with thick layers, while gently sloping domes automatically thin down to sub-millimeter slices to suppress stair-stepping artifacts below the threshold of human perception.
Cusp Geometry Invariant:
1import math23def compute_adaptive_layer_height(surface_normal, target_cusp=0.02, min_h=0.05, max_h=0.30):4 """5 Computes adaptive slicing thickness based on surface inclination angle theta.6 Cusp error delta = layer_height * cos(theta).7 Therefore layer_height = target_cusp / cos(theta), clamped to [min_h, max_h].8 """9 # Normal dot product with vertical Z axis10 nz = abs(surface_normal[2])11 cos_theta = math.sqrt(max(0.0, 1.0 - nz * nz)) # inclination relative to vertical1213 if cos_theta < 1e-4:14 return min_h # Flat horizontal surfaces require finest resolution1516 adaptive_h = target_cusp / cos_theta17 return max(min_h, min(max_h, adaptive_h))