Package com.irurueta.geometry
Class Sphere
java.lang.Object
com.irurueta.geometry.Sphere
- All Implemented Interfaces:
Serializable
This class defines a sphere.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Point3DCenter of sphere.static final doubleConstant defining default threshold value used when none is provided.static final doubleConstant defining machine precision.static final doubleConstant defining minimum allowed radius.static final doubleConstant defining minimum allowed threshold.private doubleRadius of sphere. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclosestPoint(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 doubleReturns distance from provided point to the closest point located in provided sphere boundary.Returns center of sphere.getClosestPoint(Point3D point) Returns closest point to provided point that is located in this sphere boundary.doublegetDistance(Point3D point) Returns distance from provided point to the closest point located in the sphere boundary.doubleReturns radius of sphere.doublegetSignedDistance(Point3D point) Returns distance from provided point to the closest point located in the sphere boundary.doubleReturns surface of this sphere.getTangentPlaneAt(Point3D point) 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.doubleReturns volume of this sphere.booleanDetermines if provided point is inside this sphere or not.booleanDetermines if provided point is inside this sphere or not up to a certain threshold.booleanDetermines whether provided point lies at sphere boundary or not.booleanDetermines whether provided point lies at sphere boundary or not up to a certain threshold.voidSets center of sphere.final voidsetCenterAndRadius(Point3D center, double radius) Sets center and radius of this sphere.final voidsetFromQuadric(Quadric quadric) Sets parameters of this sphere from a valid quadric corresponding to a sphere.final voidsetParametersFromPoints(Point3D point1, Point3D point2, Point3D point3, Point3D point4) Sets parameters of a sphere by using four points that must belong to its locus.voidsetRadius(double radius) Sets radius of sphere.static doublesignedDistance(Sphere sphere, Point3D point) Returns distance from provided point to the closest point located in provided sphere boundary.static doublesurface(double radius) Returns surface of a sphere having provided radius.voidtangentPlaneAt(Point3D point, Plane plane, double threshold) Computes a plane tangent to this sphere at provided point.Converts this sphere into a quadric.static doublevolume(double radius) Returns volume of a sphere having provided radius.
-
Field Details
-
MIN_RADIUS
public static final double MIN_RADIUSConstant defining minimum allowed radius.- See Also:
-
DEFAULT_THRESHOLD
public static final double DEFAULT_THRESHOLDConstant defining default threshold value used when none is provided.- See Also:
-
MIN_THRESHOLD
public static final double MIN_THRESHOLDConstant defining minimum allowed threshold.- See Also:
-
EPS
public static final double EPSConstant defining machine precision.- See Also:
-
center
Center of sphere. -
radius
private double radiusRadius of sphere.
-
-
Constructor Details
-
Sphere
public Sphere()Empty constructor. Creates sphere located at space origin (0,0) with radius 1.0. -
Sphere
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
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
Returns center of sphere.- Returns:
- Center of sphere.
-
setCenter
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Converts this sphere into a quadric. Quadrics are a more general representation of spheres.- Returns:
- A quadric representing this circle.
-
setFromQuadric
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.
-