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

Curve.computeFrenetFrames() 方法用于计算 Curve 上给定位置的切线、法线和副法线。

语法

curve.computeFrenetFrames( segments, closed );

参数

  • segments:定义曲线上切线、法线和副法线的每一段的数量。
  • closed:指定曲线是否是闭合的。

返回值

该方法没有返回值。

异常

该方法不会抛出异常。

用法

import * as THREE from "three";

const curve = new THREE.EllipseCurve(
  0, 0,     // x, y
  10, 5,    // aX, aY
  0, 2 * Math.PI, // aStartAngle, aEndAngle
  false,    // aClockwise
  0         // aRotation
);

curve.computeFrenetFrames(10, false);

console.log(curve.tangents);
console.log(curve.normals);
console.log(curve.binormals);

上述代码使用 EllipseCurve 构造函数创建一个椭圆曲线。然后,调用 computeFrenetFrames() 方法计算曲线上给定位置的切线、法线和副法线。最后,将计算得到的切线、法线和副法线打印到控制台。

示例

以下示例演示如何在场景中绘制一个椭圆,并可视化切线、法线和副法线。

import * as THREE from "three";

const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.z = 50;

const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);

const ellipse = new THREE.EllipseCurve(0, 0, 10, 5, 0, 2 * Math.PI, false, 0);

const segments = 50;
const closed = false;
ellipse.computeFrenetFrames(segments, closed);

const points = ellipse.getPoints(segments);
const geometry = new THREE.BufferGeometry().setFromPoints(points);

const material = new THREE.LineBasicMaterial({color: 0xffffff});
const line = new THREE.Line(geometry, material);
scene.add(line);

for (let i = 0; i < points.length; i++) {
  const tangent = ellipse.tangents[i];
  const normal = ellipse.normals[i];
  const binormal = ellipse.binormals[i];

  const arrowHelperTangent = new THREE.ArrowHelper(tangent, points[i], 2, 0xff0000, 1, 1);
  const arrowHelperNormal = new THREE.ArrowHelper(normal, points[i], 2, 0x00ff00, 1, 1);
  const arrowHelperBinormal = new THREE.ArrowHelper(binormal, points[i], 2, 0x0000ff, 1, 1);

  scene.add(arrowHelperTangent);
  scene.add(arrowHelperNormal);
  scene.add(arrowHelperBinormal);
}

function animate() {
  requestAnimationFrame(animate);
  renderer.render(scene, camera);
}

animate();

上述代码创建了一个场景和相机,并使用 EllipseCurve 构造函数创建一个椭圆曲线。然后,调用 computeFrenetFrames() 方法计算曲线上给定位置的切线、法线和副法线。接下来,使用 getPoints() 方法获取曲线上的所有点,创建一个几何体,并将其添加到场景中。最后,使用 ArrowHelper 工具类可视化每个点处的切线、法线和副法线。

参考资料