path-rite

pointAndTangentAtDistance

Get the point and tangent angle at a given distance along a path.

pointAndTangentAtDistance(svgPath: string, distance: number, accuracy: number): { x: number, y: number, angle: 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, y coordinates and angle (tangent direction in radians).

// Get position and direction for placing an arrowhead
const result = pathRite.pointAndTangentAtDistance(
  "M 0 0 C 50 0 50 100 100 100", 75, 0.1
);
// result === { x: ..., y: ..., angle: ... }