Array of 3D positions forming the path
Smoothing configuration options
Smoothed path with rounded corners
import { smoothPath } from '@jbcom/strata/core/pathfinding';
const rawPath = [
{ x: 0, y: 0, z: 0 },
{ x: 10, y: 0, z: 0 }, // Sharp 90° turn
{ x: 10, y: 0, z: 10 }
];
const smoothed = smoothPath(rawPath, {
iterations: 2, // More iterations = smoother
strength: 0.25, // 0-1, how much to round corners
preserveEndpoints: true // Keep start and end points exact
});
// smoothed now has more points with gentle curves
console.log('Points increased from', rawPath.length, 'to', smoothed.length);
// Light smoothing - subtle rounding
const gentle = smoothPath(path, { iterations: 1, strength: 0.1 });
// Medium smoothing - natural curves (default)
const normal = smoothPath(path, { iterations: 2, strength: 0.25 });
// Heavy smoothing - very round, flowing paths
const smooth = smoothPath(path, { iterations: 3, strength: 0.4 });
// Fast, nimble agent - aggressive smoothing
const rabbitPath = smoothPath(path, {
iterations: 3,
strength: 0.35,
preserveEndpoints: true
});
// Heavy, lumbering agent - minimal smoothing
const tankPath = smoothPath(path, {
iterations: 1,
strength: 0.15,
preserveEndpoints: true
});
// Flying agent - maximum smoothing for graceful flight
const birdPath = smoothPath(path, {
iterations: 4,
strength: 0.4,
preserveEndpoints: false // Can deviate from exact endpoints
});
import { smoothPath, simplifyPath } from '@jbcom/strata/core/pathfinding';
// First simplify to remove unnecessary points
const simplified = simplifyPath(rawPath, 0.5);
// Then smooth for natural movement
const final = smoothPath(simplified, {
iterations: 2,
strength: 0.25
});
// Result: Efficient path with natural curves
Smooths a path using Chaikin's corner cutting algorithm.
Reduces sharp corners and creates more natural-looking movement paths by iteratively replacing each line segment with two shorter segments. Perfect for making AI movement feel organic rather than robotic.