block by bricof f1f5b4d4bc02cad4dea454a3c5ff8ad7

Path-Line Intersection

Full Screen

This example presents a simple approximate solution to path-line intersection by subdividing the path (via the built-in svg path function .getPointAtLength) into an arbitrary number of straight line segments and testing for line-line intersections at each one. A more accurate solution would be to similarly walk through segments of the path, but instead using the points specified in the path’s d definition, and computing the intersections with the lines, Bezier curves and arcs - that approach is forthcoming in another future example. See also Mike Bostock’s related example on Line Segment Intersection.

The moveable intersecting line is based on this block.

For uses of this functionality, see the Path-Line Reflection and Bottled Gas Animation blocks.