Maths · function
rayClosestOnLine
The closest approach between a ray and an infinite line, written into out.
Explained in Coordinates and units.
function rayClosestOnLine(origin: ArrayLike<number>, direction: ArrayLike<number>, point: ArrayLike<number>, axis: ArrayLike<number>, out: Float32Array): booleanimport { rayClosestOnLine } from '@driftengine/core';Parameters
| Parameter | Type | Description |
|---|---|---|
origin | ArrayLike<number> | |
direction | ArrayLike<number> | |
point | ArrayLike<number> | |
axis | ArrayLike<number> | |
out | Float32Array |
In depth
out receives three numbers: the ray's parameter, the line's parameter, and the
distance between the two closest points. Three outputs is why this takes a buffer where
everything else in this file returns a number — a caller picking a gizmo handle needs
all three at once, and needs them without allocating on every pointer move.
Returns false for two lines within 1e-6 of parallel, and writes nothing in that
case. There is no closest pair to report: every point on one line is equidistant from
the other, so any answer would be arbitrary, and a caller dragging along the line has to
keep what it had rather than jump to whichever point the arithmetic happened to land on.
direction and axis must both be unit length. That is what makes the returned
parameters distances rather than multiples of two different vectors' lengths.