org.apache.commons.math3.geometry.euclidean.threed
Class Sphere

java.lang.Object
  extended by org.apache.commons.math3.geometry.euclidean.threed.Sphere
All Implemented Interfaces:
Serializable, CrossSectionProvider, IEllipsoid, Shape, SolidShape

public final class Sphere
extends Object
implements IEllipsoid, CrossSectionProvider, Serializable

This is a describing class for a 3D spherical shape, with some algorithm to compute intersections and distances to some other objects.

Since:
1.0
Version:
$Id: Sphere.java 11374 2014-10-30 15:39:29Z sabatini $
Author:
Thomas Trapier
See Also:
Shape.distanceTo(Line), Shape.intersects(Line), Serialized Form
Use sample :

Creation with a double and a Vector3D : Vector3D center = new Vector3D(1.0, 6.0, -2.0); Sphere sphere = new Sphere(center, 2.0); Intersection with a line : boolean intersects = sphere.intersects(line);

Concurrency :
immutable

Constructor Summary
Sphere(Vector3D inCenter, double inRadius)
          Build a sphere from its radius and the position of its center
 
Method Summary
 Vector3D[] closestPointTo(Line line)
          Computes the points of the shape and the line realizing the shortest distance.
 Vector3D closestPointTo(Vector3D point)
          Computes the point, on the ellipsoid surface, that is the closest to a point of space.
 double distanceTo(Line line)
          Computes the distance to a line.
 double distanceTo(Vector3D point)
          Computes the distance to a point of space.
 Vector3D getCenter()
          Get ellipsoids' center
 double getCrossSection(Vector3D direction)
          Computes the cross section from the direction defined by a Vector3D.
 Vector3D[] getIntersectionPoints(Line line)
          Compute the intersection points with a line.
 Vector3D getNormal(Vector3D point)
          Computes the normal vector to the surface
 double getRadius()
           
 double getSemiA()
          Get semi axis A
 double getSemiB()
          Get semi axis B
 double getSemiC()
          Get semi axis C
 boolean intersects(Line line)
          Tests the intersection with a line.
 String toString()
          Get a representation for this sphere.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Sphere

public Sphere(Vector3D inCenter,
              double inRadius)
Build a sphere from its radius and the position of its center

Parameters:
inCenter - the center of the sphere
inRadius - the radius of the sphere
Throws:
IllegalArgumentException - if the radius is negative
Method Detail

getRadius

public double getRadius()
Returns:
the radius

getCenter

public Vector3D getCenter()
Description copied from interface: IEllipsoid
Get ellipsoids' center

Specified by:
getCenter in interface IEllipsoid
Returns:
the center

intersects

public boolean intersects(Line line)
Tests the intersection with a line.

Specified by:
intersects in interface Shape
Parameters:
line - the line
Returns:
true if the line intersects the shape

distanceTo

public double distanceTo(Line line)
Computes the distance to a line.

Specified by:
distanceTo in interface Shape
Parameters:
line - the line
Returns:
the shortest distance between the the line and the shape

distanceTo

public double distanceTo(Vector3D point)
Computes the distance to a point of space.

Parameters:
point - the point
Returns:
the shortest distance between the surface of the sphere and the point

getIntersectionPoints

public Vector3D[] getIntersectionPoints(Line line)
Compute the intersection points with a line.

Specified by:
getIntersectionPoints in interface Shape
Parameters:
line - the line
Returns:
the intersection points if they exist. If no intersection is found, the dimension is zero

closestPointTo

public Vector3D[] closestPointTo(Line line)
Computes the points of the shape and the line realizing the shortest distance. If the line intersects the shape, the returned points are identical : this point is the first common point found.

Specified by:
closestPointTo in interface Shape
Parameters:
line - the line
Returns:
the two points : first the one from the line, and the one from the shape.

closestPointTo

public Vector3D closestPointTo(Vector3D point)
Computes the point, on the ellipsoid surface, that is the closest to a point of space.

Specified by:
closestPointTo in interface IEllipsoid
Parameters:
point - the point expressed in standard basis
Returns:
the closest point to the user point on the ellipsoid surface

getNormal

public Vector3D getNormal(Vector3D point)
Computes the normal vector to the surface

Specified by:
getNormal in interface IEllipsoid
Parameters:
point - Point as a Vector3D
Returns:
the normal vector in local basis

toString

public String toString()
Get a representation for this sphere. The given parameters are in the same order as in the constructor.

Overrides:
toString in class Object
Returns:
a representation for this sphere

getCrossSection

public double getCrossSection(Vector3D direction)
Computes the cross section from the direction defined by a Vector3D.

Specified by:
getCrossSection in interface CrossSectionProvider
Parameters:
direction - the direction vector
Returns:
the cross section

getSemiA

public double getSemiA()
Get semi axis A

Specified by:
getSemiA in interface IEllipsoid
Returns:
semi axis a

getSemiB

public double getSemiB()
Get semi axis B

Specified by:
getSemiB in interface IEllipsoid
Returns:
semi axis b

getSemiC

public double getSemiC()
Get semi axis C

Specified by:
getSemiC in interface IEllipsoid
Returns:
semi axis c


Copyright © 2016 CNES. All Rights Reserved.