The 3D point to test as a Vector3Tuple [x, y, z]
The BufferGeometry representing the closed polyhedron
A PointInPolyhedronResult with the test result
The geometry must represent a closed (watertight) surface for accurate results. Open surfaces or surfaces with holes may produce incorrect results.
import { isPointInPolyhedron } from '@wendylabsinc/react-three-map/maplibre';
import { BoxGeometry } from 'three';
const box = new BoxGeometry(100, 100, 100);
const pointInside: Vector3Tuple = [10, 10, 10];
const pointOutside: Vector3Tuple = [200, 200, 200];
isPointInPolyhedron(pointInside, box).inside; // true
isPointInPolyhedron(pointOutside, box).inside; // false
Tests whether a 3D point is inside a closed polyhedron using ray casting.
This implements the ray casting algorithm: cast a ray from the point in an arbitrary direction and count how many times it intersects the surface. If the count is odd, the point is inside; if even, it's outside.