Line3.closestPointToPointParameter()
方法用于计算一个给定点到三维空间中的直线的最近点的参数化位置。
closestPointToPointParameter(point: Vector3, clampToLine: boolean, optionalTarget: Vector3): number
point
:Vector3
类型,表示要查找最近点的目标点。clampToLine
:boolean
类型,表示是否将最近点限制在直线的端点之间。默认值为 false
。optionalTarget
:Vector3
类型,表示可选的用于存储结果的向量。number
:最近点在直线上的参数化位置。const line = new THREE.Line3(new THREE.Vector3(0, 0, 0), new THREE.Vector3(1, 0, 0));
const targetPoint = new THREE.Vector3(0.5, 1, 0);
const closestPointParameter = line.closestPointToPointParameter(targetPoint);
const closestPoint = new THREE.Vector3();
line.closestPointToPoint(targetPoint, closestPoint); // 可选,用于确认结果是否正确
closestPointToPointParameter
方法只计算最近点在直线上的参数化位置,如果需要获取最近点的位置向量,需要使用 closestPointToPoint
方法或手动计算(参考代码示例)。