Skip to main content

Sphere

Bounding sphere stored as [x, y, z, radius]. Functions modify the first argument in-place unless noted.


Functions Reference

Creation

FunctionReturnsDescription
sphere_create(center, r)ArrayCreates a new sphere (defaults to [0,0,0,-1]).
sphere_set(s, center, r)-Sets center and radius.
sphere_clone(s)ArrayReturns a copy of the sphere.
sphere_copy(s, src)-Copies values from src.
sphere_equals(a, b)booleanReturns true if spheres are identical.

Operations

FunctionReturnsDescription
sphere_apply_matrix4(s, m)-Transforms center by matrix and scales radius by max axis scale.
sphere_contains_point(s, point)booleanTrue if point is inside or on the sphere.
sphere_intersects_sphere(a, b)booleanTrue if spheres intersect.
sphere_distance_to_point(s, point)numberDistance from surface to point (negative if inside).
sphere_clamp_point(s, point, out?)ArrayClamps a point to sphere boundary; returns out or new vec.
sphere_expand_by_point(s, point)-Expands radius to include point; fixes center if empty.
sphere_is_empty(s)booleanTrue if radius < 0.
sphere_make_empty(s)-Sets center [0,0,0], radius -1.
sphere_translate(s, offset)-Offsets center.
sphere_get_bounding_box(s, out?)Box3Returns/sets box enclosing sphere.
sphere_intersects_box(s, box)booleanTrue if sphere intersects box.
sphere_intersects_plane(s, plane)booleanTrue if abs(distance(center,plane)) <= radius.
sphere_union(s, other)SphereExpands s to enclose both spheres.
sphere_set_from_points(s, points, optionalCenter?)SphereMinimal sphere from points; uses optional center if provided.

Usage Examples

var s = sphere_create(0, 0, 0, 5);
var inside = sphere_contains_point(s, 3, 4, 0); // true