Class Circle
java.lang.Object
org.apache.commons.geometry.euclidean.AbstractNSphere<Vector2D>
org.apache.commons.geometry.euclidean.twod.shape.Circle
- All Implemented Interfaces:
Region<Vector2D>
,Sized
,Linecastable2D
Class representing a circle in 2 dimensional Euclidean space.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
Class used to build BSP tree circle approximations. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfirstIntersection
(Line line) Get the first intersection point between the given line and this circle, or null if no such point exists.static Circle
from
(Vector2D center, double radius, org.apache.commons.numbers.core.Precision.DoubleEquivalence precision) Construct a circle from a center point and radius.double
Get the size of the boundary of the region.private Stream
<LinecastPoint2D> getLinecastStream
(LineConvexSubset segment) Get a stream containing the linecast intersection points of the given segment with this instance.double
getSize()
Get the size of the instance.intersections
(Line line) Get the intersections of the given line with this circle.linecast
(LineConvexSubset segment) Intersect the given line subset against the boundaries in this instance, returning a list of all intersections in order of increasing position along the line.linecastFirst
(LineConvexSubset segment) Intersect the given line subset against the boundaries in this instance, returning the first intersection found when traveling in the direction of the line subset from its start location.Project a point onto the boundary of the region.toTree
(int segments) Return aRegionBSPTree2D
representing an approximation of the circle.Methods inherited from class org.apache.commons.geometry.euclidean.AbstractNSphere
classify, equals, firstIntersection, getCenter, getCentroid, getPrecision, getRadius, hashCode, intersections, isEmpty, isFull, project, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.commons.geometry.euclidean.twod.Linecastable2D
linecast, linecastFirst
Methods inherited from interface org.apache.commons.geometry.core.Sized
isFinite, isInfinite
-
Constructor Details
-
Circle
private Circle(Vector2D center, double radius, org.apache.commons.numbers.core.Precision.DoubleEquivalence precision) Construct a new circle from its component parts.- Parameters:
center
- the center of the circleradius
- the circle radiusprecision
- precision context used to compare floating point numbers- 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
-
getSize
public double getSize()Get the size of the instance. -
getBoundarySize
public double getBoundarySize()Get the size of the boundary of the region. The size is a value in thed-1
dimension space. For example, in Euclidean space, this will be a length in 2D and an area in 3D.- Specified by:
getBoundarySize
in interfaceRegion<Vector2D>
- Returns:
- the size of the boundary of the region
-
project
-
toTree
Return aRegionBSPTree2D
representing an approximation of the circle. All points in the approximation are contained in the circle (ie, they lie inside or on the boundary). No guarantees are made regarding the internal structure of the returned tree. Non-boundary split nodes may be used in order to balance the tree and improve performance.Choosing an appropriate number of segments for an approximation is a trade-off between size and accuracy: approximations with large numbers of segments more closely match the geometric properties of the circle but at the cost of using larger tree structures. In general, the smallest number of segments that produces an acceptable result should be used.
- Parameters:
segments
- number of line segments to use for the boundary of the circle approximation- Returns:
- a BSP tree approximation of the circle
- Throws:
IllegalArgumentException
- ifsegments
is less than 3
-
intersections
Get the intersections of the given line with this circle. The returned list will contain either 0, 1, or 2 points.- 2 points - The line is a secant line and intersects the circle 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 circle at a single point (as evaluated by the circle's precision context).
- 0 points - The line does not intersect the circle.
- Parameters:
line
- line to intersect with the circle- Returns:
- a list of intersection points between the given line and this circle
-
firstIntersection
Get the first intersection point between the given line and this circle, or null if no such point exists. The "first" intersection point is the first such point encountered when traveling in the direction of the line from infinity.- Parameters:
line
- line to intersect with the circle- Returns:
- the first intersection point between the given line and this instance or null if no such point exists
-
linecast
Intersect the given line subset against the boundaries in this instance, returning a list of all intersections in order of increasing position along the line. An empty list is returned if no intersections are discovered.- Specified by:
linecast
in interfaceLinecastable2D
- Parameters:
segment
- line subset to intersect- Returns:
- a list of computed intersections in order of increasing position along the line
-
linecastFirst
Intersect the given line subset against the boundaries in this instance, returning the first intersection found when traveling in the direction of the line subset from its start location.- Specified by:
linecastFirst
in interfaceLinecastable2D
- Parameters:
segment
- line subset to intersect- Returns:
- the first intersection found or null if no intersection is found
-
getLinecastStream
Get a stream containing the linecast intersection points of the given segment with this instance.- Parameters:
segment
- segment to intersect against this instance- Returns:
- a stream containing linecast intersection points
-
from
public static Circle from(Vector2D center, double radius, org.apache.commons.numbers.core.Precision.DoubleEquivalence precision) Construct a circle from a center point and radius.- Parameters:
center
- the center point of the circleradius
- the circle radiusprecision
- precision precision context used to compare floating point numbers- Returns:
- a circle with the given center and radius
- 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
-