Skip to main content
100%

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Closest Point on a Path and Its Tangent

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

A draggable circle snaps to the nearest point along a closed, cardinal-interpolated path while a red tangent line updates to show the path's direction at that location. Built with D3 v3 and SVG, the example demonstrates the `closestPoint` algorithm using `getPointAtLength` with a linear scan and binary search, and `getTangent` to compute the tangent via nearby points. The code relies on the `pathSegList` API and the `pathseg.js` polyfill for compatibility with modern browsers.

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".

Similar vizzes