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

Box2.distanceToPoint() 方法用于计算一个 Vector2Box2 中最近点的距离。

语法:

distanceToPoint( point: Vector2 ): Number

参数:

  • point : Vector2类型表示要计算距离的点。

返回值:

  • Number类型表示点到 Box2 中最近点的距离。

示例:

import { Box2, Vector2 } from 'three';

const box = new Box2(new Vector2(-10, -10), new Vector2(10, 10));
const point = new Vector2(5, 5);
const distance = box.distanceToPoint(point);

console.log(`The distance between (${point.x}, ${point.y}) and the box is ${distance}.`);
// The distance between (5, 5) and the box is 0.

注:

Box2 的最小和最大坐标必须在适当的轴上进行设置,例如:

// 设置一个 "x" 和 "y" 轴的范围
const box = new Box2(new Vector2(-10, -10), new Vector2(10, 10));

// 设置一个 "y" 和 "z" 轴的范围
const box = new Box2(new Vector2(0, -10), new Vector2(0, 10));

如果 Box2 中的点与参数 point 重合,则返回值为 0

参考