clampPoint method

Vector3 clampPoint(
  1. Vector3 point,
  2. Vector3 result
)

Ensures the given point is inside this bounding sphere and stores the result in the given vector.

Implementation

Vector3 clampPoint( Vector3 point, Vector3 result ) {
	result.copy( point );

	final squaredDistance = center.squaredDistanceTo( point );

	if ( squaredDistance > ( radius * radius ) ) {

		result.sub( center ).normalize();
		result.multiplyScalar( radius ).add(center );

	}

	return result;
}