Skip to content

KBE3D / KBCore / Cesium / BoundingSphere

类: BoundingSphere

A bounding sphere with a center and a radius.

参数

The center of the bounding sphere.

参数

The radius of the bounding sphere.

属性

packedLength

static packedLength: number

The number of elements used to pack the object into an array.


center

center: Cartesian3

The center point of the sphere.


radius

radius: number

The radius of the sphere.

方法

fromPoints()

static fromPoints(positions?: Cartesian3[], 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.

参数

positions?

Cartesian3[]

An array of points that the bounding sphere will enclose. Each point must have <code>x</code>, <code>y</code>, and <code>z</code> properties.

result?

BoundingSphere

The object onto which to store the result.

返回

BoundingSphere

The modified result parameter or a new BoundingSphere instance if one was not provided.


fromRectangle2D()

static fromRectangle2D(rectangle?: Rectangle, projection?: any, result?: BoundingSphere): BoundingSphere

Computes a bounding sphere from a rectangle projected in 2D.

参数

rectangle?

Rectangle

The rectangle around which to create a bounding sphere.

projection?

any

The projection used to project the rectangle into 2D.

result?

BoundingSphere

The object onto which to store the result.

返回

BoundingSphere

The modified result parameter or a new BoundingSphere instance if none was provided.


fromRectangleWithHeights2D()

static fromRectangleWithHeights2D(rectangle?: Rectangle, projection?: any, minimumHeight?: number, maximumHeight?: number, result?: BoundingSphere): BoundingSphere

Computes a bounding sphere from a rectangle projected in 2D. The bounding sphere accounts for the object's minimum and maximum heights over the rectangle.

参数

rectangle?

Rectangle

The rectangle around which to create a bounding sphere.

projection?

any

The projection used to project the rectangle into 2D.

minimumHeight?

number

The minimum height over the rectangle.

maximumHeight?

number

The maximum height over the rectangle.

result?

BoundingSphere

The object onto which to store the result.

返回

BoundingSphere

The modified result parameter or a new BoundingSphere instance if none was provided.


fromRectangle3D()

static fromRectangle3D(rectangle?: Rectangle, ellipsoid?: Ellipsoid, surfaceHeight?: number, result?: BoundingSphere): BoundingSphere

Computes a bounding sphere from a rectangle in 3D. The bounding sphere is created using a subsample of points on the ellipsoid and contained in the rectangle. It may not be accurate for all rectangles on all types of ellipsoids.

参数

rectangle?

Rectangle

The valid rectangle used to create a bounding sphere.

ellipsoid?

Ellipsoid

The ellipsoid used to determine positions of the rectangle.

surfaceHeight?

number

The height above the surface of the ellipsoid.

result?

BoundingSphere

The object onto which to store the result.

返回

BoundingSphere

The modified result parameter or a new BoundingSphere instance if none was provided.


fromVertices()

static fromVertices(positions?: number[], center?: Cartesian3, stride?: number, result?: BoundingSphere): BoundingSphere

Computes a tight-fitting bounding sphere enclosing a list of 3D points, where the points are stored in a flat array in X, Y, Z, order. 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?

number[]

An array of points that the bounding sphere will enclose. Each point is formed from three elements in the array in the order X, Y, Z.

center?

Cartesian3

The position to which the positions are relative, which need not be the origin of the coordinate system. This is useful when the positions are to be used for relative-to-center (RTC) rendering.

stride?

number

The number of array elements per vertex. It must be at least 3, but it may be higher. Regardless of the value of this parameter, the X coordinate of the first position is at array index 0, the Y coordinate is at array index 1, and the Z coordinate is at array index 2. When stride is 3, the X coordinate of the next position then begins at array index 3. If the stride is 5, however, two array elements are skipped and the next position begins at array index 5.

result?

BoundingSphere

The object onto which to store the result.

返回

BoundingSphere

The modified result parameter or a new BoundingSphere instance if one was not provided.

示例

ts
// Compute the bounding sphere from 3 positions, each specified relative to a center.
// In addition to the X, Y, and Z coordinates, the points array contains two additional
// elements per point which are ignored for the purpose of computing the bounding sphere.
const center = new Cesium.Cartesian3(1.0, 2.0, 3.0);
const points = [1.0, 2.0, 3.0, 0.1, 0.2,
              4.0, 5.0, 6.0, 0.1, 0.2,
              7.0, 8.0, 9.0, 0.1, 0.2];
const sphere = Cesium.BoundingSphere.fromVertices(points, center, 5);

fromEncodedCartesianVertices()

static fromEncodedCartesianVertices(positionsHigh?: number[], positionsLow?: number[], result?: BoundingSphere): BoundingSphere

Computes a tight-fitting bounding sphere enclosing a list of EncodedCartesian3s, where the points are stored in parallel flat arrays in X, Y, Z, order. 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.

参数

positionsHigh?

number[]

An array of high bits of the encoded cartesians that the bounding sphere will enclose. Each point is formed from three elements in the array in the order X, Y, Z.

positionsLow?

number[]

An array of low bits of the encoded cartesians that the bounding sphere will enclose. Each point is formed from three elements in the array in the order X, Y, Z.

result?

BoundingSphere

The object onto which to store the result.

返回

BoundingSphere

The modified result parameter or a new BoundingSphere instance if one was not provided.


fromCornerPoints()

static fromCornerPoints(corner?: Cartesian3, oppositeCorner?: Cartesian3, result?: BoundingSphere): BoundingSphere

Computes a bounding sphere from the corner points of an axis-aligned bounding box. The sphere tightly and fully encompasses the box.

参数

corner?

Cartesian3

The minimum height over the rectangle.

oppositeCorner?

Cartesian3

The maximum height over the rectangle.

result?

BoundingSphere

The object onto which to store the result.

返回

BoundingSphere

The modified result parameter or a new BoundingSphere instance if none was provided.

示例

ts
// Create a bounding sphere around the unit cube
const sphere = Cesium.BoundingSphere.fromCornerPoints(new Cesium.Cartesian3(-0.5, -0.5, -0.5), new Cesium.Cartesian3(0.5, 0.5, 0.5));

fromEllipsoid()

static fromEllipsoid(ellipsoid: Ellipsoid, result?: BoundingSphere): BoundingSphere

Creates a bounding sphere encompassing an ellipsoid.

参数

ellipsoid

Ellipsoid

The ellipsoid around which to create a bounding sphere.

result?

BoundingSphere

The object onto which to store the result.

返回

BoundingSphere

The modified result parameter or a new BoundingSphere instance if none was provided.

示例

ts
const boundingSphere = Cesium.BoundingSphere.fromEllipsoid(ellipsoid);

fromBoundingSpheres()

static fromBoundingSpheres(boundingSpheres?: BoundingSphere[], result?: BoundingSphere): BoundingSphere

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

参数

boundingSpheres?

BoundingSphere[]

The array of bounding spheres.

result?

BoundingSphere

The object onto which to store the result.

返回

BoundingSphere

The modified result parameter or a new BoundingSphere instance if none was provided.


fromOrientedBoundingBox()

static fromOrientedBoundingBox(orientedBoundingBox: OrientedBoundingBox, result?: BoundingSphere): BoundingSphere

Computes a tight-fitting bounding sphere enclosing the provided oriented bounding box.

参数

orientedBoundingBox

OrientedBoundingBox

The oriented bounding box.

result?

BoundingSphere

The object onto which to store the result.

返回

BoundingSphere

The modified result parameter or a new BoundingSphere instance if none was provided.


fromTransformation()

static fromTransformation(transformation: Matrix4, result?: BoundingSphere): BoundingSphere

Computes a tight-fitting bounding sphere enclosing the provided affine transformation.

参数

transformation

Matrix4

The affine transformation.

result?

BoundingSphere

The object onto which to store the result.

返回

BoundingSphere

The modified result parameter or a new BoundingSphere instance if none was provided.


clone()

static clone(sphere: BoundingSphere, result?: BoundingSphere): BoundingSphere

Duplicates a BoundingSphere instance.

参数

sphere

BoundingSphere

The bounding sphere to duplicate.

result?

BoundingSphere

The object onto which to store the result.

返回

BoundingSphere

The modified result parameter or a new BoundingSphere instance if none was provided. (Returns undefined if sphere is undefined)


pack()

static pack(value: BoundingSphere, array: number[], startingIndex?: number): number[]

Stores the provided instance into the provided array.

参数

value

BoundingSphere

The value to pack.

array

number[]

The array to pack into.

startingIndex?

number

The index into the array at which to start packing the elements.

返回

number[]

The array that was packed into


unpack()

static unpack(array: number[], startingIndex?: number, result?: BoundingSphere): BoundingSphere

Retrieves an instance from a packed array.

参数

array

number[]

The packed array.

startingIndex?

number

The starting index of the element to be unpacked.

result?

BoundingSphere

The object into which to store the result.

返回

BoundingSphere

The modified result parameter or a new BoundingSphere instance if one was not provided.


union()

static union(left: BoundingSphere, right: BoundingSphere, result?: BoundingSphere): BoundingSphere

Computes a bounding sphere that contains both the left and right bounding spheres.

参数

left

BoundingSphere

A sphere to enclose in a bounding sphere.

BoundingSphere

A sphere to enclose in a bounding sphere.

result?

BoundingSphere

The object onto which to store the result.

返回

BoundingSphere

The modified result parameter or a new BoundingSphere instance if none was provided.


expand()

static expand(sphere: BoundingSphere, point: Cartesian3, result?: BoundingSphere): BoundingSphere

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

参数

sphere

BoundingSphere

A sphere to expand.

point

Cartesian3

A point to enclose in a bounding sphere.

result?

BoundingSphere

The object onto which to store the result.

返回

BoundingSphere

The modified result parameter or a new BoundingSphere instance if none was provided.


intersectPlane()

static intersectPlane(sphere: BoundingSphere, plane: Plane): Intersect

Determines which side of a plane a sphere is located.

参数

sphere

BoundingSphere

The bounding sphere to test.

plane

Plane

The plane to test against.

返回

Intersect

Intersect.INSIDE if the entire sphere is on the side of the plane the normal is pointing, Intersect.OUTSIDE if the entire sphere is on the opposite side, and Intersect.INTERSECTING if the sphere intersects the plane.


transform()

static transform(sphere: BoundingSphere, transform: Matrix4, result?: BoundingSphere): BoundingSphere

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

参数

sphere

BoundingSphere

The bounding sphere to apply the transformation to.

transform

Matrix4

The transformation matrix to apply to the bounding sphere.

result?

BoundingSphere

The object onto which to store the result.

返回

BoundingSphere

The modified result parameter or a new BoundingSphere instance if none was provided.


distanceSquaredTo()

static distanceSquaredTo(sphere: BoundingSphere, cartesian: Cartesian3): number

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

参数

sphere

BoundingSphere

The sphere.

cartesian

Cartesian3

The point

返回

number

The distance squared from the bounding sphere to the point. Returns 0 if the point is inside the sphere.

示例

ts
// Sort bounding spheres from back to front
spheres.sort(function(a, b) {
    return Cesium.BoundingSphere.distanceSquaredTo(b, camera.positionWC) - Cesium.BoundingSphere.distanceSquaredTo(a, camera.positionWC);
});

transformWithoutScale()

static transformWithoutScale(sphere: BoundingSphere, transform: Matrix4, result?: BoundingSphere): BoundingSphere

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.

参数

sphere

BoundingSphere

The bounding sphere to apply the transformation to.

transform

Matrix4

The transformation matrix to apply to the bounding sphere.

result?

BoundingSphere

The object onto which to store the result.

返回

BoundingSphere

The modified result parameter or a new BoundingSphere instance if none was provided.

示例

ts
const modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(positionOnEllipsoid);
const boundingSphere = new Cesium.BoundingSphere();
const newBoundingSphere = Cesium.BoundingSphere.transformWithoutScale(boundingSphere, modelMatrix);

computePlaneDistances()

static computePlaneDistances(sphere: BoundingSphere, position: Cartesian3, direction: Cartesian3, result?: Interval): Interval

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. <br> 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.

参数

sphere

BoundingSphere

The bounding sphere to calculate the distance to.

position

Cartesian3

The position to calculate the distance from.

direction

Cartesian3

The direction from position.

result?

Interval

A Interval to store the nearest and farthest distances.

返回

Interval

The nearest and farthest distances on the bounding sphere from position in direction.


projectTo2D()

static projectTo2D(sphere: BoundingSphere, projection?: any, result?: BoundingSphere): BoundingSphere

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

参数

sphere

BoundingSphere

The bounding sphere to transform to 2D.

projection?

any

The projection to 2D.

result?

BoundingSphere

The object onto which to store the result.

返回

BoundingSphere

The modified result parameter or a new BoundingSphere instance if none was provided.


isOccluded()

static isOccluded(sphere: BoundingSphere, occluder: Occluder): boolean

Determines whether or not a sphere is hidden from view by the occluder.

参数

sphere

BoundingSphere

The bounding sphere surrounding the occluded object.

occluder

Occluder

The occluder.

返回

boolean

true if the sphere is not visible; otherwise false.


equals()

static equals(left?: BoundingSphere, right?: BoundingSphere): boolean

Compares the provided BoundingSphere componentwise and returns <code>true</code> if they are equal, <code>false</code> otherwise.

参数

left?

BoundingSphere

The first BoundingSphere.

right?

BoundingSphere

The second BoundingSphere.

返回

boolean

true if left and right are equal, false otherwise.


intersectPlane()

intersectPlane(plane: Plane): Intersect

Determines which side of a plane the sphere is located.

参数

plane

Plane

The plane to test against.

返回

Intersect

Intersect.INSIDE if the entire sphere is on the side of the plane the normal is pointing, Intersect.OUTSIDE if the entire sphere is on the opposite side, and Intersect.INTERSECTING if the sphere intersects the plane.


distanceSquaredTo()

distanceSquaredTo(cartesian: Cartesian3): number

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

参数

cartesian

Cartesian3

The point

返回

number

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

示例

ts
// Sort bounding spheres from back to front
spheres.sort(function(a, b) {
    return b.distanceSquaredTo(camera.positionWC) - a.distanceSquaredTo(camera.positionWC);
});

computePlaneDistances()

computePlaneDistances(position: Cartesian3, direction: Cartesian3, result?: Interval): Interval

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. <br> 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.

参数

position

Cartesian3

The position to calculate the distance from.

direction

Cartesian3

The direction from position.

result?

Interval

A Interval to store the nearest and farthest distances.

返回

Interval

The nearest and farthest distances on the bounding sphere from position in direction.


isOccluded()

isOccluded(occluder: Occluder): boolean

Determines whether or not a sphere is hidden from view by the occluder.

参数

occluder

Occluder

The occluder.

返回

boolean

true if the sphere is not visible; otherwise false.


equals()

equals(right?: BoundingSphere): boolean

Compares this BoundingSphere against the provided BoundingSphere componentwise and returns <code>true</code> if they are equal, <code>false</code> otherwise.

参数

right?

BoundingSphere

The right hand side BoundingSphere.

返回

boolean

true if they are equal, false otherwise.


clone()

clone(result?: BoundingSphere): BoundingSphere

Duplicates this BoundingSphere instance.

参数

result?

BoundingSphere

The object onto which to store the result.

返回

BoundingSphere

The modified result parameter or a new BoundingSphere instance if none was provided.


volume()

volume(): number

Computes the radius of the BoundingSphere.

返回

number

The radius of the BoundingSphere.

构造函数

构造函数

new BoundingSphere(center?: Cartesian3, radius?: number): BoundingSphere

参数

center?

Cartesian3

radius?

number

返回

BoundingSphere

KBE3D @3.0.0 Copyright © 2024-present KBE3D