BoundingSphere
A bounding sphere with a center and a radius.
Usage
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)
);
Inheritance
class BoundingSphere implements BoundingVolume.
Global Functions
makeBoundingSphereFromPoints(positions : iterator, result? : BoundingSphere) : BoundingSphere
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.
positionsAn iterable (e.g. array) of points that the bounding sphere will enclose. Each point must havex,y, andzproperties.resultOptional object onto which to store the result.
Returns
- The modified
resultparameter or a newBoundingSphereinstance if one was not provided.
See Bounding Sphere computation article
Fields
center : Vector3
The center point of the sphere.
radius : Number
The radius of the sphere.
Members
constructor(center : Number[3], radius : Number)
Creates a new BoundingSphere
center=[0, 0, 0]The center of the bounding sphere.radius=0.0The radius of the bounding sphere.
fromCenterRadius(center : Number[3], radius : Number) : BoundingSphere
Sets the BoundingSphere from center and radius
center=[0, 0, 0]The center of the bounding sphere.radius=0.0The radius of the bounding sphere.
fromCornerPoints(corner : Number[3], oppositeCorner : Number[3], result? : BoundingSphere) : BoundingSphere
Computes a bounding sphere from the two corner points of an axis-aligned bounding box. The sphere tighly and fully encompases the box.
cornerThe minimum height over the rectangle.oppositeCornerThe maximum height over the rectangle.
fromBoundingSpheres(boundingSpheres : BoundingSphere[]) : BoundingSphere
Computes a tight-fitting bounding sphere enclosing the provided array of bounding spheres.
boundingSpheresThe array of bounding spheres.
Returns
- The modified
resultparameter or a newBoundingSphereinstance if none was provided.
clone()
Duplicates a BoundingSphere instance.
Returns
- A new
BoundingSphereinstance
equals(right : BoundingSphere) Boolean
Compares the provided BoundingSphere componentwise and returns true if they are equal, false otherwise.
rightThe secondBoundingSphere.
Returns
trueif left and right are equal,falseotherwise.
union(right : BoundingSphere) : BoundingSphere
Computes a bounding sphere that contains both the this and the right bounding spheres.
rightThe secondBoundingSphere.
expand(point : Number[3]) : BoundingSphere
Computes a bounding sphere by enlarging the provided sphere to contain the provided point.
pointA point to enclose in a bounding sphere.
intersectPlane(plane : Plane) : INTERSECTION
Determines which side of a plane a sphere is located.
planeThe plane to test against. ReturnsINTERSECTION.INSIDEif the entire sphere is on the side of the plane the normal is pointingINTERSECTION.OUTSIDEif the entire sphere is on the opposite sideINTERSECTION.INTERSECTINGif the sphere intersects the plane.
transform(transform : Number[16]) : BoundingSphere
Applies a 4x4 affine transformation matrix to a bounding sphere.
transformThe transformation matrix to apply to the bounding sphere.
distanceSquaredTo(point) : Number
Computes the estimated distance squared from the closest point on a bounding sphere to a point.
pointThe point
Returns
- The estimated distance squared from the bounding sphere to the point.
transformWithoutScale(sphere, transform, result)
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 BoundingSphere.transform.
-
BoundingSphere sphere The bounding sphere to apply the transformation to.
-
Matrix4 transform The transformation matrix to apply to the bounding sphere.
-
resultOptional object onto which to store the result.
Returns
- The modified
resultparameter or a newBoundingSphereinstance if none was provided.
@example var modelMatrix = Transforms.eastNorthUpToFixedFrame(positionOnEllipsoid); var boundingSphere = new BoundingSphere(); var newBoundingSphere = BoundingSphere.transformWithoutScale(boundingSphere, modelMatrix);
computePlaneDistances (sphere, position, direction, result)
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.
BoundingSpheresphereThe bounding sphere to calculate the distance to.Cartesian3positionThe position to calculate the distance from.Cartesian3directionThe direction from position.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.
projectTo2D(sphere, projection, result)
Creates a bounding sphere in 2D from a bounding sphere in 3D world coordinates.
-
BoundingSpheresphere The bounding sphere to transform to 2D. -
Object[projection=GeographicProjection] The projection to 2D. -
resultOptional object onto which to store the result.
Returns
- The modified
resultparameter or a newBoundingSphereinstance if none was provided.
Attribution
This class was ported from Cesium under the Apache 2 License.