Package gov.nasa.worldwind.geom
Class Sphere
- java.lang.Object
-
- gov.nasa.worldwind.geom.Sphere
-
- All Implemented Interfaces:
Extent
,Renderable
public final class Sphere extends java.lang.Object implements Extent, Renderable
Represents a sphere in three dimensional space.Instances of
Sphere
are immutable.
-
-
Field Summary
Fields Modifier and Type Field Description protected Vec4
center
protected double
radius
static Sphere
UNIT_SPHERE
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Sphere
createBoundingSphere(Vec4[] points)
Creates a sphere that completely contains a set of points.static Sphere
createBoundingSphere(BufferWrapper buffer)
Creates a sphere that completely contains a set of points.static Sphere
createBoundingSphere(java.lang.Iterable<? extends Extent> extents)
Creates a sphere that completely contains a set of Extents.boolean
equals(java.lang.Object o)
Vec4
getCenter()
Obtains the center of thisSphere
.double
getDiameter()
Obtains the diameter of thisSphere
.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 thisExtent
after it is projected into the specifiedview's
viewport.double
getRadius()
Obtains the radius of thisSphere
.int
hashCode()
Intersection[]
intersect(Line line)
Obtains the intersections of this sphere with a line.boolean
intersects(Frustum frustum)
Indicates whether a specifiedFrustum
intersects this sphere.boolean
intersects(Line line)
Tests for intersection with aLine
.boolean
intersects(Plane plane)
Tests for intersection with aPlane
.void
render(DrawContext dc)
Causes thisSphere
to render itself using theDrawContext
provided.java.lang.String
toString()
-
-
-
Constructor Detail
-
Sphere
public Sphere(Vec4 center, double radius)
Creates a newSphere
from a given center and radius.radius
must be positive (that is, greater than zero), andcenter
may not be null.- Parameters:
center
- the center of the new sphereradius
- the radius of the new sphere- Throws:
java.lang.IllegalArgumentException
- ifcenter
is null or ifradius
is non-positive
-
-
Method Detail
-
createBoundingSphere
public static Sphere createBoundingSphere(Vec4[] points)
Creates a sphere that completely contains a set of points.- Parameters:
points
- theVec4
s to be enclosed by the new Sphere- Returns:
- a
Sphere
encompassing the given array ofVec4
s - Throws:
java.lang.IllegalArgumentException
- ifpoints
is null or empty
-
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:
java.lang.IllegalArgumentException
- ifbuffer
is null or contains fewer than three values.
-
createBoundingSphere
public static Sphere createBoundingSphere(java.lang.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:
java.lang.IllegalArgumentException
- if the Iterable is null.
-
getRadius
public final double getRadius()
Obtains the radius of thisSphere
. 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 thisSphere
.
-
getDiameter
public final double getDiameter()
Obtains the diameter of thisSphere
. The diameter is twice the radius.- Specified by:
getDiameter
in interfaceExtent
- Returns:
- the diameter of this
Sphere
-
getCenter
public final Vec4 getCenter()
Obtains the center of thisSphere
.
-
getEffectiveRadius
public double getEffectiveRadius(Plane plane)
Computes the effective radius of the extent relative to a specified plane.- Specified by:
getEffectiveRadius
in interfaceExtent
- 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:
java.lang.IllegalArgumentException
- if the location is null.
-
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.
-
intersects
public final boolean intersects(Frustum frustum)
Indicates whether a specifiedFrustum
intersects this sphere.- Specified by:
intersects
in interfaceExtent
- Parameters:
frustum
- the frustum to test.- Returns:
- true if the specified frustum intersects this sphere, otherwise false.
- Throws:
java.lang.IllegalArgumentException
- if the frustum is null.
-
intersects
public boolean intersects(Line line)
Tests for intersection with aLine
.- Specified by:
intersects
in interfaceExtent
- Parameters:
line
- theLine
with which to test for intersection- Returns:
- true if
line
intersects or makes a tangent with the surface of thisSphere
- Throws:
java.lang.IllegalArgumentException
- ifline
is null
-
intersects
public boolean intersects(Plane plane)
Tests for intersection with aPlane
.- Specified by:
intersects
in interfaceExtent
- Parameters:
plane
- thePlane
with which to test for intersection- Returns:
- true if
plane
intersects or makes a tangent with the surface of thisSphere
- Throws:
java.lang.IllegalArgumentException
- ifplane
is null
-
getProjectedArea
public double getProjectedArea(View view)
Computes the area in square pixels of thisExtent
after it is projected into the specifiedview's
viewport. The returned value is the screen area that thisExtent
covers in the infinite plane defined by theview's
viewport. This area is not limited to the size of theview's
viewport, and portions of thisExtent
are not clipped by theview's
frustum.This returns
Double.POSITIVE_INFINITY
if theview's
eye point is inside thisExtent
, or if any portion of thisExtent
is behind the eye point. In either case, thisExtent
has no finite projection on theview
.- Specified by:
getProjectedArea
in interfaceExtent
- Parameters:
view
- theView
for which to compute a projected screen area.- Returns:
- the projected screen area of this
Extent
in square pixels, orDouble.POSITIVE_INFINITY
if theview's
eye point is inside thisExtent
or part of thisExtent
is behind theview's
eye point.
-
render
public void render(DrawContext dc)
Causes thisSphere
to render itself using theDrawContext
provided.dc
may not be null.- Specified by:
render
in interfaceRenderable
- Parameters:
dc
- theDrawContext
to be used- Throws:
java.lang.IllegalArgumentException
- ifdc
is null- See Also:
DrawContext
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-