playcanvas
Version:
Open-source WebGL/WebGPU 3D engine for the web
61 lines (60 loc) • 2.12 kB
TypeScript
/**
* A bounding sphere is a volume for facilitating fast intersection testing.
*
* @category Math
*/
export class BoundingSphere {
/**
* Creates a new BoundingSphere instance.
*
* @param {Vec3} [center] - The world space coordinate marking the center of the sphere. The
* constructor takes a reference of this parameter.
* @param {number} [radius] - The radius of the bounding sphere. Defaults to 0.5.
* @example
* // Create a new bounding sphere centered on the origin with a radius of 0.5
* const sphere = new pc.BoundingSphere();
*/
constructor(center?: Vec3, radius?: number);
/**
* Center of sphere.
*
* @type {Vec3}
* @readonly
*/
readonly center: Vec3;
/**
* The radius of the bounding sphere.
*
* @type {number}
*/
radius: number;
/**
* Test if a point is inside the sphere.
*
* @param {Vec3} point - Point to test.
* @returns {boolean} True if the point is inside the sphere and false otherwise.
* @example
* const sphere = new pc.BoundingSphere(new pc.Vec3(0, 0, 0), 1);
* const point = new pc.Vec3(0.5, 0, 0);
* const isInside = sphere.containsPoint(point); // true
*/
containsPoint(point: Vec3): boolean;
/**
* Test if a ray intersects with the sphere.
*
* @param {Ray} ray - Ray to test against (direction must be normalized).
* @param {Vec3} [point] - If there is an intersection, the intersection point will be copied
* into here.
* @returns {boolean} True if there is an intersection.
*/
intersectsRay(ray: Ray, point?: Vec3): boolean;
/**
* Test if a Bounding Sphere is overlapping, enveloping, or inside this Bounding Sphere.
*
* @param {BoundingSphere} sphere - Bounding Sphere to test.
* @returns {boolean} True if the Bounding Sphere is overlapping, enveloping, or inside this Bounding Sphere and false otherwise.
*/
intersectsBoundingSphere(sphere: BoundingSphere): boolean;
}
import { Vec3 } from '../math/vec3.js';
import type { Ray } from './ray.js';