Class Sphere.SphereTreeApproximationBuilder

java.lang.Object
org.apache.commons.geometry.euclidean.threed.shape.Sphere.SphereTreeApproximationBuilder
Enclosing class:
Sphere

private static final class Sphere.SphereTreeApproximationBuilder extends Object
Internal class used to construct hyperplane-bounded approximations of spheres as BSP trees. The class begins with an octahedron inscribed in the sphere and then subdivides each triangular face a specified number of times.
  • Field Details

    • PARTITION_THRESHOLD

      private static final int PARTITION_THRESHOLD
      Threshold used to determine when to stop inserting structural cuts and begin adding facets.
      See Also:
    • sphere

      private final Sphere sphere
      The sphere that an approximation is being created for.
    • subdivisions

      private final int subdivisions
      The number of triangular subdivisions to use.
  • Constructor Details

    • SphereTreeApproximationBuilder

      SphereTreeApproximationBuilder(Sphere sphere, int subdivisions)
      Construct a new builder for creating a BSP tree approximation of the given sphere.
      Parameters:
      sphere - the sphere to create an approximation of
      subdivisions - the number of triangle subdivisions to use in tree creation
  • Method Details

    • build

      Build the sphere approximation BSP tree.
      Returns:
      the sphere approximation BSP tree
      Throws:
      IllegalStateException - if tree creation fails for the configured subdivision count
    • partitionAndInsert

      private void partitionAndInsert(RegionBSPTree3D.RegionNode3D node, Vector3D p1, Vector3D p2, Vector3D p3, int level)
      Recursively insert structural BSP tree cuts into the given node and then insert subdivided triangles when a target subdivision level is reached. The structural BSP tree cuts are used to help reduce the overall depth of the BSP tree.
      Parameters:
      node - the node to insert into
      p1 - first triangle point
      p2 - second triangle point
      p3 - third triangle point
      level - current subdivision level
    • insertSubdividedTriangles

      private RegionBSPTree3D.RegionNode3D insertSubdividedTriangles(RegionBSPTree3D.RegionNode3D node, Vector3D p1, Vector3D p2, Vector3D p3, int level)
      Recursively insert subdivided triangles into the given node. Each triangle is inserted into the minus side of the previous triangle.
      Parameters:
      node - the node to insert into
      p1 - first triangle point
      p2 - second triangle point
      p3 - third triangle point
      level - the current subdivision level
      Returns:
      the node representing the inside of the region after insertion of all triangles
    • createPlane

      private Plane createPlane(Vector3D p1, Vector3D p2, Vector3D p3)
      Create a plane from the given points, using the precision context of the sphere.
      Parameters:
      p1 - first point
      p2 - second point
      p3 - third point
      Returns:
      a plane defined by the given points
    • checkedCut

      private void checkedCut(RegionBSPTree3D.RegionNode3D node, Plane cutter, RegionCutRule cutRule)
      Insert the cut into the given node, throwing an exception if no portion of the cutter intersects the node.
      Parameters:
      node - node to cut
      cutter - plane to use to cut the node
      cutRule - cut rule to apply
      Throws:
      IllegalStateException - if no portion of the cutter plane intersects the node