BufferGeometry
Object3D
Raycaster
Camera
CubeCamera
PerspectiveCamera
OrthographicCamera
StereoCamera
Clock
Curve
CurvePath
Path
Shape
ShapePath
ArrowHelper
AxesHelper
BoxHelper
Box3Helper
CameraHelper
DirectionalLightHelper
GridHelper
PolarGridHelper
HemisphereLightHelper
PlaneHelper
PointLightHelper
SkeletonHelper
SpotLightHelper
Light
PointLight
RectAreaLight
SpotLight
DirectionalLight
HemisphereLight
LightShadow
PointLightShadow
AnimationLoader
AudioLoader
BufferGeometryLoader
CompressedTextureLoader
CubeTextureLoader
DataTextureLoader
FileLoader
ImageBitmapLoader
ImageLoader
Loader
LoaderUtils
MaterialLoader
ObjectLoader
TextureLoader
LoadingManager
Material
Box2
Box3
Color
Cylindrical
Euler
Frustum
Interpolant
Line3
MathUtils
Matrix3
Matrix4
Plane
Quaternion
AnimationAction
AnimationClip
AnimationMixer
AnimationObjectGroup
AnimationUtils
keyframeTrack
PropertyBinding
PropertyMixer
BooleanKeyframeTrack
QuaternionKeyframeTrack
StringKeyframeTrack
Audio
AudioAnalyser
AudioContext
AudioListener
PositionalAudio

Box2.intersect()

The Box2.intersect() function is used in Three.js to check if two 2D boxes intersect each other (i.e., if they overlap). This function takes two instances of the Three.js Box2 class as input parameters and returns a Boolean value indicating whether the two boxes intersect or not.

Box2.intersect(box1, box2)

Parameters

  • box1: An instance of the Box2 class representing the first box.
  • box2: An instance of the Box2 class representing the second box.

Return Value

This function returns a Boolean value:

  • true: If the two boxes intersect.
  • false: If the two boxes do not intersect.

How it Works

The Box2.intersect() function determines if two boxes intersect by checking if the areas of the boxes overlap. In other words, if the two boxes share any common space, then they intersect.

Box2 Intersect Diagram

The Box2.intersect() function compares the maximum and minimum values of the X and Y coordinates of the two boxes to make this determination. If any of these maximum or minimum values overlap, then the two boxes intersect.

Example

var box1 = new THREE.Box2(new THREE.Vector2(0, 0), new THREE.Vector2(10, 10));
var box2 = new THREE.Box2(new THREE.Vector2(5, 5), new THREE.Vector2(15, 15));

if (box1.intersectsBox(box2)) {
    console.log("The two boxes intersect.");
} else {
    console.log("The two boxes do not intersect.");
}

In this example, we create two 2D boxes: box1 with coordinates (0, 0) and (10, 10), and box2 with coordinates (5, 5) and (15, 15). Since these two boxes intersect, the Box2.intersect() function would return true and print "The two boxes intersect." to the console.