# BoundingSphere

Class · category: Math

Source: https://github.com/playcanvas/engine/blob/b5b983982a9860d21e0c1dafb2f85f72e2c01afb/src/core/shape/bounding-sphere.js#L16

A bounding sphere is a volume for facilitating fast intersection testing.

## Constructors

### constructor

```ts
new BoundingSphere(center?: Vec3, radius?: number)
```

Creates a new BoundingSphere instance.

**Parameters**

- `center` ([`Vec3`](https://api.playcanvas.com/engine/classes/Vec3.md), optional): The world space coordinate marking the center of the sphere. The
  constructor takes a reference of this parameter.
- `radius` (`number`, optional, default `0.5`): The radius of the bounding sphere. Defaults to 0.5.

**Example**

```ts
// Create a new bounding sphere centered on the origin with a radius of 0.5
const sphere = new BoundingSphere();
```

## Properties

### center

```ts
readonly center: Vec3
```

Center of sphere.

### radius

```ts
radius: number
```

The radius of the bounding sphere.

## Methods

### containsPoint

```ts
containsPoint(point: Vec3): boolean
```

Test if a point is inside the sphere.

**Parameters**

- `point` ([`Vec3`](https://api.playcanvas.com/engine/classes/Vec3.md)): Point to test.

**Returns** `boolean`: True if the point is inside the sphere and false otherwise.

**Example**

```ts
const sphere = new BoundingSphere(new Vec3(0, 0, 0), 1);
const point = new Vec3(0.5, 0, 0);
const isInside = sphere.containsPoint(point); // true
```

### intersectsBoundingSphere

```ts
intersectsBoundingSphere(sphere: BoundingSphere): boolean
```

Test if a Bounding Sphere is overlapping, enveloping, or inside this Bounding Sphere.

**Parameters**

- `sphere` ([`BoundingSphere`](https://api.playcanvas.com/engine/classes/BoundingSphere.md)): Bounding Sphere to test.

**Returns** `boolean`: True if the Bounding Sphere is overlapping, enveloping, or inside this Bounding Sphere and false otherwise.

### intersectsRay

```ts
intersectsRay(ray: Ray, point?: Vec3): boolean
```

Test if a ray intersects with the sphere.

**Parameters**

- `ray` ([`Ray`](https://api.playcanvas.com/engine/classes/Ray.md)): Ray to test against (direction must be normalized).
- `point` ([`Vec3`](https://api.playcanvas.com/engine/classes/Vec3.md), optional): If there is an intersection, the intersection point will be copied
  into here.

**Returns** `boolean`: True if there is an intersection.
