Class Sphere

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

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

    Fields
    Modifier and Type
    Field
    Description
    private Point3D
    Center of sphere.
    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 sphere.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Empty constructor.
    Sphere(Point3D center, double radius)
    Constructor.
    Sphere(Point3D point1, Point3D point2, Point3D point3, Point3D point4)
    Constructor.
    Sphere(Quadric quadric)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    closestPoint(Point3D point, Point3D result)
    Computes closest point to provided point that is located in this sphere boundary and stores the result in provided result instance.
    static double
    distance(Sphere sphere, Point3D point)
    Returns distance from provided point to the closest point located in provided sphere boundary.
    Returns center of sphere.
    Returns closest point to provided point that is located in this sphere boundary.
    double
    Returns distance from provided point to the closest point located in the sphere boundary.
    double
    Returns radius of sphere.
    double
    Returns distance from provided point to the closest point located in the sphere boundary.
    double
    Returns surface of this sphere.
    Returns a plane tangent to this sphere at provided point.
    getTangentPlaneAt(Point3D point, double threshold)
    Returns a plane tangent to this sphere at provided point.
    double
    Returns volume of this sphere.
    boolean
    Determines if provided point is inside this sphere or not.
    boolean
    isInside(Point3D point, double threshold)
    Determines if provided point is inside this sphere or not up to a certain threshold.
    boolean
    Determines whether provided point lies at sphere boundary or not.
    boolean
    isLocus(Point3D point, double threshold)
    Determines whether provided point lies at sphere boundary or not up to a certain threshold.
    void
    Sets center of sphere.
    final void
    setCenterAndRadius(Point3D center, double radius)
    Sets center and radius of this sphere.
    final void
    Sets parameters of this sphere from a valid quadric corresponding to a sphere.
    final void
    setParametersFromPoints(Point3D point1, Point3D point2, Point3D point3, Point3D point4)
    Sets parameters of a sphere by using four points that must belong to its locus.
    void
    setRadius(double radius)
    Sets radius of sphere.
    static double
    signedDistance(Sphere sphere, Point3D point)
    Returns distance from provided point to the closest point located in provided sphere boundary.
    static double
    surface(double radius)
    Returns surface of a sphere having provided radius.
    void
    tangentPlaneAt(Point3D point, Plane plane, double threshold)
    Computes a plane tangent to this sphere at provided point.
    Converts this sphere into a quadric.
    static double
    volume(double radius)
    Returns volume of a sphere having provided radius.

    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 Point3D center
      Center of sphere.
    • radius

      private double radius
      Radius of sphere.
  • Constructor Details

    • Sphere

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

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

      public Sphere(Point3D point1, Point3D point2, Point3D point3, Point3D point4) throws CoplanarPointsException
      Constructor. Computes a sphere by using 4 points that must belong to its locus.
      Parameters:
      point1 - point 1.
      point2 - point 2.
      point3 - point 3.
      point4 - point 4.
      Throws:
      CoplanarPointsException - if provided set of points are coincident or coplanar (form a single plane). In such cases a singularity occurs since a sphere having an infinite radius would be required to contain all four points in its locus.
    • Sphere

      public Sphere(Quadric quadric)
      Constructor. Computes a sphere from a valid quadric corresponding to a sphere
      Parameters:
      quadric - a quadric to create a sphere from.
      Throws:
      IllegalArgumentException - if provided quadric is not a sphere.
  • Method Details

    • getCenter

      public Point3D getCenter()
      Returns center of sphere.
      Returns:
      Center of sphere.
    • setCenter

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

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

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

      public final void setCenterAndRadius(Point3D center, double radius)
      Sets center and radius of this sphere.
      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(Point3D point1, Point3D point2, Point3D point3, Point3D point4) throws CoplanarPointsException
      Sets parameters of a sphere by using four points that must belong to its locus.
      Parameters:
      point1 - point 1.
      point2 - point 2.
      point3 - point 3.
      point4 - point 4.
      Throws:
      CoplanarPointsException - if provided set of points are coincident or coplanar (form a single plane). In such cases a singularity occurs since a sphere having an infinite radius would be required to contain all four points in its locus.
    • volume

      public static double volume(double radius)
      Returns volume of a sphere having provided radius.
      Parameters:
      radius - Radius of a sphere.
      Returns:
      Volume of a sphere having provided radius.
      Throws:
      IllegalArgumentException - Raised if provided radius is negative.
    • getVolume

      public double getVolume()
      Returns volume of this sphere.
      Returns:
      Volume of this sphere.
    • surface

      public static double surface(double radius)
      Returns surface of a sphere having provided radius.
      Parameters:
      radius - Radius of a sphere.
      Returns:
      Surface of a sphere having provided radius.
      Throws:
      IllegalArgumentException - Raised if provided radius is negative.
    • getSurface

      public double getSurface()
      Returns surface of this sphere.
      Returns:
      Surface of this sphere.
    • isInside

      public boolean isInside(Point3D point, double threshold)
      Determines if provided point is inside this sphere or not up to a certain threshold. If provided threshold is positive, the sphere behaves as if it was a larger sphere increased by threshold amount, if provided threshold is negative, the sphere behaves as if it was a smaller sphere 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 sphere, false otherwise.
    • isInside

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

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

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

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

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

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

      public void closestPoint(Point3D point, Point3D result) throws UndefinedPointException
      Computes closest point to provided point that is located in this sphere 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 sphere center or very close to ti.
    • isLocus

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

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

      public Plane getTangentPlaneAt(Point3D point) throws NotLocusException
      Returns a plane tangent to this sphere at provided point. Provided point must be locus of this sphere, otherwise a NotLocusException will be thrown.
      Parameters:
      point - a locus point of this sphere.
      Returns:
      a 3D plane tangent to this sphere at provided point.
      Throws:
      NotLocusException - if provided point is not locus of this sphere up to DEFAULT_THRESHOLD.
    • getTangentPlaneAt

      public Plane getTangentPlaneAt(Point3D point, double threshold) throws NotLocusException
      Returns a plane tangent to this sphere at provided point. Provided point must be locus of this sphere, otherwise a NotLocusException will be thrown.
      Parameters:
      point - a locus point of this sphere.
      threshold - threshold to determine if provided point is locus.
      Returns:
      a 3D plane tangent to this circle at provided point.
      Throws:
      NotLocusException - if provided point is not locus of this sphere up to provided threshold.
      IllegalArgumentException - if provided threshold is negative.
    • tangentPlaneAt

      public void tangentPlaneAt(Point3D point, Plane plane, double threshold) throws NotLocusException
      Computes a plane tangent to this sphere at provided point. Provided point must be locus of this sphere, otherwise a NotLocusException will be thrown.
      Parameters:
      point - a locus point of this sphere.
      plane - instance of a 3D plane where result will be stored.
      threshold - threshold to determine if provided point is locus.
      Throws:
      NotLocusException - if provided point is not locus of this sphere.
      IllegalArgumentException - if provided threshold is negative.
    • toQuadric

      public Quadric toQuadric()
      Converts this sphere into a quadric. Quadrics are a more general representation of spheres.
      Returns:
      A quadric representing this circle.
    • setFromQuadric

      public final void setFromQuadric(Quadric quadric)
      Sets parameters of this sphere from a valid quadric corresponding to a sphere.
      Parameters:
      quadric - quadric to set parameters from.
      Throws:
      IllegalArgumentException - if provided quadric is not a sphere.