Skip to main content

Sphere

A sphere defined by a center and radius.

Constructor

Sphere

function Sphere( center: Vector3, radius: Float ): void;  

center - center of the sphere. Default is a Vector3 at (0, 0, 0).
radius - radius of the sphere. Default is -1.

Creates a new Sphere.

Properties

center

center: Vector3;  

A Vector3 defining the center of the sphere. Default is (0, 0, 0).

radius

radius: Float;  

The radius of the sphere. Default is -1.

Methods

applyMatrix4

function applyMatrix4( matrix: Matrix4 ): this;  

matrix - the [Page:Matrix4] to apply

Transforms this sphere with the provided Matrix4.

clampPoint

function clampPoint( point: Vector3, target: Vector3 ): Vector3;  

point - Vector3 The point to clamp.
target — the result will be copied into this Vector3.

Clamps a point within the sphere. If the point is outside the sphere, it will clamp it to the closest point on the edge of the sphere. Points already inside the sphere will not be affected.

clone

function clone( ): Sphere;  

Returns a new sphere with the same .center and .radius as this one.

containsPoint

function containsPoint( point: Vector3 ): Boolean;  

point - the Vector3 to be checked

Checks to see if the sphere contains the provided point inclusive of the surface of the sphere.

copy

function copy( sphere: Sphere ): this;  

Copies the values of the passed sphere's .center and .radius properties to this sphere.

distanceToPoint

function distanceToPoint( point: Vector3 ): Float;  

Returns the closest distance from the boundary of the sphere to the point. If the sphere contains the point, the distance will be negative.

expandByPoint

function expandByPoint( point: Vector3 ): this;  

point - Vector3 that should be included in the sphere.

Expands the boundaries of this sphere to include point.

isEmpty

function isEmpty( ): Boolean;  

Checks to see if the sphere is empty (the radius set to a negative number).
Spheres with a radius of 0 contain only their center point and are not considered to be empty.

makeEmpty

function makeEmpty( ): this;  

Makes the sphere empty by setting .center to (0, 0, 0) and .radius to -1.

equals

function equals( sphere: Sphere ): Boolean;  

Checks to see if the two spheres' centers and radii are equal.

getBoundingBox

function getBoundingBox( target: Box3 ): Box3;  

target — the result will be copied into this Box3.

Returns aMinimum Bounding Box for the sphere.

intersectsBox

function intersectsBox( box: Box3 ): Boolean;  

box - Box3 to check for intersection against.

Determines whether or not this sphere intersects a given box.

intersectsPlane

function intersectsPlane( plane: Plane ): Boolean;  

plane - Plane to check for intersection against.

Determines whether or not this sphere intersects a given plane.

intersectsSphere

function intersectsSphere( sphere: Sphere ): Boolean;  

sphere - Sphere to check for intersection against.

Checks to see if two spheres intersect.

set

function set( center: Vector3, radius: Float ): this;  

center - center of the sphere.
radius - radius of the sphere.

Sets the .center and .radius properties of this sphere.
Please note that this method only copies the values from the given center.

setFromPoints

function setFromPoints( points: Array, optionalCenter: Vector3 ): this;  

points - an Array of Vector3 positions.
optionalCenter - Optional Vector3 position for the sphere's center.

Computes the minimum bounding sphere for an array of points. If optionalCenteris given, it is used as the sphere's center. Otherwise, the center of the axis-aligned bounding box encompassing points is calculated.

translate

function translate( offset: Vector3 ): this;  

Translate the sphere's center by the provided offset Vector3.

union

function union( sphere: Sphere ): this;  

sphere - Bounding sphere that will be unioned with this sphere.

Expands this sphere to enclose both the original sphere and the given sphere.

Source

src/math/Sphere.js