intersectsBoundingSphere method

bool intersectsBoundingSphere(
  1. BoundingSphere sphere
)

Performs a ray/sphere intersection test. Returns either true or false if there is a intersection or not.

Implementation

bool intersectsBoundingSphere(BoundingSphere sphere ) {
    final v1 = Vector3();
	double squaredDistanceToPoint;

	final directionDistance = v1.subVectors( sphere.center, origin ).dot( direction );

	if ( directionDistance < 0 ) {
		// sphere's center behind the ray
		squaredDistanceToPoint = origin.squaredDistanceTo( sphere.center );
	}
    else {
		v1.copy( direction ).multiplyScalar( directionDistance ).add( origin );
		squaredDistanceToPoint = v1.squaredDistanceTo( sphere.center );
	}


	return squaredDistanceToPoint <= ( sphere.radius * sphere.radius );
}