The Box3.containsPoint(point)
method is used to determine whether a given point is inside or outside the bounding box. This method is a part of the Three.js library, which is a 3D graphics library for creating WebGL-powered applications.
box.containsPoint( point )
point
: An instance of the Vector3
class representing the point to be tested.
A boolean value (true
or false
) representing whether the point is inside or outside of the bounding box.
The Box3.containsPoint()
method is used to test whether a given point lies within the bounding box defined by a Box3
object. The method takes a single parameter, which is an instance of the Vector3
class representing the point to be tested.
const box = new THREE.Box3( new THREE.Vector3( -1, -1, -1 ), new THREE.Vector3( 1, 1, 1 ) );
const pointInside = new THREE.Vector3( 0, 0, 0 );
const pointOutside = new THREE.Vector3( 2, 2, 2 );
console.log( box.containsPoint( pointInside ) ); // true
console.log( box.containsPoint( pointOutside ) ); // false
In this example, we define a new Box3
object that represents a box extending from (-1,-1,-1)
to (1,1,1)
. We then define two points, pointInside
and pointOutside
, and use the containsPoint()
method to test whether each point is inside or outside of the bounding box. The method returns true
for pointInside
, since it lies within the bounding box, and false
for pointOutside
, since it lies outside of the bounding box.
Box3.containsPoint()
method only works with instances of the Vector3
class. If you have a point defined as an array of numbers, you can create a Vector3
object from it using the constructor of the Vector3
class, like so: new THREE.Vector3( x, y, z )
.Box3.intersectsBox()
and Box3.containsBox()
to perform more complex geometric tests on bounding boxes.