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

Curve.getLengths()

Curve.getLengths()方法是three.js库中的一个函数,用于计算曲线上所有点的长度,返回一个包含每一个点的长度之和的数组。

语法

curve.getLengths()

参数

无需输入参数。

返回值

返回一个包含每一个点的长度之和的数组。

描述

Curve.getLengths()方法是用来计算曲线上所有点的长度的。该方法返回一个数组,其中包含每个点之间的距离和,即将整个曲线划分成许多小线段,每个小线段之间的距离和即为该小线段的长度,将所有小线段的长度之和即为曲线长度。

示例

//创建一条贝塞尔曲线
const curve = new THREE.CubicBezierCurve3(
    new THREE.Vector3( -10, 0, 0 ),
    new THREE.Vector3( -5, 15, 0 ),
    new THREE.Vector3( 20, 15, 0 ),
    new THREE.Vector3( 10, 0, 0 )
);

//获取曲线上所有点的长度之和
const lengths = curve.getLengths();

console.log(lengths); // [0, 7.6923076923076925, 15.192307692307693, 23.653846153846153]

参考文献