lineIntersection
Finds the intersection point (if there is one) of the lines p1q1 and p2q2.
Basic example
Section titled “Basic example”Each line is given by two [x, y] points. The result is where the two lines meet; here the segments themselves cross, so the point lies on both.
import {lineIntersection} from "@d3plus/math";
lineIntersection([20, 160], [240, 40], [20, 40], [240, 160]);
Beyond the segments
Section titled “Beyond the segments”The points define infinite lines, not bounded segments, so an intersection is returned even when it falls past the ends of both segments (dashed). Use segmentsIntersect when the segments themselves must cross.
import {lineIntersection} from "@d3plus/math";
lineIntersection([20, 160], [100, 120], [160, 40], [240, 80]);
Parallel
Section titled “Parallel”Parallel (or coincident) lines never meet, so the result is null instead of a point.
import {lineIntersection} from "@d3plus/math";
lineIntersection([20, 60], [240, 60], [20, 140], [240, 140]);
Parameters
import {lineIntersection} from "@d3plus/math";
p1requiredPointThe first point of the first line segment, which should always be an
[x, y]formatted Array.q1requiredPointThe second point of the first line segment, which should always be an
[x, y]formatted Array.p2requiredPointThe first point of the second line segment, which should always be an
[x, y]formatted Array.q2requiredPointThe second point of the second line segment, which should always be an
[x, y]formatted Array.