public final class Sphere extends AbstractNSphere<Vector3D> implements Linecastable3D
Modifier and Type | Method and Description |
---|---|
Vector3D |
firstIntersection(Line3D line)
Get the first intersection point between the given line and this sphere, or null
if no such point exists.
|
static Sphere |
from(Vector3D center,
double radius,
Precision.DoubleEquivalence precision)
Construct a sphere from a center point and radius.
|
double |
getBoundarySize() |
double |
getSize() |
List<Vector3D> |
intersections(Line3D line)
Get the intersections of the given line with this sphere.
|
List<LinecastPoint3D> |
linecast(LineConvexSubset3D subset)
Intersect the given line convex subset against the boundaries in this instance, returning
a list of all intersections in order of increasing distance along the line.
|
LinecastPoint3D |
linecastFirst(LineConvexSubset3D subset)
Intersect the given line convex subset against the boundaries in this instance, returning
the first intersection found when traveling in the direction of the line subset from its
start point.
|
Vector3D |
project(Vector3D pt) |
RegionBSPTree3D |
toTree(int subdivisions)
Build an approximation of this sphere using a
RegionBSPTree3D . |
TriangleMesh |
toTriangleMesh(int subdivisions)
Build an approximation of this sphere using a
TriangleMesh . |
classify, equals, firstIntersection, getCenter, getCentroid, getPrecision, getRadius, hashCode, intersections, isEmpty, isFull, project, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
linecast, linecastFirst
isFinite, isInfinite
public double getBoundarySize()
getBoundarySize
in interface Region<Vector3D>
public RegionBSPTree3D toTree(int subdivisions)
RegionBSPTree3D
. The approximation is constructed by
taking an octahedron (8-sided polyhedron with triangular faces) inscribed in the sphere and subdividing each
triangular face subdivisions
number of times, each time projecting the newly created vertices onto the
sphere surface. Each triangle subdivision produces 4 triangles, meaning that the total number of triangles
inserted into tree is equal to \(8 \times 4^s\), where \(s\) is the number of subdivisions. For
example, calling this method with subdivisions
equal to 3
will produce a tree having
\(8 \times 4^3 = 512\) triangular facets inserted. See the table below for other examples. The returned BSP
tree also contains structural cuts to reduce the overall height of the tree.
Subdivisions | Triangles |
---|---|
0 | 8 |
1 | 32 |
2 | 128 |
3 | 512 |
4 | 2048 |
5 | 8192 |
Care must be taken when using this method with large subdivision numbers so that floating point errors
do not interfere with the creation of the planes and triangles in the tree. For example, if the number of
subdivisions is too high, the subdivided triangle points may become equivalent according to the sphere's
precision context
and plane creation may fail. Or plane creation may succeed but
insertion of the plane into the tree may fail for similar reasons. In general, it is best to use the lowest
subdivision number practical for the intended purpose.
subdivisions
- the number of triangle subdivisions to use when creating the tree; the total number of
triangular facets inserted into the returned tree is equal to \(8 \times 4^s\), where \(s\) is the number
of subdivisionsIllegalArgumentException
- if subdivisions
is less than zeroIllegalStateException
- if tree creation fails for the given subdivision counttoTriangleMesh(int)
public TriangleMesh toTriangleMesh(int subdivisions)
TriangleMesh
. The approximation is constructed by
taking an octahedron (8-sided polyhedron with triangular faces) inscribed in the sphere and subdividing each
triangular face subdivisions
number of times, each time projecting the newly created vertices onto the
sphere surface. Each triangle subdivision produces 4 triangles, meaning that the total number of triangles
in the returned mesh is equal to \(8 \times 4^s\), where \(s\) is the number of subdivisions. For
example, calling this method with subdivisions
equal to 3
will produce a mesh having
\(8 \times 4^3 = 512\) triangular facets inserted. See the table below for other examples.
Subdivisions | Triangles |
---|---|
0 | 8 |
1 | 32 |
2 | 128 |
3 | 512 |
4 | 2048 |
5 | 8192 |
BSP Tree Conversion
Inserting the boundaries of a sphere mesh approximation directly into a BSP tree will invariably result
in poor performance: since the region is convex the constructed BSP tree degenerates into a simple linked
list of nodes. If a BSP tree is needed, users should prefer the toTree(int)
method, which creates
balanced tree approximations directly, or the RegionBSPTree3D.PartitionedRegionBuilder3D
class,
which can be used to insert the mesh faces into a pre-partitioned tree.
subdivisions
- the number of triangle subdivisions to use when creating the mesh; the total number of
triangular faces in the returned mesh is equal to \(8 \times 4^s\), where \(s\) is the number
of subdivisionsIllegalArgumentException
- if subdivisions
is less than zerotoTree(int)
public List<Vector3D> intersections(Line3D line)
line
- line to intersect with the spherepublic Vector3D firstIntersection(Line3D line)
line
- line to intersect with the spherepublic List<LinecastPoint3D> linecast(LineConvexSubset3D subset)
linecast
in interface Linecastable3D
subset
- line subset to intersectpublic LinecastPoint3D linecastFirst(LineConvexSubset3D subset)
linecastFirst
in interface Linecastable3D
subset
- line subset to intersectpublic static Sphere from(Vector3D center, double radius, Precision.DoubleEquivalence precision)
center
- the center of the sphereradius
- the sphere radiusprecision
- precision context used to compare floating point numbersIllegalArgumentException
- if center is not finite or radius is not finite or is
less than or equal to zero as evaluated by the given precision contextCopyright © 2016–2021 The Apache Software Foundation. All rights reserved.