NASA World Wind

gov.nasa.worldwind.geom
Class Sphere

java.lang.Object
  extended by gov.nasa.worldwind.geom.Sphere
All Implemented Interfaces:
Extent, Renderable

public final class Sphere
extends Object
implements Extent, Renderable

Represents a sphere in three dimensional space.

Instances of Sphere are immutable.


Field Summary
static Sphere UNIT_SPHERE
           
 
Constructor Summary
Sphere(Vec4 center, double radius)
          Creates a new Sphere from a given center and radius.
 
Method Summary
static Vec4[] composeExtrema(Vec4[] points)
          Calculate the extrema of a given array of Vec4s.
static Sphere createBoundingSphere(Vec4[] points)
          Creates a sphere that completely contains a set of points.
 boolean equals(Object o)
           
 Vec4 getCenter()
          Obtains the center of this Sphere.
 double getDiameter()
          Obtains the diameter of this Sphere.
 double getRadius()
          Obtains the radius of this Sphere.
 int hashCode()
           
 Intersection[] intersect(Line line)
          Obtains the intersections of this sphere with a line.
 boolean intersects(Frustum frustum)
          tests for intersetion with a Frustum.
 boolean intersects(Line line)
          Tests for intersection with a Line.
 boolean intersects(Plane plane)
          Tests for intersection with a Plane.
 void render(DrawContext dc)
          Causes this Sphere to render itself using the DrawContext provided.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

UNIT_SPHERE

public static final Sphere UNIT_SPHERE
Constructor Detail

Sphere

public Sphere(Vec4 center,
              double radius)
Creates a new Sphere from a given center and radius. radius must be positive (that is, greater than zero), and center may not be null.

Parameters:
center - the center of the new sphere
radius - the radius of the new sphere
Throws:
IllegalArgumentException - if center is null or if radius is non-positive
Method Detail

composeExtrema

public static Vec4[] composeExtrema(Vec4[] points)
Calculate the extrema of a given array of Vec4s. The resulting array is always of length 2, with the first element containing the minimum extremum, and the second containing the maximum. The minimum extremum is composed by taking the smallest x, y and z values from all the Vec4s in the array. These values are not necessarily taken from the same Vec4. The maximum extrema is composed in the same fashion.

Parameters:
points - any array of Vec4s
Returns:
a array with length of 2, comprising the most extreme values in the given array
Throws:
IllegalArgumentException - if points is null

createBoundingSphere

public static Sphere createBoundingSphere(Vec4[] points)
Creates a sphere that completely contains a set of points.

Parameters:
points - the Vec4s to be enclosed by the new Sphere
Returns:
a Sphere encompassing the given array of Vec4s
Throws:
IllegalArgumentException - if points is null or empty

equals

public boolean equals(Object o)
Overrides:
equals in class Object

getCenter

public final Vec4 getCenter()
Obtains the center of this Sphere.

Specified by:
getCenter in interface Extent
Returns:
the Vec4 situated at the center of this Sphere

getDiameter

public final double getDiameter()
Obtains the diameter of this Sphere. The diameter is twice the radius.

Specified by:
getDiameter in interface Extent
Returns:
the diameter of this Sphere

getRadius

public final double getRadius()
Obtains the radius of this Sphere. The radus is the distance from the center to the surface. If an object's distance to this sphere's center is less than or equal to the radius, then that object is at least partially within this Sphere.

Specified by:
getRadius in interface Extent
Returns:
the radius of this sphere

hashCode

public int hashCode()
Overrides:
hashCode in class Object

intersect

public final Intersection[] intersect(Line line)
Obtains the intersections of this sphere with a line. The returned array may be either null or of zero length if no intersections are discovered. It does not contain null elements and will have a size of 2 at most. Tangential intersections are marked as such. line is considered to have infinite length in both directions.

Specified by:
intersect in interface Extent
Parameters:
line - the Line with which to intersect this Sphere
Returns:
an array containing all the intersections of this Sphere and line
Throws:
IllegalArgumentException - if line is null

intersects

public boolean intersects(Frustum frustum)
tests for intersetion with a Frustum. This operation is commutative, so someSphere.intersects(frustum) and frustum.intersects(someSphere) are equivalent.

Specified by:
intersects in interface Extent
Parameters:
frustum - the Frustum with which to test for intersection
Returns:
true if either frustum or this Sphere wholly or partially contain the other, false otherwise.
Throws:
IllegalArgumentException - if frustum is null

intersects

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

Specified by:
intersects in interface Extent
Parameters:
line - the Line with which to test for intersection
Returns:
true if line intersects or makes a tangent with the surface of this Sphere
Throws:
IllegalArgumentException - if line is null

intersects

public boolean intersects(Plane plane)
Tests for intersection with a Plane.

Specified by:
intersects in interface Extent
Parameters:
plane - the Plane with which to test for intersection
Returns:
true if plane intersects or makes a tangent with the surface of this Sphere
Throws:
IllegalArgumentException - if plane is null

render

public void render(DrawContext dc)
Causes this Sphere to render itself using the DrawContext provided. dc may not be null.

Specified by:
render in interface Renderable
Parameters:
dc - the DrawContext to be used
Throws:
IllegalArgumentException - if dc is null
See Also:
DrawContext

toString

public String toString()
Overrides:
toString in class Object

NASA World Wind