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.containsPoint()

Box2.containsPoint(v: Vector2): boolean

Box2containsPoint()方法用于判断一个二维点(Vector2)是否在这个矩形框内,返回布尔值。

参数

v(Vector2类型) - 二维点向量

返回值

返回一个布尔值,表示点是否在矩形框内。

示例

const box = new THREE.Box2(new THREE.Vector2(0, 0), new THREE.Vector2(10, 10));

const point1 = new THREE.Vector2(5, 5);
const isInside1 = box.containsPoint(point1); // true

const point2 = new THREE.Vector2(11, 11);
const isInside2 = box.containsPoint(point2); // false

注意事项

Box2的两个参数分别是代表左上角和右下角的向量,一定要注意它们的顺序,否则会得到错误的结果。因此,最好始终将左上角的向量放在第一个参数中,右下角的向量放在第二个参数中。

此外,Box2内的矩形边界是闭合的,如果希望判断点是否在矩形框内,并且不包括边界,则可以使用Box2.containsPoint()方法后,再用Box2.intersectsBox()方法判断是否与矩形框相交。