com.hedgehog.geo.threed.shapes
Class Ellipsoid3D

java.lang.Object
  extended by com.hedgehog.HObject
      extended by com.hedgehog.geo.GeometricObject
          extended by com.hedgehog.geo.threed.GeometricObject3D
              extended by com.hedgehog.geo.threed.shapes.Shape3D
                  extended by com.hedgehog.geo.threed.shapes.Ellipsoid3D
All Implemented Interfaces:
ModelObject, java.lang.Comparable, java.util.Comparator
Direct Known Subclasses:
Spheroid3D

public class Ellipsoid3D
extends Shape3D
implements ModelObject

Title: Ellipsoid3D - models a 3D ellipsoid.

Description: Models a 3D ellipsoid, having a centre, radii and local axes.

Copyright: Copyright (c) Hedgehog Software 2007-2009.

Company: Hedgehog Software

Since:
1.0
Version:
1.1

Field Summary
protected  Point3D mCentre
          Ellipsoid centre.
protected  Vector3D mlxAxis
          Local x-axis vector.
protected  Vector3D mlyAxis
          Local y-axis vector.
protected  Vector3D mlzAxis
          Local z-axis vector.
protected  double mxRadius
          Radius in local x-axis direction.
protected  double myRadius
          Radius in local y-axis direction.
protected  double mzRadius
          Radius in local z-axis direction.
 
Fields inherited from class com.hedgehog.HObject
mID, mName
 
Constructor Summary
Ellipsoid3D()
          Default constructor.
Ellipsoid3D(Ellipsoid3D object)
          Copy constructor.
Ellipsoid3D(ID id)
          Constructor.
Ellipsoid3D(Point3D centre, double xRadius, double yRadius, double zRadius)
          Constructor.
Ellipsoid3D(Point3D centre, double xRadius, double yRadius, double zRadius, Vector3D lxAxis, Vector3D lyAxis, Vector3D lzAxis)
          Constructor.
Ellipsoid3D(java.lang.String name)
          Constructor.
Ellipsoid3D(java.lang.String name, ID id)
          Constructor.
 
Method Summary
 double area()
          Returns the surface area of this ellipsoid.
 Point3D axisPointOnNegativeLocalXAxis()
          Returns the point of intersection between the negative local x-axis and the ellipsoid surface.
 Point3D axisPointOnNegativeLocalYAxis()
          Returns the point of intersection between the negative local y-axis and the ellipsoid surface.
 Point3D axisPointOnNegativeLocalZAxis()
          Returns the point of intersection between the negative local z-axis and the ellipsoid surface.
 Point3D axisPointOnPositiveLocalXAxis()
          Returns the point of intersection between the positive local x-axis and the ellipsoid surface.
 Point3D axisPointOnPositiveLocalYAxis()
          Returns the point of intersection between the positive local x-axis and the ellipsoid surface.
 Point3D axisPointOnPositiveLocalZAxis()
          Returns the point of intersection between the positive local z-axis and the ellipsoid surface.
 AxisAlignedBox3D boundingBox()
          Returns the bounding box of this ellipsoid.
 Point3D centroid()
          Returns the centroid of this ellipsoid; ie the centre.
 java.util.Vector<ModelObject> childModelObjects()
          Returns a vector of this object's child ModelObject objects.
 java.sql.PreparedStatement databaseInsertStatement(java.sql.Connection connection, int modelID)
          Returns a prepared statement for inserting (INSERT command) a ModelObject object into a database.
 java.sql.PreparedStatement databaseUpdateStatement(java.sql.Connection connection, int modelID)
          Returns a prepared statement for updating (UPDATE command) a ModelObject object into a database.
 HDouble ellipsoidImplicitFunction(Vector3D v)
          Method for OneVariableVector3DFunction implicit function.
 double evaluate(Point3D p)
          Evaluates the quadratic Q(X) = (X-K)^T * M * (X-K) - 1 for the specified point.
 ModelObject fromDatabase(java.sql.Connection connection, Model model, int modelID, int objectID)
          Returns a model object from the specified database table.
 ModelObject fromXMLNode(org.w3c.dom.Document document, org.w3c.dom.Node documentRootNode, org.w3c.dom.Node node, Model model)
          Returns a model object from the specified xml node.
 Point3D furthestPoint(Point3D q, double tolerance)
          Returns the furthest point on this ellipsoid's surfacae from the specified point.
 double gaussCurvature(Point3D p)
          Returns the Gauss curvature at the specified point.
 Vector3D getAxis(int axisIndex, boolean normalise)
          Returns the local axis.
 Point3D getCentre()
          Returns the centre.
 Matrix3x3 getM()
          Compute M = sum_{i=0}^2 U[i]*U[i]^T/e[i]^2.
 double getRadius(int radiusIndex)
          Returns the ellipsoid radius for the specified axis.
 Vector3D getXAxis(boolean normalise)
          Returns the x-axis.
 double getXRadius()
          Returns the x-axis radius.
 Vector3D getYAxis(boolean normalise)
          Returns the y-axis.
 double getYRadius()
          Returns the y-axis radius.
 Vector3D getZAxis(boolean normalise)
          Returns the z-axis.
 double getZRadius()
          Returns the z-axis radius.
 OneVariableDoubleVector3DFunction implicitFunction()
          Returns the implicit function of an ellipsoid; ie (x^2/rx^2)+(y^2/ry^2)+(z^2/rz^2)=1.
 Intersection3D intersection(Ray3D ray, double tolerance)
          Tests for an intersection between this ellipsoid and the specified ray.
 Intersection3D intersection(StraightLine3D line, double tolerance)
          Returns the intersection object between an ellipsoid and a straight line segment.
 boolean isOblateSpheroid(double tolerance)
          An ellipsoid is an oblate spheroid if two axes are of the same length and greater than the other axis.
 boolean isProlateSpheroid(double tolerance)
          An ellipsoid is an oblate spheroid if two axes are of the same length and less than the other axis.
 boolean isScaleneEllipsoid(double tolerance)
          Tests whether or not this ellipsoid is scalene; ie all three axis radii are unequal.
 boolean isSphere(double tolerance)
          Tests whether or not this ellipsoid is a sphere, within the specified tolerance.
 boolean isValid()
          Returns logical-true if a valid ellipsoid object, else logical-false.
 java.util.Vector<Vector3D> localAxes()
          Returns the set of local axes.
 double meanCurvature(double phiRadians, double thetaRadians)
          Returns the mean curvature at the specified point.
 Point3D nearestPoint(Point3D q, double tolerance)
          Returns the nearest point on this ellipsoid's surface to the specified point.
 boolean pointInside(Point3D p, double tolerance)
          Tests whether or not the specified point is inside this ellipsoid.
 Point3D pointOnEllipsoid(double phi_radians, double theta_radians, int local_or_global)
          Returns the point on an ellipsoid corresponding to the angles phi (-pi/2<=phi<=pi/2)and theta (-pi<=theta<=pi), (both in radians).
 boolean pointOnSurface(Point3D p, double tolerance)
          Tests whether or not the specified point on the surface of this ellipsoid.
 boolean pointOutside(Point3D p, double tolerance)
          Tests whether or not the specified point is inside this ellipsoid.
 java.util.Vector<Point3D> randomPointsInsideEllipsoid(int numberRandomPoints)
          Returns a vector of random points inside this ellipsoid.
 java.util.Vector<Point3D> randomPointsOnEllipsoid(int numberRandomPoints)
          Returns a vector of random points on the surface of this ellipsoid.
 Shape3D rotate(double theta, double beta, double gamma, Point3D fixedPoint, boolean degrees)
          Returns a rotated ellipsoid.
 Shape3D rotatedShapeInXYCoordinatePlane(double theta, Point3D fixedPoint, boolean degrees)
          Returns a rotated ellipsoid.
 Shape3D rotatedShapeInYZCoordinatePlane(double gamma, Point3D fixedPoint, boolean degrees)
          Returns a rotated ellipsoid.
 Shape3D rotatedShapeInZXCoordinatePlane(double beta, Point3D fixedPoint, boolean degrees)
          Returns a rotated ellipsoid.
 Shape3D scale(double s, Point3D fixedPoint)
          Scales this ellipsoid by the specified scaling factor.
 void setAxis(Vector3D axis, int axisIndex)
          Sets the specified local axis.
 void setCentre(Point3D centre)
          Sets the centre.
 void setRadius(double radius, int radiusIndex)
          Sets the radius for the specified axis.
 void setXAxis(Vector3D new_lx_axis)
          Sets the lx-axis to the specified axis.
 void setXRadius(double xRadius)
          Sets the radius in the x-direction.
 void setYAxis(Vector3D new_ly_axis)
          Sets the ly-axis to the specified axis.
 void setYRadius(double yRadius)
          Sets the radius in the y-direction.
 void setZAxis(Vector3D new_lz_axis)
          Sets the lz-axis to the specified axis.
 void setZRadius(double zRadius)
          Sets the radius in the z-direction.
 double surfaceArea(int method)
          Returns the surface area of an ellipsoid.
 QuadraticEquation3D toQuadraticEquation()
          Returns the implicit quadratic equation for this ellipsoid; ie Q=(Gz^2+Hxz+Iyz+Jz)+(Ax^2+Bxy+Cy^2+Dx+Ey+F)=0.
 QuadraticSurface3D toQuadraticSurface3D()
          Returns the quadratic surface equation equivalent of this ellipsoid; ie Q=(Gz^2+Hxz+Iyz+Jz)+(Ax^2+Bxy+Cy^2+Dx+Ey+F)=0.
 java.lang.String toString()
          Returns a String representation of an Ellipsoid3D object.
 X3DNode toX3DNode(X3DObject x3dObject)
          X3D support.
 org.w3c.dom.Element toXMLNode(org.w3c.dom.Document document, org.w3c.dom.Element documentRootNode)
          Returns the xml node of this object.
 Shape3D translate(double tx, double ty, double tz)
          Translates this ellipsoid.
 double volume()
          Returns the volume of an ellipsoid.
 HDouble xValue(HDouble phiRadians, HDouble thetaRadians)
          Returns the global x-coordinate of a point on this ellipsoid's surface specified by the (phi,theta) values.
 PlanarEllipse3D xyAxisEllipse()
          Returns the planar ellipse in the local x'y'-plane.
 PlanarEllipse3D xzAxisEllipse()
          Returns the planar ellipse in the local x'z'-plane.
 HDouble yValue(HDouble phiRadians, HDouble thetaRadians)
          Returns the global y-coordinate of a point on this ellipsoid's surface specified by the (phi,theta) values.
 PlanarEllipse3D yzAxisEllipse()
          Returns the planar ellipse in the local y'z'-plane.
 HDouble zValue(HDouble phiRadians, HDouble thetaRadians)
          Returns the global z-coordinate of a point on this ellipsoid's surface specified by the (phi,theta) values.
 
Methods inherited from class com.hedgehog.geo.threed.shapes.Shape3D
is2D, is3D, isCurve, isGrid, isMesh, isPoint, isPointSet, isShape, isSurface, pointInsideOrOnSurface
 
Methods inherited from class com.hedgehog.geo.GeometricObject
objectDimension
 
Methods inherited from class com.hedgehog.HObject
clone, compare, compareTo, copy, equals, getID, getName, hashCode, hasID, hasName, setID, setName
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

mCentre

protected Point3D mCentre
Ellipsoid centre.


mxRadius

protected double mxRadius
Radius in local x-axis direction.


myRadius

protected double myRadius
Radius in local y-axis direction.


mzRadius

protected double mzRadius
Radius in local z-axis direction.


mlxAxis

protected Vector3D mlxAxis
Local x-axis vector.


mlyAxis

protected Vector3D mlyAxis
Local y-axis vector.


mlzAxis

protected Vector3D mlzAxis
Local z-axis vector.

Constructor Detail

Ellipsoid3D

public Ellipsoid3D()
Default constructor. Sets the centre to (0,0,0), all three radii to 1 and the local axes to (1,0,0), (0,1,0) and (0,0,1).


Ellipsoid3D

public Ellipsoid3D(Point3D centre,
                   double xRadius,
                   double yRadius,
                   double zRadius)
            throws java.lang.IllegalArgumentException
Constructor.

Parameters:
centre - Ellipsoid centre.
xRadius - Radius in local x-direction.
yRadius - Radius in local y-direction.
zRadius - Radius in local z-directon.
Throws:
java.lang.IllegalArgumentException - Thrown if xRadius, yRadius or zRadius < 0.

Ellipsoid3D

public Ellipsoid3D(Point3D centre,
                   double xRadius,
                   double yRadius,
                   double zRadius,
                   Vector3D lxAxis,
                   Vector3D lyAxis,
                   Vector3D lzAxis)
            throws java.lang.IllegalArgumentException
Constructor.

Parameters:
centre - Ellipsoid centre.
xRadius - Radius in local x-direction.
yRadius - Radius in local y-direction.
zRadius - Radius in local z-directon.
lxAxis - Local x-axis.
lyAxis - Local y-axis.
lzAxis - Local z-axis.
Throws:
java.lang.IllegalArgumentException - Thrown if xRadius, yRadius or zRadius < 0.

Ellipsoid3D

public Ellipsoid3D(java.lang.String name)
Constructor. Same as default constructor in that it sets the centre to (0,0,0), all three radii to 0 and the local axes to (1,0,0), (0,1,0) and (0,0,1).

Parameters:
name - Object name.

Ellipsoid3D

public Ellipsoid3D(ID id)
Constructor. Same as default constructor in that it sets the centre to (0,0,0), all three radii to 0 and the local axes to (1,0,0), (0,1,0) and (0,0,1).

Parameters:
id - Object ID.

Ellipsoid3D

public Ellipsoid3D(java.lang.String name,
                   ID id)
Constructor. Same as default constructor in that it sets the centre to (0,0,0), all three radii to 0 and the local axes to (1,0,0), (0,1,0) and (0,0,1).

Parameters:
name - Object name.
id - Object ID.

Ellipsoid3D

public Ellipsoid3D(Ellipsoid3D object)
Copy constructor.

Parameters:
object - Object top copy.
Method Detail

getCentre

public Point3D getCentre()
Returns the centre.

Returns:
The centre.

getXRadius

public double getXRadius()
Returns the x-axis radius.

Returns:
Radius in x-axis.

getYRadius

public double getYRadius()
Returns the y-axis radius.

Returns:
Radius in y-axis.

getZRadius

public double getZRadius()
Returns the z-axis radius.

Returns:
Radius in z-axis.

getXAxis

public Vector3D getXAxis(boolean normalise)
Returns the x-axis.

Parameters:
normalise - Specifies whether or not the return x axis vector is normalised.
Returns:
The x-axis.

getYAxis

public Vector3D getYAxis(boolean normalise)
Returns the y-axis.

Parameters:
normalise - Specifies whether or not the return x axis vector is normalised.
Returns:
The y-axis.

getZAxis

public Vector3D getZAxis(boolean normalise)
Returns the z-axis.

Parameters:
normalise - Specifies whether or not the return x axis vector is normalised.
Returns:
The z-axis.

getRadius

public double getRadius(int radiusIndex)
                 throws java.lang.IllegalArgumentException
Returns the ellipsoid radius for the specified axis.

Parameters:
radiusIndex - Radius axis index: 0(xRadius), 1(yRadius) or 2(zRadius).
Returns:
Radius.
Throws:
java.lang.IllegalArgumentException - Thrown if radiusIndex is out of range [0:2].

getAxis

public Vector3D getAxis(int axisIndex,
                        boolean normalise)
                 throws java.lang.IllegalArgumentException
Returns the local axis.

Parameters:
axisIndex - Axis index: 0(lx), 1(ly) or 2(lz).
normalise - Specifies whether or not the returned axis is normalised.
Returns:
Axis.
Throws:
java.lang.IllegalArgumentException - Thrown if axisIndex is out of range [0:2].

setCentre

public void setCentre(Point3D centre)
Sets the centre.

Parameters:
centre - New centre point.

setXRadius

public void setXRadius(double xRadius)
                throws java.lang.IllegalArgumentException
Sets the radius in the x-direction.

Parameters:
xRadius - New radius in the x-direction.
Throws:
java.lang.IllegalArgumentException - Thrown if xRadius<0.

setYRadius

public void setYRadius(double yRadius)
                throws java.lang.IllegalArgumentException
Sets the radius in the y-direction.

Parameters:
yRadius - New radius in the y-direction.
Throws:
java.lang.IllegalArgumentException - Thrown if yRadius<0.

setZRadius

public void setZRadius(double zRadius)
                throws java.lang.IllegalArgumentException
Sets the radius in the z-direction.

Parameters:
zRadius - New radius in the z-direction.
Throws:
java.lang.IllegalArgumentException - Thrown if zRadius<0.

setRadius

public void setRadius(double radius,
                      int radiusIndex)
               throws java.lang.IllegalArgumentException
Sets the radius for the specified axis.

Parameters:
radius - New radius value.
radiusIndex - Radius index: 0(xRadius), 1(yRadius) or 2(zRadius).
Throws:
java.lang.IllegalArgumentException - Thrown if radiusIndex out of range [0:2].

setXAxis

public void setXAxis(Vector3D new_lx_axis)
Sets the lx-axis to the specified axis.

Parameters:
new_lx_axis - New lx-axis.

setYAxis

public void setYAxis(Vector3D new_ly_axis)
Sets the ly-axis to the specified axis.

Parameters:
new_ly_axis - New ly-axis.

setZAxis

public void setZAxis(Vector3D new_lz_axis)
Sets the lz-axis to the specified axis.

Parameters:
new_lz_axis - New lz-axis.

setAxis

public void setAxis(Vector3D axis,
                    int axisIndex)
             throws java.lang.IllegalArgumentException
Sets the specified local axis.

Parameters:
axis - New axis.
axisIndex - Axis index: 0(lx), 1(ly) or 2(lz).
Throws:
java.lang.IllegalArgumentException - Thrown if axisIndex is out of range [0:2].

isSphere

public boolean isSphere(double tolerance)
Tests whether or not this ellipsoid is a sphere, within the specified tolerance.

Parameters:
tolerance - Tolerance used to test the radii.
Returns:
Logical-true if this ellipsoid is a sphere, else logical-false.

isOblateSpheroid

public boolean isOblateSpheroid(double tolerance)
An ellipsoid is an oblate spheroid if two axes are of the same length and greater than the other axis. Since the ellipsoid can be arbitrarily oriented all permutations need to be tested; ie a==b>c, a==c>b and b==c>a.

Parameters:
tolerance - Required tolerance.
Returns:
Logical-true if this ellipsoid is an oblate spheroid, else logical-false.

isProlateSpheroid

public boolean isProlateSpheroid(double tolerance)
An ellipsoid is an oblate spheroid if two axes are of the same length and less than the other axis. Since the ellipsoid can be arbitrarily oriented all permutations need to be tested; ie a==b
Parameters:
tolerance - Required tolerance.
Returns:
Logical-true if this ellipsoid is an oblate spheroid, else logical-false.

isScaleneEllipsoid

public boolean isScaleneEllipsoid(double tolerance)
Tests whether or not this ellipsoid is scalene; ie all three axis radii are unequal.

Parameters:
tolerance - Required tolerance.
Returns:
Returns logical-true if this ellipsoid is scalene, else logical-false.

xValue

public HDouble xValue(HDouble phiRadians,
                      HDouble thetaRadians)
               throws java.lang.IllegalArgumentException
Returns the global x-coordinate of a point on this ellipsoid's surface specified by the (phi,theta) values.

Parameters:
phiRadians - phi value of point on surface.
thetaRadians - theta value of point on surface.
Returns:
z-coordinate of point (phi,theta).
Throws:
java.lang.IllegalArgumentException - Thrown if phiRadians or thetaRadians are out of range.

yValue

public HDouble yValue(HDouble phiRadians,
                      HDouble thetaRadians)
               throws java.lang.IllegalArgumentException
Returns the global y-coordinate of a point on this ellipsoid's surface specified by the (phi,theta) values.

Parameters:
phiRadians - phi value of point on surface.
thetaRadians - theta value of point on surface.
Returns:
z-coordinate of point (phi,theta).
Throws:
java.lang.IllegalArgumentException - Thrown if phiRadians or thetaRadians are out of range.

zValue

public HDouble zValue(HDouble phiRadians,
                      HDouble thetaRadians)
               throws java.lang.IllegalArgumentException
Returns the global z-coordinate of a point on this ellipsoid's surface specified by the (phi,theta) values.

Parameters:
phiRadians - phi value of point on surface.
thetaRadians - theta value of point on surface.
Returns:
z-coordinate of point (phi,theta).
Throws:
java.lang.IllegalArgumentException - Thrown if phiRadians or thetaRadians are out of range.

surfaceArea

public double surfaceArea(int method)
                   throws java.lang.IllegalArgumentException
Returns the surface area of an ellipsoid. For example; an ellipse having (10,5,5) radii has area using method 0 of 536.9608831970901 and 536.4907061451287 (0.08% accurate) using method 1.

Parameters:
method - Method used to evaluate the area: 0(exact via numerical integration of elliptic integrals of 2nd kind), 1(Knud Thomson's formula).
Returns:
Surface area of this ellipsoid.
Throws:
java.lang.IllegalArgumentException - Thrown if method is invalid.

localAxes

public java.util.Vector<Vector3D> localAxes()
Returns the set of local axes.

Returns:
Vector of local axes [lx,ly,lz].

isValid

public boolean isValid()
Returns logical-true if a valid ellipsoid object, else logical-false. Confirms that a valid centre has been defined and that positive radii have been set.

Returns:
Logical-true if this object is valid, else logcal-false.

pointOnEllipsoid

public Point3D pointOnEllipsoid(double phi_radians,
                                double theta_radians,
                                int local_or_global)
                         throws java.lang.IllegalArgumentException
Returns the point on an ellipsoid corresponding to the angles phi (-pi/2<=phi<=pi/2)and theta (-pi<=theta<=pi), (both in radians).

Parameters:
phi_radians - Angle phi in radians.
theta_radians - Angle theta in radians.
local_or_global - Specified whether the returned point is with respect the ellipsoid's local axes, or global axes.
Returns:
Returns the point on this ellipsoid corresponding to the specified (phi,theta) parametric coordinates.
Throws:
java.lang.IllegalArgumentException - Thrown if either phi or theta are out of range.

gaussCurvature

public double gaussCurvature(Point3D p)
                      throws java.lang.IllegalArgumentException
Returns the Gauss curvature at the specified point. For further details refer to MathWorld.

Parameters:
p - Point at which to determine the curvature.
Returns:
The Gauss curvature.
Throws:
java.lang.IllegalArgumentException - Thrown if the specified point does not lie on the surface of this ellipsoid.

meanCurvature

public double meanCurvature(double phiRadians,
                            double thetaRadians)
                     throws java.lang.IllegalArgumentException
Returns the mean curvature at the specified point. For further details refer to MathWorld.

Parameters:
phiRadians - Phi. Must be in range [-PI/2:PI/2].
thetaRadians - Theta. Must be in range [-PI:PI].
Returns:
Mean curvature at (phi,theta).
Throws:
java.lang.IllegalArgumentException - Thrown if the specified (phi,theta) point does not lie on the surface of this ellipsoid.

axisPointOnPositiveLocalXAxis

public Point3D axisPointOnPositiveLocalXAxis()
Returns the point of intersection between the positive local x-axis and the ellipsoid surface.

Returns:
Point of intersection between the positive local x-axis and the ellipsoid.

axisPointOnNegativeLocalXAxis

public Point3D axisPointOnNegativeLocalXAxis()
Returns the point of intersection between the negative local x-axis and the ellipsoid surface.

Returns:
Point of intersection between the negative locla x-axis and the ellipsoid surface.

axisPointOnPositiveLocalYAxis

public Point3D axisPointOnPositiveLocalYAxis()
Returns the point of intersection between the positive local x-axis and the ellipsoid surface.

Returns:
Point of intersection between the positive local x-axis and the ellipsoid.

axisPointOnNegativeLocalYAxis

public Point3D axisPointOnNegativeLocalYAxis()
Returns the point of intersection between the negative local y-axis and the ellipsoid surface.

Returns:
Point of intersection between the negative locla y-axis and the ellipsoid surface.

axisPointOnPositiveLocalZAxis

public Point3D axisPointOnPositiveLocalZAxis()
Returns the point of intersection between the positive local z-axis and the ellipsoid surface.

Returns:
Point of intersection between the positive local z-axis and the ellipsoid.

axisPointOnNegativeLocalZAxis

public Point3D axisPointOnNegativeLocalZAxis()
Returns the point of intersection between the negative local z-axis and the ellipsoid surface.

Returns:
Point of intersection between the negative locla z-axis and the ellipsoid surface.

nearestPoint

public Point3D nearestPoint(Point3D q,
                            double tolerance)
Returns the nearest point on this ellipsoid's surface to the specified point. Note that if q is at the ellipsoid centre then the nearest axis terminating point is returned. Optimisation is required to find the nearest point to an ellipsoid surface. This method uses TwoVariableBisectionOptimiser with min/max function EllipsoidNearestPointOpt.evaluate() to perform the optimisation.

Parameters:
q - Point to find nearest point.
tolerance - Required tolerance.
Returns:
Nearest ellipsoid point to the specified point. Returns null if unable to determine the nearest point.

furthestPoint

public Point3D furthestPoint(Point3D q,
                             double tolerance)
Returns the furthest point on this ellipsoid's surfacae from the specified point. Note that if q is at the ellipsoid centre then the furthest positive axis point is returned.

Parameters:
q - Point to find furthest point.
tolerance - Required tolerance.
Returns:
Furthest ellipsoid point to the specified point. Returns null if unable to determine the furthest point.

area

public double area()
Returns the surface area of this ellipsoid. Calls surfaceArea() using numerical integration.

Specified by:
area in class Shape3D
Returns:
Surface area of this ellipsoid.

boundingBox

public AxisAlignedBox3D boundingBox()
Returns the bounding box of this ellipsoid. The returned bounding box is a loose fit in that its dimensions are (2rx,2ry,2rz). A tighter fit bounding box could be generated but would take a disproportionate amount of computation to compute.

Specified by:
boundingBox in class Shape3D
Returns:
Bounding box of this ellipsoid.

centroid

public Point3D centroid()
Returns the centroid of this ellipsoid; ie the centre.

Specified by:
centroid in class Shape3D
Returns:
Ellipsoid centre.

rotate

public Shape3D rotate(double theta,
                      double beta,
                      double gamma,
                      Point3D fixedPoint,
                      boolean degrees)
               throws java.lang.IllegalArgumentException
Returns a rotated ellipsoid.

Specified by:
rotate in class Shape3D
Parameters:
theta - Rotation angle about x-axis.
beta - Rotation angle about y-axis.
gamma - Rotation angle about z-axis.
fixedPoint - Fixed point about which object is rotated; default is null meaning ellipsoid centre.
degrees - Specifies whether (theta,beta,gamma) are in degrees or radians.
Returns:
Rotated ellipsoid. A null value is returned if an internal error occurred, probably as a result of non-orthogonal axes.
Throws:
java.lang.IllegalArgumentException - Thrown if theta, beta or gamma are out of range [0:2pi].

rotatedShapeInXYCoordinatePlane

public Shape3D rotatedShapeInXYCoordinatePlane(double theta,
                                               Point3D fixedPoint,
                                               boolean degrees)
                                        throws java.lang.IllegalArgumentException
Returns a rotated ellipsoid.

Parameters:
theta - Rotation angle about z-axis.
fixedPoint - Fixed point about which object is rotated; default is null meaning ellipsoid centre.
degrees - Specifies whether (theta,beta,gamma) are in degrees or radians.
Returns:
Rotated ellipsoid. A null value is returned if an internal error occurred, probably as a result of non-orthogonal axes.
Throws:
java.lang.IllegalArgumentException - Thrown if theta, beta or gamma are out of range [0:2pi] radians.

rotatedShapeInYZCoordinatePlane

public Shape3D rotatedShapeInYZCoordinatePlane(double gamma,
                                               Point3D fixedPoint,
                                               boolean degrees)
                                        throws java.lang.IllegalArgumentException
Returns a rotated ellipsoid.

Parameters:
gamma - Rotation angle about x-axis.
fixedPoint - Fixed point about which object is rotated; default is null meaning ellipsoid centre.
degrees - Specifies whether (theta,beta,gamma) are in degrees or radians.
Returns:
Rotated ellipsoid. A null value is returned if an internal error occurred, probably as a result of non-orthogonal axes.
Throws:
java.lang.IllegalArgumentException - Thrown if theta, beta or gamma are out of range [0:2pi].

rotatedShapeInZXCoordinatePlane

public Shape3D rotatedShapeInZXCoordinatePlane(double beta,
                                               Point3D fixedPoint,
                                               boolean degrees)
                                        throws java.lang.IllegalArgumentException
Returns a rotated ellipsoid.

Parameters:
beta - Rotation angle about y-axis.
fixedPoint - Fixed point about which object is rotated; default is null meaning ellipsoid centre.
degrees - Specifies whether (theta,beta,gamma) are in degrees or radians.
Returns:
Rotated ellipsoid. A null value is returned if an internal error occurred, probably as a result of non-orthogonal axes.
Throws:
java.lang.IllegalArgumentException - Thrown if theta, beta or gamma are out of range [0:2pi].

scale

public Shape3D scale(double s,
                     Point3D fixedPoint)
Scales this ellipsoid by the specified scaling factor. Scales the ellipsoid radii.

Specified by:
scale in class Shape3D
Parameters:
s - Scaling factor.
fixedPoint - Fixed point. Not used for scaling an ellipsoid.
Returns:
Scaled ellipsoid.

translate

public Shape3D translate(double tx,
                         double ty,
                         double tz)
Translates this ellipsoid.

Specified by:
translate in class Shape3D
Parameters:
tx - Translation in x-direction.
ty - Translation in y-direction.
tz - Translation in z-direction.
Returns:
Translated ellipsoid.

volume

public double volume()
Returns the volume of an ellipsoid. Note: when rx=ry=rz and the ellipsoid becomes a sphere the volume is equal to (4/3)pir^3.

Specified by:
volume in class Shape3D
Returns:
Volume of an ellipsoid.

toQuadraticSurface3D

public QuadraticSurface3D toQuadraticSurface3D()
Returns the quadratic surface equation equivalent of this ellipsoid; ie Q=(Gz^2+Hxz+Iyz+Jz)+(Ax^2+Bxy+Cy^2+Dx+Ey+F)=0.

Returns:
This ellipsoid expressed as a QuadraticSurface3D object.

toQuadraticEquation

public QuadraticEquation3D toQuadraticEquation()
Returns the implicit quadratic equation for this ellipsoid; ie Q=(Gz^2+Hxz+Iyz+Jz)+(Ax^2+Bxy+Cy^2+Dx+Ey+F)=0. Thus, this method effectively converts the implicit form (x-cx)^2/rx^2 + (y-cy)^2/ry^2 + (z-cz)^2/rz^2 - 1 = 0 to a QuadraticEquation3D object.

Returns:
Quadratic equation of this ellipsoid.

toString

public java.lang.String toString()
Returns a String representation of an Ellipsoid3D object.

Overrides:
toString in class java.lang.Object
Returns:
A String representation of an Ellipsoid3D object.

getM

public Matrix3x3 getM()
Compute M = sum_{i=0}^2 U[i]*U[i]^T/e[i]^2.

Returns:
Matrix M. Returns a null value if an internal error occurred computing M.

intersection

public Intersection3D intersection(Ray3D ray,
                                   double tolerance)
Tests for an intersection between this ellipsoid and the specified ray.

Parameters:
ray - Ray.
tolerance - equired tolerance.
Returns:
Intersection object. Equal to NONE if no intersection points, POINT if 1 Point3D tangential intersection point and POINTS if 2 Point3D intersection points.

intersection

public Intersection3D intersection(StraightLine3D line,
                                   double tolerance)
Returns the intersection object between an ellipsoid and a straight line segment.

Parameters:
line - The straight line to test for intersection with this sphere.
tolerance - Required tolerance.
Returns:
Intersection object. The object can consist of no intersection points (NONE), 1 Point3D intersection point (POINT) or 2 Point3D intersection points (POINTS).

evaluate

public double evaluate(Point3D p)
                throws InvalidObjectException
Evaluates the quadratic Q(X) = (X-K)^T * M * (X-K) - 1 for the specified point.

Parameters:
p - Point to evaluate.
Returns:
Evaluation of ellipsoid quadratic.
Throws:
InvalidObjectException - Thrown If either of the axes radii are zero (within Tolerances.ZERO).

ellipsoidImplicitFunction

public HDouble ellipsoidImplicitFunction(Vector3D v)
Method for OneVariableVector3DFunction implicit function.

Parameters:
v - Vector at which implicit function is to be evaluated.
Returns:
Function value at v.

implicitFunction

public OneVariableDoubleVector3DFunction implicitFunction()
Returns the implicit function of an ellipsoid; ie (x^2/rx^2)+(y^2/ry^2)+(z^2/rz^2)=1.

Returns:
Ellipsoid implicit function. A null value is returned if there is a problem generating the function object.

randomPointsInsideEllipsoid

public java.util.Vector<Point3D> randomPointsInsideEllipsoid(int numberRandomPoints)
                                                      throws java.lang.IllegalArgumentException
Returns a vector of random points inside this ellipsoid.

Parameters:
numberRandomPoints - Number of random points.
Returns:
Vector of random points inside this ellipsoid.
Throws:
java.lang.IllegalArgumentException - Thrown if numberRandomPoints < 0.

randomPointsOnEllipsoid

public java.util.Vector<Point3D> randomPointsOnEllipsoid(int numberRandomPoints)
                                                  throws java.lang.IllegalArgumentException
Returns a vector of random points on the surface of this ellipsoid.

Parameters:
numberRandomPoints - Number of random points.
Returns:
Vector of random points on the surface of this ellipsoid.
Throws:
java.lang.IllegalArgumentException - Thrown if numberRandomPoints < 0.

xyAxisEllipse

public PlanarEllipse3D xyAxisEllipse()
Returns the planar ellipse in the local x'y'-plane.

Returns:
Ellipse in the local x'y'-plane.

yzAxisEllipse

public PlanarEllipse3D yzAxisEllipse()
Returns the planar ellipse in the local y'z'-plane.

Returns:
Ellipse in the local y'z'-plane.

xzAxisEllipse

public PlanarEllipse3D xzAxisEllipse()
Returns the planar ellipse in the local x'z'-plane.

Returns:
Ellipse in the local x'z'-plane.

pointInside

public boolean pointInside(Point3D p,
                           double tolerance)
Tests whether or not the specified point is inside this ellipsoid.

Specified by:
pointInside in class Shape3D
Parameters:
p - Point to test.
tolerance - Required tolerance.
Returns:
Logical-true if p is inside this ellipsoid, else logical-false.

pointOutside

public boolean pointOutside(Point3D p,
                            double tolerance)
Tests whether or not the specified point is inside this ellipsoid.

Overrides:
pointOutside in class Shape3D
Parameters:
p - Point to test.
tolerance - Required tolerance.
Returns:
Logical-true if p is outside this ellipsoid, else logical-false.

pointOnSurface

public boolean pointOnSurface(Point3D p,
                              double tolerance)
Tests whether or not the specified point on the surface of this ellipsoid.

Specified by:
pointOnSurface in class Shape3D
Parameters:
p - Point to test.
tolerance - Required tolerance.
Returns:
Logical-true if p is on the surface of this ellipsoid, else logical-false.

childModelObjects

public java.util.Vector<ModelObject> childModelObjects()
Returns a vector of this object's child ModelObject objects.

Specified by:
childModelObjects in interface ModelObject
Returns:
A vector with the 4 elements of the centre and 3 axis vectors.

databaseInsertStatement

public java.sql.PreparedStatement databaseInsertStatement(java.sql.Connection connection,
                                                          int modelID)
                                                   throws java.sql.SQLException
Returns a prepared statement for inserting (INSERT command) a ModelObject object into a database.

Specified by:
databaseInsertStatement in interface ModelObject
Parameters:
connection - Database connection.
modelID - Model ID.
Returns:
A prepared statement for inserting a ModelObject object into a database.
Throws:
java.sql.SQLException - Thrown if an SQL exception occurs.

databaseUpdateStatement

public java.sql.PreparedStatement databaseUpdateStatement(java.sql.Connection connection,
                                                          int modelID)
                                                   throws java.sql.SQLException
Returns a prepared statement for updating (UPDATE command) a ModelObject object into a database.

Specified by:
databaseUpdateStatement in interface ModelObject
Parameters:
connection - Database connection.
modelID - Model ID.
Returns:
A prepared statement for inserting a ModelObject object into a database.
Throws:
java.sql.SQLException - Thrown if an SQL exception occurs.

toXMLNode

public org.w3c.dom.Element toXMLNode(org.w3c.dom.Document document,
                                     org.w3c.dom.Element documentRootNode)
                              throws InvalidObjectException
Returns the xml node of this object.

Specified by:
toXMLNode in interface ModelObject
Parameters:
document - XML document.
documentRootNode - Document root node.
Returns:
The xml node of this object.
Throws:
InvalidObjectException - Thrown if this object's ID is equal to the default ID of -1.

fromXMLNode

public ModelObject fromXMLNode(org.w3c.dom.Document document,
                               org.w3c.dom.Node documentRootNode,
                               org.w3c.dom.Node node,
                               Model model)
                        throws InvalidObjectException
Returns a model object from the specified xml node.

Specified by:
fromXMLNode in interface ModelObject
Parameters:
document - XML document.
documentRootNode - Document root node; ie Model node.
node - XML node.
model - The model to which the returned object is associated.
Returns:
ModelObject corresponding to the specified node. A null value is returned if an error occurred building the object.
Throws:
InvalidObjectException - Thrown if an error occurred building the object.

fromDatabase

public ModelObject fromDatabase(java.sql.Connection connection,
                                Model model,
                                int modelID,
                                int objectID)
                         throws java.sql.SQLException
Returns a model object from the specified database table.

Specified by:
fromDatabase in interface ModelObject
Parameters:
connection - Database connection.
modelID - Model ID.
objectID - Object ID in associated ModelObjects table.
model - Model built from database.
Returns:
ModelObject corresponding to the specified db connection, model ID and obect ID. A null value is returned if no match found.
Throws:
java.sql.SQLException - Thrown if an SQL exception occurs.

toX3DNode

public X3DNode toX3DNode(X3DObject x3dObject)
                  throws InvalidObjectException
X3D support. Represents as a node with scaling for for the y and z axes.

Specified by:
toX3DNode in interface ModelObject
Parameters:
x3dObject - X3D object.
Returns:
X3D object or null if object has no visualisation.
Throws:
InvalidObjectException - Thrown if this object is invalid.