mesh.rayHits

Every crossing of a ray with the mesh, with the inside and gap spans between them: wall thickness and clearance.

GeometricSince 0.5.0

Usage

TypeScript
mesh.rayHits(ray: Ray): RayHits

Parameters

  • rayRay

    Origin and direction (any non-zero length; t is in units of it). Required. In model.

Returns

{ hits: [{ t, point, face, normal, entering, grazing? }] sorted by t (t ≥ 0), spans: [{ t0, t1, length, kind: "inside" | "gap", across? }], startsInside }.

Guarantees

  • a 3 mm wall measures 0.003 to about 1e-11 at the origin, near x = 4.5e5 and at micrometre scale (span length)
  • a ray through an edge or corner several faces share is one hit; when those faces disagree on entering it is grazing and stays out of spans
  • across equals the wall thickness for an oblique ray when the faces at both ends are parallel
  • The same result on every machine.

Example

TypeScript
const wall = Mesh.box(Vector3.of(0.003, 1, 1)).value
wall.rayHits(Ray.of(Point3.of(-1, 0.1, 0.2), Vector3.of(1, 0, 0))).spans[0].length // → 0.003

See also