Skip to main content

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

Sweeps a profile curve along a path curve to create a 3D boundary representation.
path_points
&[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.
profile_points
&[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.
options
SweepOptions
required
Configuration controlling end cap generation.

Configuration

SweepOptions

cap_start
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.
cap_end
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 a Brep (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

  1. Path Sanitization: Removes consecutive duplicate points and detects if the path forms a closed loop
  2. Profile Preparation:
    • Computes profile centroid
    • Calculates profile plane normal
    • Converts profile to local coordinates (u, v, w basis)
  3. Frame Calculation:
    • Computes tangent vectors along the path
    • Builds rotation-minimizing frames using parallel transport
    • Ensures smooth frame transitions without twisting
  4. Vertex Placement: Transforms each profile point into world space at each path section
  5. 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-9 for 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
Last modified on March 14, 2026