Modules | TS
Intersect
Compute intersection curves between meshes and scalar field isocontours.
The Intersect module computes intersection curves between geometric objects and extracts isocontour curves from scalar fields.
Intersection Curves
Compute intersection curves between two 3D meshes:
import * as tf from "@polydera/trueform";
const mesh1 = tf.readStl("mesh1.stl");
const mesh2 = tf.readStl("mesh2.stl");
// Compute intersection curves
const curves = tf.intersectionCurves(mesh1, mesh2);
console.log(`Number of curves: ${curves.length}`);
console.log(`Total curve points: ${curves.points.length}`);
// Access individual curve paths
for (let i = 0; i < curves.length; i++) {
const pathIds = curves.paths.at(i);
console.log(`Curve ${i}: ${pathIds.length} points`);
}
The function returns a Curves object with:
paths—OffsetBlockedBufferwhere each element contains indices intopoints, representing one curvepoints—NDArrayFloat32of shape[N, 3]containing all curve verticeslength— number of curves
Requirements:
- Both meshes must be 3D
- Works with both triangle meshes and polygon meshes
Self-Intersection Curves
Find curves where a mesh intersects itself.
To embed self-intersection curves into mesh topology, use
tf.embeddedSelfIntersectionCurves from the Cut module.import * as tf from "@polydera/trueform";
const mesh = tf.readStl("mesh.stl");
// Find self-intersection curves
const curves = tf.selfIntersectionCurves(mesh);
console.log(`Found ${curves.length} self-intersection curve(s)`);
Isocontours
Extract isocontour curves from scalar fields on meshes.
To cut meshes into regions using isocontours, use
tf.isobands from the Cut module.import * as tf from "@polydera/trueform";
const mesh = tf.readStl("terrain.stl");
// Create scalar field (one value per vertex)
const plane = tf.plane([0, 0, 1], 0.0);
const scalars = tf.distance(tf.point(mesh.points), plane);
// Extract isocontours at a single threshold
const curves = tf.isocontours(mesh, scalars, 0.0);
console.log(`Number of contours: ${curves.length}`);
Multiple Thresholds
Extract isocontours at several threshold values in a single call:
// Extract contours at multiple thresholds
const thresholds = new Float32Array([0.0, 0.5, 1.0]);
const curves = tf.isocontours(mesh, scalars, thresholds);
for (let i = 0; i < curves.length; i++) {
const pathIds = curves.paths.at(i);
console.log(`Contour ${i}: ${pathIds.length} points`);
}
| Parameter | Type | Description |
|---|---|---|
mesh | Mesh | Mesh to extract isocontours from |
scalars | NDArrayFloat32 | Scalar field with one value per vertex |
threshold | number | Float32Array | Single threshold value or array of thresholds |
Use cases:
- Extracting elevation contours from terrain data
- Visualizing level sets of physical quantities (temperature, pressure, etc.)
- Creating contour lines from implicit functions
- Analyzing stress distributions in FEA results
Async
All intersect functions are available as async variants via tf.async for off-main-thread execution:
const curves = await tf.async.intersectionCurves(mesh1, mesh2);
const self = await tf.async.selfIntersectionCurves(mesh);
const iso = await tf.async.isocontours(mesh, scalars, 0.0);
For implementation details and low-level intersection access, see the C++ Intersect documentation.
