Sphere

class Sphere(val center: Vector3 = Vector3(), var radius: Double = -1.0)

An analytical 3D sphere defined by a center and radius. This class is mainly used as a Bounding Sphere for 3D objects.

The sphere is mutable and not thread-safe; confine an instance (and any object graph holding it) to a single thread, exactly as in three.js.

The constructor stores the given center by reference (it does not copy it). Sharing that vector with another object means later mutations are visible through every alias; use set or clone for independent storage.

A sphere with a negative radius is considered empty (see isEmpty); a radius of 0 contains only the center point and is not empty.

Constructors

Link copied to clipboard
constructor(center: Vector3 = Vector3(), radius: Double = -1.0)

Properties

Link copied to clipboard

The center of the sphere.

Link copied to clipboard

The radius of the sphere.

Functions

Link copied to clipboard

Transforms this sphere with the given 4x4 transformation matrix matrix.

Link copied to clipboard
fun clampPoint(point: Vector3, target: Vector3): Vector3

Clamps a point within the sphere, writing the result into target. If the point is outside the sphere, it is clamped to the closest point on the edge of the sphere. Points already inside the sphere are not affected.

Link copied to clipboard
fun clone(): Sphere

Returns a new sphere with copied values from this instance.

Link copied to clipboard

Returns true if this sphere contains the given point inclusive of the surface of the sphere.

Link copied to clipboard
fun copy(sphere: Sphere): Sphere

Copies the values of the given sphere sphere to this instance.

Link copied to clipboard

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

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean

Structural equality: true when other is a Sphere with an equal center (via Vector3.equals) and an equal radius (primitive ==, so NaN != NaN).

Link copied to clipboard

Expands the boundaries of this sphere to include the given point.

Link copied to clipboard

Sets this sphere from json laid out as [centerX, centerY, centerZ, radius].

Link copied to clipboard
fun getBoundingBox(target: Box3): Box3

Writes a bounding box that encloses this sphere into target.

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard

Returns true if this sphere intersects with the given box.

Link copied to clipboard

Returns true if this sphere intersects with the given plane.

Link copied to clipboard

Returns true if this sphere intersects with the given one sphere.

Link copied to clipboard

Returns true if the sphere is empty (the radius set to a negative number).

Link copied to clipboard

Makes this sphere empty which means it encloses a zero space in 3D.

Link copied to clipboard
fun set(center: Vector3, radius: Double): Sphere

Sets the sphere's components by copying the given values.

Link copied to clipboard
fun setFromPoints(points: List<Vector3>, optionalCenter: Vector3? = null): Sphere

Computes the minimum bounding sphere for a list of points. If the optional optionalCenter is given, it is used as the sphere's center. Otherwise, the center of the axis-aligned bounding box encompassing the points is calculated.

Link copied to clipboard

Writes this sphere as [centerX, centerY, centerZ, radius].

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
fun translate(offset: Vector3): Sphere

Translates the sphere's center by the given offset.

Link copied to clipboard
fun union(sphere: Sphere): Sphere

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