Class Segment
- java.lang.Object
-
- org.apache.commons.geometry.euclidean.twod.LineSubset
-
- org.apache.commons.geometry.euclidean.twod.LineConvexSubset
-
- org.apache.commons.geometry.euclidean.twod.Segment
-
- All Implemented Interfaces:
Embedding<Vector2D,Vector1D>
,HyperplaneConvexSubset<Vector2D>
,HyperplaneSubset<Vector2D>
,Splittable<Vector2D,HyperplaneSubset<Vector2D>>
,RegionEmbedding<Vector2D,Vector1D>
,Sized
public final class Segment extends LineConvexSubset
Class representing a line segment in 2D Euclidean space. A line segment is a portion of a line with finite start and end points.Instances of this class are guaranteed to be immutable.
- See Also:
Lines
, Line Segment
-
-
Field Summary
Fields Modifier and Type Field Description private Vector2D
endPoint
End point for the segment.private Vector2D
startPoint
Start point for the segment.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) RegionLocation
classifyAbscissa(double abscissa)
Classify the given line abscissa value with respect to the subspace region.(package private) double
closestAbscissa(double abscissa)
Get the closest value in the subspace region to the given abscissa.Bounds2D
getBounds()
Get aBounds2D
object defining an axis-aligned bounding box containing all vertices for this subset.Vector2D
getCentroid()
Get the centroid, or geometric center, of the hyperplane subset or null if no centroid exists or one exists but is not unique.Vector2D
getEndPoint()
Get the end point for the subset.double
getSize()
Get the size of the instance.Vector2D
getStartPoint()
Get the start point for the subset.double
getSubspaceEnd()
Get the 1D end location of the subset orDouble.POSITIVE_INFINITY
if no end location exists.double
getSubspaceStart()
Get the 1D start location of the subset orDouble.NEGATIVE_INFINITY
if no start location exists.boolean
isFinite()
Return true if the size of the instance is finite.boolean
isFull()
Return true if this instance contains all points in the hyperplane.boolean
isInfinite()
Return true if the size of the instance is infinite.Segment
reverse()
Reverse the orientation of the hyperplane for this instance, returning the result as a new instance.(package private) Split<LineConvexSubset>
splitOnIntersection(Line splitter, Vector2D intersection)
Split this instance using the given splitter line and intersection point.java.lang.String
toString()
Segment
transform(Transform<Vector2D> transform)
Return a new hyperplane subset resulting from the application of the given transform.-
Methods inherited from class org.apache.commons.geometry.euclidean.twod.LineConvexSubset
closest, getInterval, getSubspaceRegion, isEmpty, split, toConvex
-
Methods inherited from class org.apache.commons.geometry.euclidean.twod.LineSubset
classify, createSplitResult, getHyperplane, getLine, getNonIntersectingSplitResult, getPrecision, intersection, intersection, splitterPlusIsPositiveFacing, toSpace, toSubspace
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.commons.geometry.core.Embedding
toSpace, toSubspace
-
Methods inherited from interface org.apache.commons.geometry.core.partitioning.HyperplaneSubset
classify, contains, getHyperplane
-
-
-
-
Constructor Detail
-
Segment
Segment(Line line, Vector2D startPoint, Vector2D endPoint)
Construct a new instance from a line and two points on the line. Callers are responsible for ensuring that the given points lie on the line and are in order of increasing abscissa. No validation is performed.- Parameters:
line
- line for the segmentstartPoint
- segment start pointendPoint
- segment end point
-
-
Method Detail
-
isFull
public boolean isFull()
Return true if this instance contains all points in the hyperplane.This method always returns
false
.- Returns:
- true if this instance contains all points in the hyperplane
-
isInfinite
public boolean isInfinite()
Return true if the size of the instance is infinite.This method always returns
false
.- Returns:
- true if the size of the instance is infinite
-
isFinite
public boolean isFinite()
Return true if the size of the instance is finite.This method always returns
true
.- Returns:
- true if the size of the instance is finite
-
getSize
public double getSize()
Get the size of the instance.- Returns:
- the size of the instance
-
getCentroid
public Vector2D getCentroid()
Get the centroid, or geometric center, of the hyperplane subset or null if no centroid exists or one exists but is not unique. A centroid will not exist for empty or infinite subsets.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.
- Returns:
- the centroid of the hyperplane subset or null if no unique centroid exists
- See Also:
- Centroid
-
getStartPoint
public Vector2D getStartPoint()
Get the start point for the subset.- Specified by:
getStartPoint
in classLineConvexSubset
- Returns:
- the start point for the subset, or null if no start point exists
-
getSubspaceStart
public double getSubspaceStart()
Get the 1D start location of the subset orDouble.NEGATIVE_INFINITY
if no start location exists.- Specified by:
getSubspaceStart
in classLineConvexSubset
- Returns:
- the 1D start location of the subset or
Double.NEGATIVE_INFINITY
if no start location exists.
-
getEndPoint
public Vector2D getEndPoint()
Get the end point for the subset.- Specified by:
getEndPoint
in classLineConvexSubset
- Returns:
- the end point for the subset, or null if no end point exists.
-
getSubspaceEnd
public double getSubspaceEnd()
Get the 1D end location of the subset orDouble.POSITIVE_INFINITY
if no end location exists.- Specified by:
getSubspaceEnd
in classLineConvexSubset
- Returns:
- the 1D end location of the subset or
Double.POSITIVE_INFINITY
if no end location exists
-
getBounds
public Bounds2D getBounds()
Get aBounds2D
object defining an axis-aligned bounding box containing all vertices for this subset. Null is returned if the subset is infinite or does not contain any vertices.- Specified by:
getBounds
in classLineSubset
- Returns:
- the bounding box for this instance or null if no valid bounds could be determined
-
transform
public Segment transform(Transform<Vector2D> transform)
Return a new hyperplane subset resulting from the application of the given transform. The current instance is not modified.Hyperplane convex subsets subjected to affine transformations remain convex.
- Specified by:
transform
in interfaceHyperplaneConvexSubset<Vector2D>
- Specified by:
transform
in interfaceHyperplaneSubset<Vector2D>
- Specified by:
transform
in classLineConvexSubset
- Parameters:
transform
- the transform instance to apply- Returns:
- new transformed hyperplane subset
-
reverse
public Segment reverse()
Reverse the orientation of the hyperplane for this instance, returning the result as a new instance. The returned subset contains the same points but has a reversed orientation.- Specified by:
reverse
in interfaceHyperplaneConvexSubset<Vector2D>
- Specified by:
reverse
in classLineConvexSubset
- Returns:
- a hyperplane convex subset representing the same region but with the opposite orientation.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
classifyAbscissa
RegionLocation classifyAbscissa(double abscissa)
Classify the given line abscissa value with respect to the subspace region.- Specified by:
classifyAbscissa
in classLineSubset
- Parameters:
abscissa
- the abscissa value to classify- Returns:
- the region location of the line abscissa value
-
closestAbscissa
double closestAbscissa(double abscissa)
Get the closest value in the subspace region to the given abscissa.- Specified by:
closestAbscissa
in classLineConvexSubset
- Parameters:
abscissa
- input abscissa- Returns:
- the closest value in the subspace region to the given abscissa
-
splitOnIntersection
Split<LineConvexSubset> splitOnIntersection(Line splitter, Vector2D intersection)
Split this instance using the given splitter line and intersection point.- Specified by:
splitOnIntersection
in classLineConvexSubset
- Parameters:
splitter
- splitter lineintersection
- intersection point between the splitter line and the line for this instance- Returns:
- the result of splitting this instance with the given splitter line and intersection point
-
-