Class Circle

java.lang.Object
com.irurueta.geometry.Circle
All Implemented Interfaces:
Serializable

public class Circle extends Object implements Serializable
This class defines a circle.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private Point2D
    Center of circle.
    static final double
    Constant defining default threshold value used when none is provided.
    static final double
    Constant defining machine precision.
    static final double
    Constant defining minimum allowed radius.
    static final double
    Constant defining minimum allowed threshold.
    private double
    Radius of circle.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Empty constructor.
    Circle(Conic conic)
    Constructor.
    Circle(Point2D center, double radius)
    Constructor.
    Circle(Point2D point1, Point2D point2, Point2D point3)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    area(double radius)
    Returns area of a circle having provided radius.
    void
    closestPoint(Point2D point, Point2D result)
    Computes closest point to provided point that is located in this circle boundary and stores the result in provided result instance.
    static double
    curvature(double radius)
    Gets curvature for provided radius.
    static double
    distance(Circle circle, Point2D point)
    Returns distance from provided point to the closest point located in provided circle boundary.
    double
    Returns area of this circle.
    Returns center of circle.
    Returns closest point to provided point that is located in this circle boundary.
    double
    Gets curvature of radius at provided point.
    double
    Returns distance from provided point to the closest point located in the circle boundary.
    double
    Returns perimeter of this circle.
    double
    Returns radius of circle.
    double
    Returns distance from provided point to the closest point located in the circle boundary.
    Returns a line tangent to this circle at provided point.
    getTangentLineAt(Point2D point, double threshold)
    Returns a line tangent to this circle at provided point.
    boolean
    Determines if provided point is inside this circle or not.
    boolean
    isInside(Point2D point, double threshold)
    Determines if provided point is inside this circle or not up to a certain threshold.
    boolean
    Determines whether provided point lies at circle boundary or not.
    boolean
    isLocus(Point2D point, double threshold)
    Determines whether provided point lies at circle boundary or not up to a certain threshold.
    static double
    perimeter(double radius)
    Returns perimeter of a circle having provided radius.
    void
    Sets center of circle.
    final void
    setCenterAndRadius(Point2D center, double radius)
    Sets center and radius of this circle.
    final void
    Set parameters of this circle from a valid conic corresponding to a circle.
    final void
    setParametersFromPoints(Point2D point1, Point2D point2, Point2D point3)
    Sets parameters of a circle by using three points that must belong to its locus.
    void
    setRadius(double radius)
    Sets radius of circle.
    static double
    signedDistance(Circle circle, Point2D point)
    Returns distance from provided point to the closest point located in provided circle boundary.
    void
    tangentLineAt(Point2D point, Line2D line, double threshold)
    Computes a line tangent to this circle at provided point.
    Converts this circle into a conic.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MIN_RADIUS

      public static final double MIN_RADIUS
      Constant defining minimum allowed radius.
      See Also:
    • DEFAULT_THRESHOLD

      public static final double DEFAULT_THRESHOLD
      Constant defining default threshold value used when none is provided.
      See Also:
    • MIN_THRESHOLD

      public static final double MIN_THRESHOLD
      Constant defining minimum allowed threshold.
      See Also:
    • EPS

      public static final double EPS
      Constant defining machine precision.
      See Also:
    • center

      private Point2D center
      Center of circle.
    • radius

      private double radius
      Radius of circle.
  • Constructor Details

    • Circle

      public Circle()
      Empty constructor. Creates circle located at space origin (0,0) with radius 1.0.
    • Circle

      public Circle(Point2D center, double radius)
      Constructor. Sets center and radius of circle.
      Parameters:
      center - Center of circle.
      radius - Radius of circle.
      Throws:
      IllegalArgumentException - Raised if provided radius is negative.
    • Circle

      public Circle(Point2D point1, Point2D point2, Point2D point3) throws ColinearPointsException
      Constructor. Computes a circle by using three points that must belong to its locus.
      Parameters:
      point1 - point 1.
      point2 - point 2.
      point3 - point 3.
      Throws:
      ColinearPointsException - if provided set of points are coincident or co-linear (form a single line). In such cases a singularity occurs since a circle having an infinite radius would be required to contain all three points in its locus.
    • Circle

      public Circle(Conic conic)
      Constructor. Computes a circle from a valid conic corresponding to a circle.
      Parameters:
      conic - a conic to create a circle from.
      Throws:
      IllegalArgumentException - if provided conic is not a circle.
  • Method Details

    • getCenter

      public Point2D getCenter()
      Returns center of circle.
      Returns:
      Center of circle.
    • setCenter

      public void setCenter(Point2D center)
      Sets center of circle.
      Parameters:
      center - Center of circle.
      Throws:
      NullPointerException - Raised if provided center is null.
    • getRadius

      public double getRadius()
      Returns radius of circle.
      Returns:
      Radius of circle.
    • setRadius

      public void setRadius(double radius)
      Sets radius of circle.
      Parameters:
      radius - Radius of circle.
      Throws:
      IllegalArgumentException - Raised if provided radius is negative.
    • setCenterAndRadius

      public final void setCenterAndRadius(Point2D center, double radius)
      Sets center and radius of this circle.
      Parameters:
      center - Center to be set.
      radius - Radius to be set.
      Throws:
      IllegalArgumentException - Raised if provided radius is negative.
      NullPointerException - Raised if provided center is null.
    • setParametersFromPoints

      public final void setParametersFromPoints(Point2D point1, Point2D point2, Point2D point3) throws ColinearPointsException
      Sets parameters of a circle by using three points that must belong to its locus.
      Parameters:
      point1 - point 1.
      point2 - point 2.
      point3 - point 3.
      Throws:
      ColinearPointsException - if provided set of points are coincident or co-linear (form a single line). In such cases a singularity occurs since a circle having an infinite radius would be required to contain all three points in its locus.
    • area

      public static double area(double radius)
      Returns area of a circle having provided radius.
      Parameters:
      radius - Radius of a circle.
      Returns:
      Area of a circle having provided radius.
      Throws:
      IllegalArgumentException - Raised if provided radius is negative.
    • getArea

      public double getArea()
      Returns area of this circle.
      Returns:
      Area of this circle.
    • perimeter

      public static double perimeter(double radius)
      Returns perimeter of a circle having provided radius.
      Parameters:
      radius - Radius of a circle.
      Returns:
      Perimeter of a circle having provided radius.
      Throws:
      IllegalArgumentException - Raised if provided radius is negative.
    • getPerimeter

      public double getPerimeter()
      Returns perimeter of this circle.
      Returns:
      Perimeter of this circle.
    • curvature

      public static double curvature(double radius)
      Gets curvature for provided radius. Curvature of a circle is always the reciprocal of its radius.
      Parameters:
      radius - radius of a circle.
      Returns:
      curvature of a circle.
    • getCurvature

      public double getCurvature()
      Gets curvature of radius at provided point. Curvature of a circle is always the reciprocal of its radius.
      Returns:
      curvature of circle.
    • isInside

      public boolean isInside(Point2D point, double threshold)
      Determines if provided point is inside this circle or not up to a certain threshold. If provided threshold is positive, the circle behaves as if it was a larger circle increased by threshold amount, if provided threshold is negative, the circle behaves as if it was a smaller circle decreased by threshold amount in radius.
      Parameters:
      point - Point to be checked.
      threshold - Threshold to determine if point is inside or not.
      Returns:
      True if point is considered to be inside this circle, false otherwise.
    • isInside

      public boolean isInside(Point2D point)
      Determines if provided point is inside this circle or not.
      Parameters:
      point - Point to be checked.
      Returns:
      True if point is considered to be inside this circle, false otherwise.
    • getSignedDistance

      public double getSignedDistance(Point2D point)
      Returns distance from provided point to the closest point located in the circle boundary. Returned distance will be negative when point is inside of circle, and positive otherwise.
      Parameters:
      point - Point to be checked.
      Returns:
      Distance from point to circle boundary.
    • signedDistance

      public static double signedDistance(Circle circle, Point2D point)
      Returns distance from provided point to the closest point located in provided circle boundary. Returned distance will be negative when point is inside of circle, and positive otherwise.
      Parameters:
      circle - A circle.
      point - Point to be checked.
      Returns:
      Distance from point to provided circle boundary.
    • getDistance

      public double getDistance(Point2D point)
      Returns distance from provided point to the closest point located in the circle boundary.
      Parameters:
      point - Point to be checked.
      Returns:
      Distance from point to circle boundary.
    • distance

      public static double distance(Circle circle, Point2D point)
      Returns distance from provided point to the closest point located in provided circle boundary.
      Parameters:
      circle - A circle.
      point - Point to be checked.
      Returns:
      Distance from point to provided circle boundary.
    • getClosestPoint

      public Point2D getClosestPoint(Point2D point) throws UndefinedPointException
      Returns closest point to provided point that is located in this circle boundary.
      Parameters:
      point - A point to be checked.
      Returns:
      Closest point laying in circle boundary.
      Throws:
      UndefinedPointException - Raised if provided point is at circle center or very close to it.
    • closestPoint

      public void closestPoint(Point2D point, Point2D result) throws UndefinedPointException
      Computes closest point to provided point that is located in this circle boundary and stores the result in provided result instance.
      Parameters:
      point - A point to be checked.
      result - Instance where result will be stored.
      Throws:
      UndefinedPointException - Raised if provided point is at circle center or very close to ti.
    • isLocus

      public boolean isLocus(Point2D point, double threshold)
      Determines whether provided point lies at circle boundary or not up to a certain threshold.
      Parameters:
      point - Point to be checked.
      threshold - A small threshold to determine whether point lies at circle boundary.
      Returns:
      True if point lies at circle boundary, false otherwise.
      Throws:
      IllegalArgumentException - Raised if provided threshold is negative.
    • isLocus

      public boolean isLocus(Point2D point)
      Determines whether provided point lies at circle boundary or not.
      Parameters:
      point - Point to be checked.
      Returns:
      True if point lies at circle boundary, false otherwise.
    • getTangentLineAt

      public Line2D getTangentLineAt(Point2D point) throws NotLocusException
      Returns a line tangent to this circle at provided point. Provided point must be locus of this circle, otherwise a NotLocusException will be thrown.
      Parameters:
      point - a locus point of this circle.
      Returns:
      a 2D line tangent to this circle at provided point.
      Throws:
      NotLocusException - if provided point is not locus of this circle up to DEFAULT_THRESHOLD.
    • getTangentLineAt

      public Line2D getTangentLineAt(Point2D point, double threshold) throws NotLocusException
      Returns a line tangent to this circle at provided point. Provided point must be locus of this circle, otherwise a NotLocusException will be thrown.
      Parameters:
      point - a locus point of this circle.
      threshold - threshold to determine if provided point is locus.
      Returns:
      a 2D line tangent to this circle at provided point.
      Throws:
      NotLocusException - if provided point is not locus of this circle up to provided threshold.
      IllegalArgumentException - if provided threshold is negative.
    • tangentLineAt

      public void tangentLineAt(Point2D point, Line2D line, double threshold) throws NotLocusException
      Computes a line tangent to this circle at provided point. Provided point must be locus of this circle, otherwise a NotLocusException will be thrown.
      Parameters:
      point - a locus point of this circle.
      line - instance of a 2D line where result will be stored.
      threshold - threshold to determine if provided point is locus.
      Throws:
      NotLocusException - if provided point is not locus of this circle up to provided threshold.
      IllegalArgumentException - if provided threshold is negative.
    • toConic

      public Conic toConic()
      Converts this circle into a conic. Conics are a more general representation of circles.
      Returns:
      A conic representing this circle.
    • setFromConic

      public final void setFromConic(Conic conic)
      Set parameters of this circle from a valid conic corresponding to a circle.
      Parameters:
      conic - conic to set parameters from.
      Throws:
      IllegalArgumentException - if provided conic is not a circle.