The Intersect module computes intersection curves between geometric objects and extracts isocontours from scalar fields.
Compute intersection curves between two 3D meshes:
import trueform as tf
import numpy as np
# Load two meshes (must be 3D and have matching dtypes)
faces1, points1 = tf.read_stl("mesh1.stl")
faces2, points2 = tf.read_stl("mesh2.stl")
mesh1 = tf.Mesh(faces1, points1)
mesh2 = tf.Mesh(faces2, points2)
#optionally add transformations to one or both
mesh1.transformation = np.eye(4, dtype=np.float32)
# Compute intersection curves between the two meshes
paths, curve_points = tf.intersection_curves(mesh1, mesh2)
# paths: OffsetBlockedArray of curve paths (each path is a sequence of point indices)
# curve_points: numpy array of 3D intersection points
print(f"Number of curves: {len(paths)}")
print(f"Number of curve points: {len(curve_points)}")
# Iterate over each curve
for i, path_ids in enumerate(paths):
# Get the points for this curve
pts = curve_points[path_ids]
print(f"Curve {i}: {len(pts)} points")
The function returns:
OffsetBlockedArray where each element contains indices into curve_points, representing one curve(N, 3) containing all curve verticesRequirements:
Find curves where a mesh intersects itself:
import trueform as tf
# Load mesh that may have self-intersections
faces, points = tf.read_stl("mesh.stl")
mesh = tf.Mesh(faces, points)
# Find self-intersection curves
paths, curve_points = tf.self_intersection_curves(mesh)
print(f"Found {len(paths)} self-intersection curve(s)")
# Iterate over curves
for path_ids in paths:
pts = curve_points[path_ids]
# Process curve (e.g., visualize, repair, etc.)
Requirements:
Extract isocontour curves from scalar fields on meshes:
# Load mesh
faces, points = tf.read_stl("terrain.stl")
mesh = tf.Mesh(faces, points)
# Create scalar field using distance to a plane (one value per vertex)
plane = tf.Plane(normal=[0, 0, 1], offset=0.0)
scalar_field = tf.distance_field(mesh.points, plane)
# Extract isocontours at specific threshold values
paths, contour_points = tf.isocontours(mesh, scalar_field, 0.0)
# paths: OffsetBlockedArray of contour paths
# contour_points: numpy array of contour vertices
print(f"Number of contours: {len(paths)}")
print(f"Number of contour points: {len(contour_points)}")
# Extract multiple isocontours
thresholds = np.array([0.0, 0.5, 1.0], dtype=np.float32)
paths, contour_points = tf.isocontours(mesh, scalar_field, thresholds)
# Iterate over each contour
for i, path_ids in enumerate(paths):
# Get the points for this contour
pts = contour_points[path_ids]
print(f"Contour {i}: {len(pts)} points")
The function returns:
OffsetBlockedArray where each element contains indices into contour_points, representing one isocontour(N, D) where D is 2 or 3, containing all contour verticesParameters:
(faces, points)Use cases: