in commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/shape/Sphere.java [276:328]
RegionBSPTree3D build() {
final RegionBSPTree3D tree = RegionBSPTree3D.empty();
final Vector3D center = sphere.getCenter();
final double radius = sphere.getRadius();
final Precision.DoubleEquivalence precision = sphere.getPrecision();
// insert the primary split planes
final Plane plusXPlane = Planes.fromPointAndNormal(center, Vector3D.Unit.PLUS_X, precision);
final Plane plusYPlane = Planes.fromPointAndNormal(center, Vector3D.Unit.PLUS_Y, precision);
final Plane plusZPlane = Planes.fromPointAndNormal(center, Vector3D.Unit.PLUS_Z, precision);
tree.insert(plusXPlane.span(), RegionCutRule.INHERIT);
tree.insert(plusYPlane.span(), RegionCutRule.INHERIT);
tree.insert(plusZPlane.span(), RegionCutRule.INHERIT);
// create the vertices for the octahedron
final double cx = center.getX();
final double cy = center.getY();
final double cz = center.getZ();
final Vector3D maxX = Vector3D.of(cx + radius, cy, cz);
final Vector3D minX = Vector3D.of(cx - radius, cy, cz);
final Vector3D maxY = Vector3D.of(cx, cy + radius, cz);
final Vector3D minY = Vector3D.of(cx, cy - radius, cz);
final Vector3D maxZ = Vector3D.of(cx, cy, cz + radius);
final Vector3D minZ = Vector3D.of(cx, cy, cz - radius);
// partition and subdivide the face triangles and insert them into the tree
final RegionNode3D root = tree.getRoot();
try {
partitionAndInsert(root.getMinus().getMinus().getMinus(), minX, minZ, minY, 0);
partitionAndInsert(root.getMinus().getMinus().getPlus(), minX, minY, maxZ, 0);
partitionAndInsert(root.getMinus().getPlus().getMinus(), minX, maxY, minZ, 0);
partitionAndInsert(root.getMinus().getPlus().getPlus(), minX, maxZ, maxY, 0);
partitionAndInsert(root.getPlus().getMinus().getMinus(), maxX, minY, minZ, 0);
partitionAndInsert(root.getPlus().getMinus().getPlus(), maxX, maxZ, minY, 0);
partitionAndInsert(root.getPlus().getPlus().getMinus(), maxX, minZ, maxY, 0);
partitionAndInsert(root.getPlus().getPlus().getPlus(), maxX, maxY, maxZ, 0);
} catch (final IllegalStateException | IllegalArgumentException exc) {
// standardize any tree construction failure as an IllegalStateException
throw new IllegalStateException("Failed to construct sphere approximation with subdivision count " +
subdivisions + ": " + exc.getMessage(), exc);
}
return tree;
}