Table of Contents

Developer Guide

math.gl

@math.gl/culling

@math.gl/geospatial

@math.gl/sun

@math.gl/web-mercator

API Reference

math.gl

@math.gl/culling

@math.gl/polygon

@math.gl/sun

@math.gl/web-mercator

A bounding sphere with a center and a radius.

Create a bounding sphere around the unit cube

```
import {BoundingSphere} from '@math.gl/culling';
cont sphere = new BoundingSphere().fromCornerPoints(
[-0.5, -0.5, -0.5],
[0.5, 0.5, 0.5]
);
```

Sort bounding spheres from back to front

```
import {BoundingSphere} from '@math.gl/culling';
const spheres = [new BoundingSphere(...), new BoundingSphere(...), ...];
const cameraPosWC = ...;
spheres.sort(
(a, b) => b.distanceSquaredTo(b, cameraPosWC) - a.distanceSquaredTo(a.cameraPosWC)
);
```

Computes a tight-fitting bounding sphere enclosing a list of 3D Cartesian points. The bounding sphere is computed by running two algorithms, a naive algorithm and Ritter's algorithm. The smaller of the two spheres is used to ensure a tight fit.

`positions`

An iterable (e.g. array) of points that the bounding sphere will enclose. Each point must have`x`

,`y`

, and`z`

properties.`result`

Optional object onto which to store the result.

Returns

- The modified
`result`

parameter or a new`BoundingSphere`

instance if one was not provided.

See Bounding Sphere computation article

The center point of the sphere.

The radius of the sphere.

Creates a new `BoundingSphere`

`center`

=`[0, 0, 0]`

The center of the bounding sphere.`radius`

=`0.0`

The radius of the bounding sphere.

Sets the `BoundingSphere`

from center and radius

`center`

=`[0, 0, 0]`

The center of the bounding sphere.`radius`

=`0.0`

The radius of the bounding sphere.

Computes a bounding sphere from the two corner points of an axis-aligned bounding box. The sphere tighly and fully encompases the box.

`corner`

The minimum height over the rectangle.`oppositeCorner`

The maximum height over the rectangle.

Computes a tight-fitting bounding sphere enclosing the provided array of bounding spheres.

`boundingSpheres`

The array of bounding spheres.

Returns

- The modified
`result`

parameter or a new`BoundingSphere`

instance if none was provided.

Duplicates a `BoundingSphere`

instance.

Returns

- A new
`BoundingSphere`

instance

Compares the provided `BoundingSphere`

componentwise and returns `true`

if they are equal, `false`

otherwise.

`right`

The second`BoundingSphere`

.

Returns

`true`

if left and right are equal,`false`

otherwise.

Computes a bounding sphere that contains both the this and the `right`

bounding spheres.

`right`

The second`BoundingSphere`

.

Computes a bounding sphere by enlarging the provided sphere to contain the provided point.

`point`

A point to enclose in a bounding sphere.

Determines which side of a plane a sphere is located.

`plane`

The plane to test against. Returns`INTERSECTION.INSIDE`

if the entire sphere is on the side of the plane the normal is pointing`INTERSECTION.OUTSIDE`

if the entire sphere is on the opposite side`INTERSECTION.INTERSECTING`

if the sphere intersects the plane.

Applies a 4x4 affine transformation matrix to a bounding sphere.

`transform`

The transformation matrix to apply to the bounding sphere.

Computes the estimated distance squared from the closest point on a bounding sphere to a point.

`point`

The point

Returns

- The estimated distance squared from the bounding sphere to the point.

Applies a 4x4 affine transformation matrix to a bounding sphere where there is no scale The transformation matrix is not verified to have a uniform scale of 1. This method is faster than computing the general bounding sphere transform using {@link BoundingSphere.transform}.

@param {BoundingSphere} sphere The bounding sphere to apply the transformation to. @param {Matrix4} transform The transformation matrix to apply to the bounding sphere.

`result`

Optional object onto which to store the result.

Returns

- The modified
`result`

parameter or a new`BoundingSphere`

instance if none was provided.

@example var modelMatrix = Transforms.eastNorthUpToFixedFrame(positionOnEllipsoid); var boundingSphere = new BoundingSphere(); var newBoundingSphere = BoundingSphere.transformWithoutScale(boundingSphere, modelMatrix);

The distances calculated by the vector from the center of the bounding sphere to position projected onto direction plus/minus the radius of the bounding sphere.

If you imagine the infinite number of planes with normal direction, this computes the smallest distance to the closest and farthest planes from position that intersect the bounding sphere.

@param {BoundingSphere} sphere The bounding sphere to calculate the distance to. @param {Cartesian3} position The position to calculate the distance from. @param {Cartesian3} direction The direction from position. @param {Interval} [result] A Interval to store the nearest and farthest distances. @returns {Interval} The nearest and farthest distances on the bounding sphere from position in direction.

Creates a bounding sphere in 2D from a bounding sphere in 3D world coordinates.

@param {BoundingSphere} sphere The bounding sphere to transform to 2D. @param {Object} [projection=GeographicProjection] The projection to 2D.

`result`

Optional object onto which to store the result.

Returns

- The modified
`result`

parameter or a new`BoundingSphere`

instance if none was provided.

This class was ported from Cesium under the Apache 2 License.