ProGAL.geom3d.volumes
Class Sphere

java.lang.Object
  extended by ProGAL.geom3d.volumes.Sphere
All Implemented Interfaces:
Shape, Volume

public class Sphere
extends java.lang.Object
implements Volume

A sphere represented by a center-point and a radius.


Constructor Summary
Sphere(Circle c)
          creates a sphere with the specified circle as equator
Sphere(CTetrahedron tetr)
           
Sphere(Point[] points)
           
Sphere(Point center, double radius)
          Constructs a sphere with the specified center and the specified radius.
Sphere(Point p0, Point p1, Point p2, Point p3)
           
Sphere(PointWeighted p)
          Constructs a sphere with the weighted point as center and a radius with the square root of the points weight.
 
Method Summary
 Sphere clone()
          Returns a deep clone of this sphere.
 boolean contains(Point p)
          Returns true if the given point is in the sphere.
 boolean containsNone(java.util.List<Point> points)
          Returns true if none of the given points is in the sphere.
 PointList generatePointsOnSphere(int n)
          TODO: Comment, move up and test
 PointList generateRandomPointsOnSphere(int n)
          TODO: Comment, move up and test
 Point getCenter()
          Get the center
 LineSegment getIntersection(Line line)
          Gets the secant on the line.
 java.lang.Double getIntersectionAngle(Circle c, Point p, Vector dir)
           
 Point[] getIntersections(Circle c)
           
static Point[] getIntersections(Sphere s1, Sphere s2, Sphere s3)
          Find the two, one or zero points that is at the intersection of the three sphere shells.
static Sphere getMinSphere(Circle c)
          Get the sphere with the specified circle as equator
static Sphere getMinSphere(PointList points)
          Gets the smallest sphere containing a set of points.
static Sphere getMinSphere(Point p1, Point p2)
          Get the smallest sphere through two given points.
static Sphere getMinSphere(Point p0, Point p1, Point p2)
          Get the smallest sphere through three points.
static Sphere getMinSphere(Point p0, Point p1, Point p2, Point p3)
          Constructs the sphere through four points.
 double getRadius()
          Get the radius
 double getRadiusSquared()
          Get the squared radius
 double getSurfaceArea()
          Get the surface area
 double getVolume()
          Get the volume
 double[] intersectionParameters(Line line)
          Returns the two line-parameters that indicate where line intersects this sphere.
 boolean isEmpty(Point[] points, double eps)
           
 boolean isInside(Point p)
          Returns true if the point is inside this sphere
 boolean isInside(Point p, double eps)
           
 boolean isIntersected(Sphere sphere)
          Returns true if this sphere is intersected or touched by another sphere.
static void main(java.lang.String[] args)
           
 boolean overlaps(Volume vol)
          Returns true if the sphere overlaps with vol.
 double powerDistance(Point p)
          Gets the squared distance of a point from a sphere surface (negative if the point is inside the sphere).
 void setCenter(Point center)
           
 void setCenter(Point p0, Point p1, Point p2, Point p3)
           
 void setRadius(double radius)
           
 void toConsole()
          Writes this sphere to System.out.
 void toConsole(int dec)
          Writes this sphere to System.out with dec decimals precision.
 void toScene(J3DScene scene, java.awt.Color clr)
           
 java.lang.String toString()
          Return a string representation of this sphere.
 java.lang.String toString(int dec)
          Return a string representation of this sphere with dec decimals precision
static double unionVolume_Grid(java.util.Collection<Sphere> spheres)
          Estimate the volume of the union of a set of spheres.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Sphere

public Sphere(Point center,
              double radius)
Constructs a sphere with the specified center and the specified radius.


Sphere

public Sphere(Point[] points)

Sphere

public Sphere(Point p0,
              Point p1,
              Point p2,
              Point p3)

Sphere

public Sphere(CTetrahedron tetr)

Sphere

public Sphere(PointWeighted p)
Constructs a sphere with the weighted point as center and a radius with the square root of the points weight.


Sphere

public Sphere(Circle c)
creates a sphere with the specified circle as equator

Method Detail

getCenter

public Point getCenter()
Get the center

Specified by:
getCenter in interface Shape

getRadius

public double getRadius()
Get the radius


getRadiusSquared

public double getRadiusSquared()
Get the squared radius


getSurfaceArea

public double getSurfaceArea()
Get the surface area


getVolume

public double getVolume()
Get the volume

Specified by:
getVolume in interface Volume

isInside

public boolean isInside(Point p)
Returns true if the point is inside this sphere


isInside

public boolean isInside(Point p,
                        double eps)

isEmpty

public boolean isEmpty(Point[] points,
                       double eps)

setCenter

public void setCenter(Point center)

setCenter

public void setCenter(Point p0,
                      Point p1,
                      Point p2,
                      Point p3)

setRadius

public void setRadius(double radius)

isIntersected

public boolean isIntersected(Sphere sphere)
Returns true if this sphere is intersected or touched by another sphere.


getIntersection

public LineSegment getIntersection(Line line)
Gets the secant on the line. TODO: Rename.


intersectionParameters

public double[] intersectionParameters(Line line)
Returns the two line-parameters that indicate where line intersects this sphere. TODO: Coordinate line-intersection methods (see above).


getIntersections

public Point[] getIntersections(Circle c)

getIntersectionAngle

public java.lang.Double getIntersectionAngle(Circle c,
                                             Point p,
                                             Vector dir)

containsNone

public boolean containsNone(java.util.List<Point> points)
Returns true if none of the given points is in the sphere.


contains

public boolean contains(Point p)
Returns true if the given point is in the sphere.


powerDistance

public double powerDistance(Point p)
Gets the squared distance of a point from a sphere surface (negative if the point is inside the sphere).


toString

public java.lang.String toString()
Return a string representation of this sphere.

Overrides:
toString in class java.lang.Object

toString

public java.lang.String toString(int dec)
Return a string representation of this sphere with dec decimals precision


toConsole

public void toConsole()
Writes this sphere to System.out.


toConsole

public void toConsole(int dec)
Writes this sphere to System.out with dec decimals precision.


toScene

public void toScene(J3DScene scene,
                    java.awt.Color clr)

overlaps

public boolean overlaps(Volume vol)
Returns true if the sphere overlaps with vol. TODO: Implement for all volumes.

Specified by:
overlaps in interface Volume

clone

public Sphere clone()
Returns a deep clone of this sphere.

Specified by:
clone in interface Volume
Overrides:
clone in class java.lang.Object

getMinSphere

public static Sphere getMinSphere(Circle c)
Get the sphere with the specified circle as equator


getMinSphere

public static Sphere getMinSphere(Point p1,
                                  Point p2)
Get the smallest sphere through two given points.


getMinSphere

public static Sphere getMinSphere(Point p0,
                                  Point p1,
                                  Point p2)
Get the smallest sphere through three points.


getMinSphere

public static Sphere getMinSphere(Point p0,
                                  Point p1,
                                  Point p2,
                                  Point p3)
Constructs the sphere through four points. An error is thrown if the points are coplanar.


getMinSphere

public static Sphere getMinSphere(PointList points)
Gets the smallest sphere containing a set of points. Uses a randomized, O(n) expected time algorithm.


getIntersections

public static Point[] getIntersections(Sphere s1,
                                       Sphere s2,
                                       Sphere s3)
Find the two, one or zero points that is at the intersection of the three sphere shells. If the three spheres intersect in more than two points or one sphere contains another, the result of this method not specified.


main

public static void main(java.lang.String[] args)

unionVolume_Grid

public static double unionVolume_Grid(java.util.Collection<Sphere> spheres)
Estimate the volume of the union of a set of spheres. A grid is placed around the spheres and the volume of the cells are used to compute an upper and a lower bound. The average value of the upper and lower bound is used. Typically the result is accurate to 1/100 (not to 1/1000) and takes around 150ms to compute.


generateRandomPointsOnSphere

public PointList generateRandomPointsOnSphere(int n)
TODO: Comment, move up and test


generatePointsOnSphere

public PointList generatePointsOnSphere(int n)
TODO: Comment, move up and test