Class AbstractNSphere<V extends EuclideanVector<V>>
java.lang.Object
org.apache.commons.geometry.euclidean.AbstractNSphere<V>
- Type Parameters:
V
- Vector implementation type
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 -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
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 TypeMethodDescriptionClassify the given point with respect to the region.boolean
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
hashCode()
intersections
(L line, ToDoubleBiFunction<L, V> abscissaFn, 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 asoutside
.boolean
isFull()
Return true if the region spans the entire space.protected V
Project the given point to the boundary of the n-sphere.toString()
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
The center point of the n-sphere. -
radius
private final double radiusThe radius of the n-sphere. -
precision
private final org.apache.commons.numbers.core.Precision.DoubleEquivalence precisionPrecision 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-sphereradius
- the radius of the n-sphereprecision
- 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
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 asoutside
.This method always returns
false
.- Specified by:
isFull
in interfaceRegion<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 asoutside
.This method always returns
false
.- Specified by:
isEmpty
in interfaceRegion<V extends EuclideanVector<V>>
- Returns:
- true if the region is empty
-
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 interfaceRegion<V extends EuclideanVector<V>>
- Returns:
- the centroid of the region or null if no unique centroid exists
- See Also:
-
classify
Classify the given point with respect to the region.- Specified by:
classify
in interfaceRegion<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() -
equals
-
toString
-
project
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 ofdefaultVector
.- Parameters:
pt
- the point to projectdefaultVector
- 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-sphereabscissaFn
- function used to compute the abscissa value of a point on a linedistanceFn
- 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-sphereabscissaFn
- function used to compute the abscissa value of a point on a linedistanceFn
- 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
-