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
protected  Vec4 center
           
protected  double radius
           
static Sphere UNIT_SPHERE
           
 
Constructor Summary
Sphere(Vec4 center, double radius)
          Creates a new Sphere from a given center and radius.
 
Method Summary
static Sphere createBoundingSphere(BufferWrapper buffer)
          Creates a sphere that completely contains a set of points.
static Sphere createBoundingSphere(Iterable<? extends Extent> extents)
          Creates a sphere that completely contains a set of Extents.
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 getEffectiveRadius(Plane plane)
          Computes the effective radius of the extent relative to a specified plane.
 Vec4 getPointOnSphere(LatLon location)
          Computes a point on the sphere corresponding to a specified location.
 double getProjectedArea(View view)
          Computes the area in square pixels of this Extent after it is projected into the specified view's viewport.
 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)
          Indicates whether a specified Frustum intersects this sphere.
 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

center

protected final Vec4 center

radius

protected final double radius

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

createBoundingSphere

public static Sphere createBoundingSphere(BufferWrapper buffer)
Creates a sphere that completely contains a set of points.

Parameters:
buffer - the Cartesian coordinates to be enclosed by the new Sphere.
Returns:
a Sphere encompassing the given coordinates.
Throws:
IllegalArgumentException - if buffer is null or contains fewer than three values.

createBoundingSphere

public static Sphere createBoundingSphere(Iterable<? extends Extent> extents)
Creates a sphere that completely contains a set of Extents. This returns null if the specified Iterable is empty or contains only null elements. Note that this does not compute an optimal bounding sphere. The returned sphere is computed as follows: the center is the mean of all center points in the specified set of Extents, and the radius is smallest value which defines a sphere originating at the computed center point and containing all the specified Extents.

Parameters:
extents - the extends to be enclosed by the new Sphere.
Returns:
a new Sphere encompassing the given Extents.
Throws:
IllegalArgumentException - if the Iterable 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

getEffectiveRadius

public double getEffectiveRadius(Plane plane)
Computes the effective radius of the extent relative to a specified plane.

Specified by:
getEffectiveRadius in interface Extent
Parameters:
plane - the plane.
Returns:
the effective radius, or 0 if the plane is null.

getPointOnSphere

public Vec4 getPointOnSphere(LatLon location)
Computes a point on the sphere corresponding to a specified location.

Parameters:
location - the location to compute the point for.
Returns:
the Cartesian coordinates of the corresponding location on the sphere.
Throws:
IllegalArgumentException - if the location is null.

getProjectedArea

public double getProjectedArea(View view)
Computes the area in square pixels of this Extent after it is projected into the specified view's viewport. The returned value is the screen area that this Extent covers in the infinite plane defined by the view's viewport. This area is not limited to the size of the view's viewport, and portions of this Extent are not clipped by the view's frustum.

This returns Double.POSITIVE_INFINITY if the view's eye point is inside this Extent, or if any portion of this Extent is behind the eye point. In either case, this Extent has no finite projection on the view.

Specified by:
getProjectedArea in interface Extent
Parameters:
view - the View for which to compute a projected screen area.
Returns:
the projected screen area of this Extent in square pixels, or Double.POSITIVE_INFINITY if the view's eye point is inside this Extent or part of this Extent is behind the view's eye point.

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 final boolean intersects(Frustum frustum)
Indicates whether a specified Frustum intersects this sphere.

Specified by:
intersects in interface Extent
Parameters:
frustum - the frustum to test.
Returns:
true if the specified frustum intersects this sphere, otherwise false.
Throws:
IllegalArgumentException - if the 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