Class AbstractNSphere<V extends EuclideanVector<V>>

java.lang.Object
org.apache.commons.geometry.euclidean.AbstractNSphere<V>
Type Parameters:
V - Vector implementation type
All Implemented Interfaces:
Region<V>, Sized
Direct Known Subclasses:
Circle, Sphere

public abstract class AbstractNSphere<V extends EuclideanVector<V>> extends Object implements Region<V>
Abstract base class representing an n-sphere, which is a generalization of the ordinary 3 dimensional sphere to arbitrary dimensions.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final V
    The center point of the n-sphere.
    private final org.apache.commons.numbers.core.Precision.DoubleEquivalence
    Precision object used to perform floating point comparisons.
    private final double
    The radius of the n-sphere.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    AbstractNSphere(V center, double radius, org.apache.commons.numbers.core.Precision.DoubleEquivalence precision)
    Construct a new instance from its component parts.
  • Method Summary

    Modifier and Type
    Method
    Description
    classify(V pt)
    Classify the given point with respect to the region.
    boolean
    protected <L extends Embedding<V, Vector1D>>
    V
    firstIntersection(L line, ToDoubleBiFunction<L,V> abscissaFn, ToDoubleBiFunction<L,V> distanceFn)
    Internal method to compute the first intersection between a line and this instance.
    Get the center point of the n-sphere.
    Get the centroid, or geometric center, of the region or null if no centroid exists or one exists but is not unique.
    org.apache.commons.numbers.core.Precision.DoubleEquivalence
    Get the precision object used to perform floating point comparisons for this instance.
    double
    Get the radius of the n-sphere.
    int
    protected <L extends Embedding<V, Vector1D>>
    List<V>
    intersections(L line, ToDoubleBiFunction<L,V> abscissaFn, ToDoubleBiFunction<L,V> distanceFn)
    Internal method to compute the intersections between a line and this instance.
    boolean
    Return true if the region is completely empty, ie all points in the space are classified as outside.
    boolean
    Return true if the region spans the entire space.
    protected V
    project(V pt, V defaultVector)
    Project the given point to the boundary of the n-sphere.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.apache.commons.geometry.core.Region

    contains, getBoundarySize, project

    Methods inherited from interface org.apache.commons.geometry.core.Sized

    getSize, isFinite, isInfinite
  • Field Details

    • center

      private final V extends EuclideanVector<V> center
      The center point of the n-sphere.
    • radius

      private final double radius
      The radius of the n-sphere.
    • precision

      private final org.apache.commons.numbers.core.Precision.DoubleEquivalence precision
      Precision object used to perform floating point comparisons.
  • Constructor Details

    • AbstractNSphere

      protected AbstractNSphere(V center, double radius, org.apache.commons.numbers.core.Precision.DoubleEquivalence precision)
      Construct a new instance from its component parts.
      Parameters:
      center - the center point of the n-sphere
      radius - the radius of the n-sphere
      precision - precision context used to perform floating point comparisons
      Throws:
      IllegalArgumentException - if center is not finite or radius is not finite or is less than or equal to zero as evaluated by the given precision context
  • Method Details

    • getCenter

      public V getCenter()
      Get the center point of the n-sphere.
      Returns:
      the center of the n-sphere
    • getRadius

      public double getRadius()
      Get the radius of the n-sphere.
      Returns:
      the radius of the n-sphere.
    • getPrecision

      public org.apache.commons.numbers.core.Precision.DoubleEquivalence getPrecision()
      Get the precision object used to perform floating point comparisons for this instance.
      Returns:
      the precision object for this instance
    • isFull

      public boolean isFull()
      Return true if the region spans the entire space. In other words, a region is full if no points in the space are classified as outside.

      This method always returns false.

      Specified by:
      isFull in interface Region<V extends EuclideanVector<V>>
      Returns:
      true if the region spans the entire space
    • isEmpty

      public boolean isEmpty()
      Return true if the region is completely empty, ie all points in the space are classified as outside.

      This method always returns false.

      Specified by:
      isEmpty in interface Region<V extends EuclideanVector<V>>
      Returns:
      true if the region is empty
    • getCentroid

      public V getCentroid()
      Get the centroid, or geometric center, of the region or null if no centroid exists or one exists but is not unique. A centroid will not exist for empty or infinite regions.

      The centroid of a geometric object is defined as the mean position of all points in the object, including interior points, vertices, and other points lying on the boundary. If a physical object has a uniform density, then its center of mass is the same as its geometric centroid.

      This method is an alias for getCenter().

      Specified by:
      getCentroid in interface Region<V extends EuclideanVector<V>>
      Returns:
      the centroid of the region or null if no unique centroid exists
      See Also:
    • classify

      public RegionLocation classify(V pt)
      Classify the given point with respect to the region.
      Specified by:
      classify in interface Region<V extends EuclideanVector<V>>
      Parameters:
      pt - the point to classify
      Returns:
      the location of the point with respect to the region
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • project

      protected V project(V pt, V defaultVector)
      Project the given point to the boundary of the n-sphere. If the given point is exactly equal to the n-sphere center, it is projected to the boundary in the direction of defaultVector.
      Parameters:
      pt - the point to project
      defaultVector - the direction to project the point if it lies exactly at the center of the n-sphere
      Returns:
      the projected point
    • intersections

      protected <L extends Embedding<V, Vector1D>> List<V> intersections(L line, ToDoubleBiFunction<L,V> abscissaFn, ToDoubleBiFunction<L,V> distanceFn)
      Internal method to compute the intersections between a line and this instance. The returned list will contain either 0, 1, or 2 points.
      • 2 points - The line is a secant line and intersects the n-sphere at two distinct points. The points are ordered such that the first point in the list is the first point encountered when traveling in the direction of the line. (In other words, the points are ordered by increasing abscissa value.)
      • 1 point - The line is a tangent line and only intersects the n-sphere at a single point (as evaluated by the n-sphere's precision context).
      • 0 points - The line does not intersect the n-sphere.
      Type Parameters:
      L - Line implementation type
      Parameters:
      line - line to intersect with the n-sphere
      abscissaFn - function used to compute the abscissa value of a point on a line
      distanceFn - function used to compute the smallest distance between a point and a line
      Returns:
      a list of intersection points between the given line and this n-sphere
    • firstIntersection

      protected <L extends Embedding<V, Vector1D>> V firstIntersection(L line, ToDoubleBiFunction<L,V> abscissaFn, ToDoubleBiFunction<L,V> distanceFn)
      Internal method to compute the first intersection between a line and this instance.
      Type Parameters:
      L - Line implementation type
      Parameters:
      line - line to intersect with the n-sphere
      abscissaFn - function used to compute the abscissa value of a point on a line
      distanceFn - function used to compute the smallest distance between a point and a line
      Returns:
      the first intersection between the given line and this instance or null if no such intersection exists