Overview
The sweep operation generates a 3D surface (BREP) by moving a 2D profile shape along a 3D path. It automatically computes rotation-minimizing frames along the path to prevent twisting, making it ideal for creating pipes, tubes, rails, and architectural moldings.Function Signature
&[Vector3]
required
The 3D path curve to sweep along. Must have at least 2 points. If the first and last points are identical (within epsilon), the path is treated as closed.
&[Vector3]
required
The 2D or 3D profile shape to sweep. Must have at least 3 points to form a valid closed profile. The profile is automatically centered and oriented relative to the path.
SweepOptions
required
Configuration controlling end cap generation.
Configuration
SweepOptions
bool
default:"true"
Generate a closed face at the start of the sweep (only for open paths). Set to
false to create an open tube.bool
default:"true"
Generate a closed face at the end of the sweep (only for open paths). Set to
false to create an open tube.Default Options
Return Type
Returns aBrep (Boundary Representation) object containing:
- vertices: All 3D vertex positions (profile vertices × path sections)
- edges: Connectivity information for the mesh
- faces: Quadrilateral side faces and optional triangular/polygonal end caps
How It Works
- Path Sanitization: Removes consecutive duplicate points and detects if the path forms a closed loop
- Profile Preparation:
- Computes profile centroid
- Calculates profile plane normal
- Converts profile to local coordinates (u, v, w basis)
- Frame Calculation:
- Computes tangent vectors along the path
- Builds rotation-minimizing frames using parallel transport
- Ensures smooth frame transitions without twisting
- Vertex Placement: Transforms each profile point into world space at each path section
- Face Generation:
- Creates quadrilateral side faces connecting successive sections
- Adds end caps for open paths (if enabled)
- Connects vertices to form a watertight mesh
Code Examples
Basic Sweep: Creating a Pipe
Curved Path Sweep
Open Tube Without Caps
Closed Loop Sweep
Visual Examples
Frame Calculation Details
Rotation-Minimizing Frames
The sweep operation uses a parallel transport method to compute frames that:- Follow the path tangent direction
- Minimize rotation (twist) along the path
- Handle sudden direction changes smoothly
- Work correctly for both open and closed paths
Frame Components
- Tangent: Direction along the path
- Normal: First perpendicular direction (maps to profile U axis)
- Binormal: Second perpendicular direction (maps to profile V axis)
Implementation Details
Source Location
~/workspace/source/main/opengeometry/src/operations/sweep.rs:98
Precision
- Uses
EPSILON = 1.0e-9for geometric comparisons - Robust handling of near-zero vectors
- Graceful fallback for degenerate cases
Profile Orientation
- Profile is automatically centered at its centroid
- Profile normal is computed using Newell’s method
- Profile is decomposed into local orthonormal basis (u, v, w)
- No manual profile alignment required
Edge Cases
- Insufficient Points:
- Path < 2 points: Returns empty BREP
- Profile < 3 points: Returns empty BREP
- Closed Paths: Automatically detected and handled (no end caps generated)
- Degenerate Frames: Fallback to default orthogonal vectors
- Collinear Path Segments: Frames smoothly interpolated
Performance Considerations
- Vertex count:
profile_points × path_sections - Face count (open):
profile_points × (path_sections - 1) + 2 caps - Face count (closed):
profile_points × path_sections - Memory: O(vertices + faces)
Live Demo
Sweep Demo
Try the Sweep operation in the browser
See Also
Extrude
Special case of sweep along a straight vertical path
Offset
Create parallel offset curves in 2D

