Class AbstractNSphere<V extends EuclideanVector<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 java.lang.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:
    N-sphere
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private V center
      The center point of the n-sphere.
      private org.apache.commons.numbers.core.Precision.DoubleEquivalence precision
      Precision object used to perform floating point comparisons.
      private double radius
      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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      RegionLocation classify​(V pt)
      Classify the given point with respect to the region.
      boolean equals​(java.lang.Object obj)
      protected <L extends Embedding<V,​Vector1D>>
      V
      firstIntersection​(L line, java.util.function.ToDoubleBiFunction<L,​V> abscissaFn, java.util.function.ToDoubleBiFunction<L,​V> distanceFn)
      Internal method to compute the first intersection between a line and this instance.
      V getCenter()
      Get the center point of the n-sphere.
      V getCentroid()
      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 getPrecision()
      Get the precision object used to perform floating point comparisons for this instance.
      double getRadius()
      Get the radius of the n-sphere.
      int hashCode()
      protected <L extends Embedding<V,​Vector1D>>
      java.util.List<V>
      intersections​(L line, java.util.function.ToDoubleBiFunction<L,​V> abscissaFn, java.util.function.ToDoubleBiFunction<L,​V> distanceFn)
      Internal method to compute the intersections between a line and this instance.
      boolean isEmpty()
      Return true if the region is completely empty, ie all points in the space are classified as outside.
      boolean isFull()
      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.
      java.lang.String toString()
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • 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 Detail

      • 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:
        java.lang.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 Detail

      • 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:
        Centroid
      • 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 java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.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>> java.util.List<V> intersections​(L line,
                                                                                          java.util.function.ToDoubleBiFunction<L,​V> abscissaFn,
                                                                                          java.util.function.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,
                                                                              java.util.function.ToDoubleBiFunction<L,​V> abscissaFn,
                                                                              java.util.function.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