Skip to content

segmentsIntersect

Checks whether the line segments p1q1 && p2q2 intersect.

True when the two segments share a point. Unlike lineIntersection, the crossing has to fall within both segments’ extents.

import {segmentsIntersect} from "@d3plus/math";

segmentsIntersect([20, 160], [240, 40], [20, 40], [240, 160]);

These segments lie on lines that do meet, but past their ends, so they do not intersect. Network and Sankey layouts use this check to detect overlapping links.

import {segmentsIntersect} from "@d3plus/math";

segmentsIntersect([20, 160], [100, 120], [160, 40], [240, 80]);

Parameters

import {segmentsIntersect} from "@d3plus/math";
p1requiredPoint

The first point of the first line segment, which should always be an [x, y] formatted Array.

q1requiredPoint

The second point of the first line segment, which should always be an [x, y] formatted Array.

p2requiredPoint

The first point of the second line segment, which should always be an [x, y] formatted Array.

q2requiredPoint

The second point of the second line segment, which should always be an [x, y] formatted Array.