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
Sphereare immutable.
-
-
Field Summary
Fields Modifier and Type Field Description protected Vec4centerprotected doubleradiusstatic SphereUNIT_SPHERE
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SpherecreateBoundingSphere(Vec4[] points)Creates a sphere that completely contains a set of points.static SpherecreateBoundingSphere(BufferWrapper buffer)Creates a sphere that completely contains a set of points.static SpherecreateBoundingSphere(java.lang.Iterable<? extends Extent> extents)Creates a sphere that completely contains a set of Extents.booleanequals(java.lang.Object o)Vec4getCenter()Obtains the center of thisSphere.doublegetDiameter()Obtains the diameter of thisSphere.doublegetEffectiveRadius(Plane plane)Computes the effective radius of the extent relative to a specified plane.Vec4getPointOnSphere(LatLon location)Computes a point on the sphere corresponding to a specified location.doublegetProjectedArea(View view)Computes the area in square pixels of thisExtentafter it is projected into the specifiedview'sviewport.doublegetRadius()Obtains the radius of thisSphere.inthashCode()Intersection[]intersect(Line line)Obtains the intersections of this sphere with a line.booleanintersects(Frustum frustum)Indicates whether a specifiedFrustumintersects this sphere.booleanintersects(Line line)Tests for intersection with aLine.booleanintersects(Plane plane)Tests for intersection with aPlane.voidrender(DrawContext dc)Causes thisSphereto render itself using theDrawContextprovided.java.lang.StringtoString()
-
-
-
Constructor Detail
-
Sphere
public Sphere(Vec4 center, double radius)
Creates a newSpherefrom a given center and radius.radiusmust be positive (that is, greater than zero), andcentermay not be null.- Parameters:
center- the center of the new sphereradius- the radius of the new sphere- Throws:
java.lang.IllegalArgumentException- ifcenteris null or ifradiusis non-positive
-
-
Method Detail
-
createBoundingSphere
public static Sphere createBoundingSphere(Vec4[] points)
Creates a sphere that completely contains a set of points.- Parameters:
points- theVec4s to be enclosed by the new Sphere- Returns:
- a
Sphereencompassing the given array ofVec4s - Throws:
java.lang.IllegalArgumentException- ifpointsis 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
Sphereencompassing the given coordinates. - Throws:
java.lang.IllegalArgumentException- ifbufferis 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:
getDiameterin 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:
getEffectiveRadiusin 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.lineis considered to have infinite length in both directions.
-
intersects
public final boolean intersects(Frustum frustum)
Indicates whether a specifiedFrustumintersects this sphere.- Specified by:
intersectsin 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:
intersectsin interfaceExtent- Parameters:
line- theLinewith which to test for intersection- Returns:
- true if
lineintersects or makes a tangent with the surface of thisSphere - Throws:
java.lang.IllegalArgumentException- iflineis null
-
intersects
public boolean intersects(Plane plane)
Tests for intersection with aPlane.- Specified by:
intersectsin interfaceExtent- Parameters:
plane- thePlanewith which to test for intersection- Returns:
- true if
planeintersects or makes a tangent with the surface of thisSphere - Throws:
java.lang.IllegalArgumentException- ifplaneis null
-
getProjectedArea
public double getProjectedArea(View view)
Computes the area in square pixels of thisExtentafter it is projected into the specifiedview'sviewport. The returned value is the screen area that thisExtentcovers in the infinite plane defined by theview'sviewport. This area is not limited to the size of theview'sviewport, and portions of thisExtentare not clipped by theview'sfrustum.This returns
Double.POSITIVE_INFINITYif theview'seye point is inside thisExtent, or if any portion of thisExtentis behind the eye point. In either case, thisExtenthas no finite projection on theview.- Specified by:
getProjectedAreain interfaceExtent- Parameters:
view- theViewfor which to compute a projected screen area.- Returns:
- the projected screen area of this
Extentin square pixels, orDouble.POSITIVE_INFINITYif theview'seye point is inside thisExtentor part of thisExtentis behind theview'seye point.
-
render
public void render(DrawContext dc)
Causes thisSphereto render itself using theDrawContextprovided.dcmay not be null.- Specified by:
renderin interfaceRenderable- Parameters:
dc- theDrawContextto be used- Throws:
java.lang.IllegalArgumentException- ifdcis null- See Also:
DrawContext
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-