Skip to main content
100%

Closest Point on a Path and Its Tangent

✓ Published0🌍 Public
Aandresin87
Last edited Feb 14, 2016
Created on Feb 10, 2016

This example shows a closed cardinal spline path with a draggable circle that snaps to the closest point on the path. As the user drags the circle over the SVG area, a red tangent line appears at the nearest path location, with its angle and position continuously updated based on the path geometry. The visualization uses D3’s drag behavior, SVG path interpolation, and a binary search plus linear scan to compute the closest point and tangent. It also includes the pathseg.js polyfill to support the SVGPathSeg API in browsers that removed it.

AI-generated description

Drag The circle through the svg area and discover the behaviour.

The "pathSegList" method was removed in chome version 58 so you need to include the javascript library "pathseg.js".

Newest faster version Here!

Similar vizzes