Line3.closestPointToPoint( point, clampToLineSegment = false, target = new Vector3() )是在一个三维空间中给出一个线,并在此线上最接近给定点的点。
point(类型: Vector3):要计算的点。clampToLineSegment(类型:Boolean,默认值:false):如果为true,则返回的点将被限制在线段之间(两个端点之间)。target(类型:Vector3,默认值:new Vector3()):用于存储结果的可选向量。Vector3:点在线上的最佳匹配点。
const point = new Vector3( 1, 1, 1 );
const lineStart = new Vector3( 0, 0, 0 );
const lineEnd = new Vector3( 0, 0, 2 );
const line = new Line3( lineStart, lineEnd );
const closestPoint = line.closestPointToPoint( point, true );
// closestPoint is (0, 0, 1)
如果给定点在线段上,则返回给定点。否则返回在线段的端点之一(如果不将clampToLineSegment设置为false的话)。