closestPointToPointParameter method

double closestPointToPointParameter(
  1. Vector3 point, [
  2. bool clampToLine = true
])

Computes a scalar value which represents the closest point on an infinite line defined by the line segment. It's possible to clamp this value so it does not exceed the start and end position of the line segment.

Implementation

double closestPointToPointParameter(Vector3 point, [bool clampToLine = true ]) {
	p1.subVectors( point, from );
	p2.subVectors( to, from );

	final dotP2P2 = p2.dot( p2 );
	final dotP2P1 = p2.dot( p1 );

	double t = dotP2P1 / dotP2P2;

	if ( clampToLine ) t = MathUtils.clamp( t, 0, 1 );

	return t;
}