polygonRayCast
Gives the two closest intersection points between a ray cast from a point inside a polygon. The two points should lie on opposite sides of the origin.
Angled ray
Section titled “Angled ray”The third argument is the ray’s angle in radians. At π/4 the two crossings sit on the diagonal through the origin.
import {polygonRayCast} from "@d3plus/math";
const poly = [
[40, 30],
[200, 20],
[250, 100],
[210, 180],
[60, 170],
[20, 90],
];
polygonRayCast(poly, [130, 100], Math.PI / 4);
Basic example
Section titled “Basic example”Casts a line through a point inside the polygon and returns where it meets the edges on either side: the closest crossing to the left of the origin and the closest to the right. With the default angle of 0 the ray is horizontal, which is how a label’s available width at a given height is found.
import {polygonRayCast} from "@d3plus/math";
const poly = [
[40, 30],
[200, 20],
[250, 100],
[210, 180],
[60, 170],
[20, 90],
];
polygonRayCast(poly, [130, 100]);
Parameters
import {polygonRayCast} from "@d3plus/math";