path-rite

pointAtDistance

Get the x/y coordinates of the point at a given distance along a path.

pointAtDistance(svgPath: string, distance: number, accuracy: number): { x: number, y: number }

svgPath — SVG path d-attribute string.

distance — Distance along the path from the start, in SVG units.

accuracy — Computation accuracy. Smaller values give more precise results. Typical value: 0.1.

Returns — An object with x and y coordinates of the point.

// Find the midpoint of a line
const pt = pathRite.pointAtDistance("M 0 0 L 100 0", 50, 0.1);
// pt === { x: 50, y: 0 }