Class Circle

    • Constructor Detail

      • 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 circle
        radius - the circle radius
        precision - precision context used to compare floating point numbers
        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

      • getSize

        public double getSize()
        Get the size of the instance.
        Specified by:
        getSize in interface Sized
        Returns:
        the size of the instance
      • getBoundarySize

        public double getBoundarySize()
        Get the size of the boundary of the region. The size is a value in the d-1 dimension space. For example, in Euclidean space, this will be a length in 2D and an area in 3D.
        Specified by:
        getBoundarySize in interface Region<Vector2D>
        Returns:
        the size of the boundary of the region
      • project

        public Vector2D project​(Vector2D pt)
        Project a point onto the boundary of the region. Null is returned if the region contains no boundaries (ie, is either full or empty).
        Specified by:
        project in interface Region<Vector2D>
        Parameters:
        pt - pt to project
        Returns:
        projection of the point on the boundary of the region or null if the region does not contain any boundaries
      • toTree

        public RegionBSPTree2D toTree​(int segments)
        Return a RegionBSPTree2D 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:
        java.lang.IllegalArgumentException - if segments is less than 3
      • intersections

        public java.util.List<Vector2D> intersections​(Line line)
        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

        public Vector2D firstIntersection​(Line line)
        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

        public java.util.List<LinecastPoint2D> 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. An empty list is returned if no intersections are discovered.
        Specified by:
        linecast in interface Linecastable2D
        Parameters:
        segment - line subset to intersect
        Returns:
        a list of computed intersections in order of increasing position along the line
      • linecastFirst

        public LinecastPoint2D 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.
        Specified by:
        linecastFirst in interface Linecastable2D
        Parameters:
        segment - line subset to intersect
        Returns:
        the first intersection found or null if no intersection is found
      • getLinecastStream

        private java.util.stream.Stream<LinecastPoint2D> getLinecastStream​(LineConvexSubset segment)
        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 circle
        radius - the circle radius
        precision - precision precision context used to compare floating point numbers
        Returns:
        a circle with the given center and radius
        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