Sphere

A two dimensional surface that extends infinitely in 3d space, represented in Hessian normal form by a unit length normal vector and a constant.

Math Class

A two dimensional surface that extends infinitely in 3d space, represented in Hessian normal form by a unit length normal vector and a constant.

Constructors

Constructor

new Sphere(center?, radius?): Sphere

Parameters

center?

Vector3

radius?

number

Returns

Sphere

Properties

center

center: Vector3

A Vector3 defining the center of the sphere.

Default Value

(0, 0, 0).


radius

radius: number

The radius of the sphere.

Default Value

0.

Methods

set()

set(center, radius): Sphere

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

Parameters

center

Vector3

center of the sphere.

radius

number

radius of the sphere.

Returns

Sphere


setFromPoints()

setFromPoints(points, optionalCenter?): Sphere

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

Parameters

points

Vector3[]

an array of Vector3 positions.

optionalCenter?

Vector3

Optional Vector3 position for the sphere’s center.

Returns

Sphere


clone()

clone(): Sphere

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

Returns

Sphere


copy()

copy(sphere): Sphere

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

Parameters

sphere

Sphere

Returns

Sphere


empty()

empty(): boolean

If the radius smaller than zero, this will return false, otherwise return true.

Returns

boolean


containsPoint()

containsPoint(point): boolean

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

Parameters

point

Vector3

the Vector3 to be checked.

Returns

boolean


distanceToPoint()

distanceToPoint(point): number

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

Parameters

point

Vector3

Returns

number


intersectsSphere()

intersectsSphere(sphere): boolean

Checks to see if two spheres intersect.

Parameters

sphere

Sphere

Sphere to check for intersection against.

Returns

boolean


intersectsBox()

intersectsBox(box): boolean

Determines whether or not this sphere intersects a given box.

Parameters

box

Box3

Box3 to check for intersection against.

Returns

boolean


intersectsPlane()

intersectsPlane(plane): boolean

Determines whether or not this sphere intersects a given plane.

Parameters

plane

Plane

Plane to check for intersection against.

Returns

boolean


clampPoint()

clampPoint(point, target): 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.

Parameters

point

Vector3

Vector3 The point to clamp.

target

Vector3

the result will be copied into this Vector3.

Returns

Vector3


getBoundingBox()

getBoundingBox(target): Box3

Returns a Minimum Bounding Box for the sphere.

Parameters

target

Box3

the result will be copied into this Box3.

Returns

Box3


applyMatrix4()

applyMatrix4(matrix): Sphere

Transforms this sphere with the provided Matrix4.

Parameters

matrix

Matrix4

the Matrix4 to apply

Returns

Sphere


translate()

translate(offset): Sphere

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

Parameters

offset

Vector3

Returns

Sphere


equals()

equals(sphere): boolean

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

Parameters

sphere

Sphere

Returns

boolean