com.hedgehog.geo.twod.curves
Class Ray2D

java.lang.Object
  extended by com.hedgehog.HObject
      extended by com.hedgehog.geo.GeometricObject
          extended by com.hedgehog.geo.twod.GeometricObject2D
              extended by com.hedgehog.geo.twod.curves.Curve2D
                  extended by com.hedgehog.geo.twod.curves.Ray2D
All Implemented Interfaces:
ModelObject, java.lang.Comparable, java.util.Comparator

public class Ray2D
extends Curve2D
implements ModelObject

Title: Ray2D - represents a 2D ray.

Description: Represents a 2D ray. The ray is represented as P+t*D, where P is the ray origin, D is a unit-length direction vector, and t >= 0. The user must ensure that the direction vector satisfies this condition.

Although Ray2D encapsulates its own origin point, it does make use of Curve2D's end-points mp0 and mp1.

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

Company: Hedgehog Software

Since:
1.0
Version:
1.1

Field Summary
protected  Vector2D mDirection
          Ray direction.
protected  Point2D mOrigin
          Ray origin.
 
Fields inherited from class com.hedgehog.geo.twod.curves.Curve2D
mp0, mp1
 
Fields inherited from class com.hedgehog.HObject
mID, mName
 
Constructor Summary
Ray2D()
          Default constructor.
Ray2D(ID id)
          Constructor.
Ray2D(Point2D origin, Point2D otherPoint)
          Constructor.
Ray2D(Point2D origin, Vector2D direction)
          Constructor.
Ray2D(Point2D origin, Vector2D direction, java.lang.String name, ID id)
          Constructor.
Ray2D(Ray2D object)
          Copy constructor.
Ray2D(java.lang.String name)
          Constructor.
Ray2D(java.lang.String name, ID id)
          Constructor.
 
Method Summary
 java.util.Vector<ModelObject> childModelObjects()
          Returns a vector of this object's child ModelObject objects.
 Ray2D copy()
          Returns a copy of this Ray2D object.
 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.
 double distanceTo(Point2D p)
          Returns the distance from the specified point to this ray; ie sqrt(distanceToSquared(p)).
 double distanceTo(Ray2D ray1, double tolerance, Point2D ray0ClosestPoint, Point2D ray1ClosestPoint)
          Returns the minimum distance between this ray (ray0) and the specified ray (ray1).
 double distanceToSquared(Point2D p)
          Returns the distance squared from the specified point to this ray.
 double distanceToSquared(Ray2D ray1, double tolerance, Point2D ray0ClosestPoint, Point2D ray1ClosestPoint)
          Returns the minimum distance squared between this ray (ray0) and the specified ray (ray1).
 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.
 Vector2D getDirection()
          Returns the direction.
 Point2D getOrigin()
          Returns the origin.
 Point2D getP0()
          Returns end-point p0; which is set to mOrigin.
 Point2D getP1()
          Returns end-point p1; which is set to null to indicte that this ray does not have an end-point p1.
 Point2D intermediatePoint(double c1, double c2)
          Returns null since method is undefined for a ray of infinite length.
 void intermediatePointLengthCoordinates(Point2D p, double tolerance, HDouble c1, HDouble c2)
          Returns, via reference, the distances c1 and c2 from origin to p and p to end-of ray.
 Point2D intersection(Ray2D ray, double tolerance)
          Returns the point of intersection between two rays, if any.
 boolean isHorizontal(double tolerance)
          Tests whether or not this ray is horizontal.
 boolean isSelfIntersecting()
          Returns false since a ray cannot self-intersect.
 boolean isValid()
          Tests the validity of this ray.
 boolean isVertical(double tolerance)
          Tests whether or not this ray is vertical.
 double length()
          Length of a ray is infinite, so hedgehog.utility.Tolerances.POSITIVE_INFINITE returned.
 void lengthCoordinates(Point2D p, HDouble zeta1, HDouble zeta2)
          Sets both zeta1 and zeta2 to 0 since length coordinates are undefined because the ray length is infinite.
 Point2D midPoint()
          Returns null since the mid-point of a ray is undefined.
 double minimumDistance(Point2D p, double tolerance)
          Returns the minimum distance from the specified point to this ray.
 void normaliseDirectionVector()
          Normalises the direction vector of this ray.
 double parametricVariable(Point2D p, double tolerance)
          Returns the value of the parametric variable, t, corresponding to the specified point.
 boolean pointOfCurve(Point2D p, double tolerance)
          Tests if the specified point is a point of this ray; ie if p is identical to the ray origin.
 Point2D pointOnCurve(double u, double tolerance)
          Returns a point on the ray given the parametric variable.
 boolean pointOnCurve(Point2D p, double tolerance)
          Tests whether or not the specified point is on this ray.
 boolean pointOnLeft(Point2D p, double tolerance)
          Tests whether or not the specified point is on the left of this ray.
 boolean pointOnRight(Point2D p, double tolerance)
          Tests whether or not the specified point is on the right of this ray.
 java.util.ArrayList<Point2D> pointsOnRay(Point2D startPoint, Point2D endPoint, double distanceBetweenPoints)
          Returns a vector of points between the specified start and end points on this ray.
static Ray2D rayThroughPointSet(Point2DSet pset)
           Returns a Ray2D object that passes through the specified point set.
 void reverse()
          Reverses the direction vector of this ray.
 Curve2D scale(double sx, double sy, Point2D fixedPoint)
          Scales this ray by the specified scaling factors in the x and y directions.
 Vector2D secondDerivative(double u)
          Returns the second derivative at u.
 void setDirection(Vector2D direction)
          Sets the direction.
 void setOrigin(Point2D origin)
          Sets the origin.
 Vector2D tangent()
          Returns the tangent vector; ie the direction vector.
 Vector2D tangent(double u)
          Returns the tangent vector; ie the ray direction vector.
 Vector2D tangent(Point2D p)
          Returns the tangent vector; ie the ray direction vector.
 LinearLine2D toLinearLine2D()
          Returns a LinearLine2D equivalent of this ray.
 double torsion(double u)
          Returns the torsion at u.
 java.lang.String toString()
          Returns a String representation of a Ray2D 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.
 Curve2D translate(double tx, double ty)
          Translates this ray by the specified (tx,ty) translation vector.
 
Methods inherited from class com.hedgehog.geo.twod.curves.Curve2D
commonEndPoint, curvature, curvePoints, distanceBetweenTwoPointsAlongCurve, distanceBetweenTwoPointsAlongCurve, equals, evenlySpacedIntermediatePoints, interpolation, is2D, is3D, isCurve, isEndPoint, isEndPointP0, isEndPointP1, isGrid, isMesh, isOpen, isP0Set, isP1Set, isPoint, isPointSet, isShape, isSurface, jacobianDeterminant, length, lengthCoordinates, lengthFunction, maximumX, maximumY, minimumX, minimumY, nearestEndPoint, nearestEndPoint, nearestPoint, nearestPointApprox, otherEndPoint, pointXOnCurve, pointYOnCurve, randomPoint, sameCurve, sameEndPoints, setP0, setP1, shapeFunctions, shapeFunctions, shapeFunctionsDerivatives, shareEndPoint, toPolyStraightLine2D, trihedron, unitBiNormalVector, unitPrincipalNormalVector
 
Methods inherited from class com.hedgehog.geo.GeometricObject
objectDimension
 
Methods inherited from class com.hedgehog.HObject
clone, compare, compareTo, getID, getName, hashCode, hasID, hasName, setID, setName
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

mOrigin

protected Point2D mOrigin
Ray origin.


mDirection

protected Vector2D mDirection
Ray direction.

Constructor Detail

Ray2D

public Ray2D()
Default constructor. Initialises the origin to (0,0) and the direction vector to (1,0).


Ray2D

public Ray2D(Point2D origin,
             Vector2D direction)
Constructor.

Parameters:
origin - Ray origin.
direction - Ray direction.
Throws:
java.lang.IllegalArgumentException - Thrown if origin or direction are null or if direction is not of unit length.

Ray2D

public Ray2D(Point2D origin,
             Vector2D direction,
             java.lang.String name,
             ID id)
Constructor.

Parameters:
origin - Ray origin.
direction - Ray direction.
name - Object name.
id - Object ID.
Throws:
java.lang.IllegalArgumentException - Thrown if origin or direction are null or if direction is not of unit length.

Ray2D

public Ray2D(Point2D origin,
             Point2D otherPoint)
      throws java.lang.IllegalArgumentException
Constructor. Build a ray from origin to otherPoint.

Parameters:
origin - Ray origin.
otherPoint - Other point.
Throws:
java.lang.IllegalArgumentException - Thrown if origin to otherPoint are the same point within hedgehog.utility.Tolerances.TOLERANCE.

Ray2D

public Ray2D(java.lang.String name)
Constructor. Initialises the origin to (0,0) and the direction vector to (1,0).

Parameters:
name - Object name.

Ray2D

public Ray2D(ID id)
Constructor. Initialises the origin to (0,0) and the direction vector to (1,0).

Parameters:
id - Object ID.

Ray2D

public Ray2D(java.lang.String name,
             ID id)
Constructor. Initialises the origin to (0,0) and the direction vector to (1,0).

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

Ray2D

public Ray2D(Ray2D object)
Copy constructor.

Parameters:
object - Object to copy.
Method Detail

getOrigin

public Point2D getOrigin()
Returns the origin.

Returns:
The ray origin.

getDirection

public Vector2D getDirection()
Returns the direction.

Returns:
The ray direction.

setOrigin

public void setOrigin(Point2D origin)
Sets the origin.

Parameters:
origin - New origin.

setDirection

public void setDirection(Vector2D direction)
                  throws java.lang.IllegalArgumentException
Sets the direction.

Parameters:
direction - New direction vector.
Throws:
java.lang.IllegalArgumentException - Thrown if the specified direction vector is null or not of unit length.

getP0

public Point2D getP0()
Returns end-point p0; which is set to mOrigin.

Overrides:
getP0 in class Curve2D
Returns:
Returns end-point p0; ie the ray origin.

getP1

public Point2D getP1()
Returns end-point p1; which is set to null to indicte that this ray does not have an end-point p1.

Overrides:
getP1 in class Curve2D
Returns:
Returns null.

pointOnCurve

public Point2D pointOnCurve(double u,
                            double tolerance)
                     throws java.lang.IllegalArgumentException
Returns a point on the ray given the parametric variable. Note: An IllegalArgumentException exception is thrown if u<0. If a -ve u value is required then flip the direction of the ray using reverse().

Specified by:
pointOnCurve in class Curve2D
Parameters:
u - Parametric distance along ray from ray origin.
tolerance - Required tolerance used to test if the value of u is approximately 0 and hence at the ray origin.
Returns:
Point on ray at specified u value.
Throws:
java.lang.IllegalArgumentException - Thrown if u<0.

pointOnCurve

public boolean pointOnCurve(Point2D p,
                            double tolerance)
Tests whether or not the specified point is on this ray. A point on the negative side (-ve parametric variable value) of this ray is not considered to be on the ray.

Specified by:
pointOnCurve in class Curve2D
Parameters:
p - Point to test.
tolerance - Required tolerance.
Returns:
Logical-true if p is on this ray, else logical-false.

pointOnLeft

public boolean pointOnLeft(Point2D p,
                           double tolerance)
Tests whether or not the specified point is on the left of this ray.

Specified by:
pointOnLeft in class Curve2D
Parameters:
p - Point to test.
tolerance - Required tolerance.
Returns:
Logical-true if p is on the left of this ray, else logical-false.

pointOnRight

public boolean pointOnRight(Point2D p,
                            double tolerance)
Tests whether or not the specified point is on the right of this ray.

Specified by:
pointOnRight in class Curve2D
Parameters:
p - Point to test.
tolerance - Required tolerance.
Returns:
Logical-true if p is on the right of this ray, else logical-false.

length

public double length()
Length of a ray is infinite, so hedgehog.utility.Tolerances.POSITIVE_INFINITE returned.

Overrides:
length in class Curve2D
Returns:
Length of this ray, which is Tolerances.POSITIVE_INFINITE.

isValid

public boolean isValid()
Tests the validity of this ray.

Overrides:
isValid in class Curve2D
Returns:
Logical-true if valid, else logical-false if null origin and/or ZERO direction vector.

isHorizontal

public boolean isHorizontal(double tolerance)
Tests whether or not this ray is horizontal. Tests that the y-component of it's direction vector is zero within the specified tolerance.

Parameters:
tolerance - Required tolerance.
Returns:
Logical-true if this ray is horizontal, else logical-false.

isVertical

public boolean isVertical(double tolerance)
Tests whether or not this ray is vertical. Tests that the x-component of it's direction vector is zero within the specified tolerance.

Parameters:
tolerance - Required tolerance.
Returns:
Logical-true if this ray is vertical, else logical-false.

copy

public Ray2D copy()
Returns a copy of this Ray2D object.

Overrides:
copy in class HObject
Returns:
Copy of this ray.

reverse

public void reverse()
Reverses the direction vector of this ray.

Overrides:
reverse in class Curve2D

midPoint

public Point2D midPoint()
Returns null since the mid-point of a ray is undefined.

Overrides:
midPoint in class Curve2D
Returns:
A null value is returned.

isSelfIntersecting

public boolean isSelfIntersecting()
Returns false since a ray cannot self-intersect.

Returns:
Logical-false since a ray cannot self-intersect.

lengthCoordinates

public void lengthCoordinates(Point2D p,
                              HDouble zeta1,
                              HDouble zeta2)
Sets both zeta1 and zeta2 to 0 since length coordinates are undefined because the ray length is infinite.

Parameters:
p - Point at which to find length coordinates.
zeta1 - Set upon return to length coordinate 1.
zeta2 - Set upon return to length coordinate 2.

minimumDistance

public double minimumDistance(Point2D p,
                              double tolerance)
Returns the minimum distance from the specified point to this ray.

Overrides:
minimumDistance in class Curve2D
Parameters:
p - Point from which to find minimum distance.
tolerance - Required tolerance.
Returns:
Minimum distance from p to this ray.

distanceToSquared

public double distanceToSquared(Point2D p)
Returns the distance squared from the specified point to this ray. If the projection of the point lies on the ray then this perpendicular distance squared is returned. If the point lies behind the ray origin then the straight line distance squared between the ray origin and point is returned.

Parameters:
p - Point.
Returns:
Distance squared from this ray to the specified point.

distanceTo

public double distanceTo(Point2D p)
Returns the distance from the specified point to this ray; ie sqrt(distanceToSquared(p)). If the projection of the point lies on the ray then this perpendicular distance is returned. If the point lies behind the ray origin then the straight line distance between the ray origin and point is returned.

Parameters:
p - Point.
Returns:
Distance from this ray to the specified point.

normaliseDirectionVector

public void normaliseDirectionVector()
Normalises the direction vector of this ray.

Since:
1.1

distanceToSquared

public double distanceToSquared(Ray2D ray1,
                                double tolerance,
                                Point2D ray0ClosestPoint,
                                Point2D ray1ClosestPoint)
Returns the minimum distance squared between this ray (ray0) and the specified ray (ray1).

Parameters:
ray1 - Other ray.
tolerance - Required tolerance.
ray0ClosestPoint - Set upon return to the point on this ray that is closest to the specified ray.
ray1ClosestPoint - Set upon return to the point on the specified ray that is closest to this ray.
Returns:
The minimum distance squared.
Since:
1.1

distanceTo

public double distanceTo(Ray2D ray1,
                         double tolerance,
                         Point2D ray0ClosestPoint,
                         Point2D ray1ClosestPoint)
Returns the minimum distance between this ray (ray0) and the specified ray (ray1).

Parameters:
ray1 - Other ray.
tolerance - Required tolerance.
ray0ClosestPoint - Set upon return to the point on this ray that is closest to the specified ray.
ray1ClosestPoint - Set upon return to the point on the specified ray that is closest to this ray.
Returns:
The minimum distance.
Since:
1.1

pointsOnRay

public java.util.ArrayList<Point2D> pointsOnRay(Point2D startPoint,
                                                Point2D endPoint,
                                                double distanceBetweenPoints)
                                         throws java.lang.IllegalArgumentException
Returns a vector of points between the specified start and end points on this ray. The distance between the points is speicfied by distanceBetweenPoints. The returned vector includes both the start and end points.

Parameters:
startPoint - Start point. Must be on the ray and before the end point.
endPoint - End point. Must be on the ray and after the start point.
distanceBetweenPoints - Distance between intermediate points. Must be less than the dstance between the start and end points.
Returns:
Vector of points on this ray.
Throws:
java.lang.IllegalArgumentException - Thrown if endPoint is before startPoint, startPoint and endPoint are the same point or distanceBetweenPoints is greater than the distance between the start and end point.

toLinearLine2D

public LinearLine2D toLinearLine2D()
Returns a LinearLine2D equivalent of this ray. Generates the line by passing an infinite line through this ray oriign and a point at parametric distance 10 from the ray origin.

Returns:
LinearLine2D line passing through this ray.

toString

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

Overrides:
toString in class Curve2D
Returns:
A String representation of a Ray2D object.

pointOfCurve

public boolean pointOfCurve(Point2D p,
                            double tolerance)
Tests if the specified point is a point of this ray; ie if p is identical to the ray origin.

Overrides:
pointOfCurve in class Curve2D
Parameters:
p - Point to test.
tolerance - Require tolerance.
Returns:
Logical-true if p is located at the same coordinates as this ray origin, else logical-false.

tangent

public Vector2D tangent(double u)
                 throws java.lang.IllegalArgumentException
Returns the tangent vector; ie the ray direction vector. Since the direction vector is constant then the returned vector is independent of u.

Overrides:
tangent in class Curve2D
Parameters:
u - Parametric-variable along the ray from the origin.
Returns:
The tangent vector.
Throws:
java.lang.IllegalArgumentException - Thrown if u is invalid.

tangent

public Vector2D tangent(Point2D p)
                 throws java.lang.IllegalArgumentException
Returns the tangent vector; ie the ray direction vector. Since the direction vector is constant then the returned vector is independent of p.

Overrides:
tangent in class Curve2D
Parameters:
p - Point at which to find the tangent.
Returns:
The tangent vector.
Throws:
java.lang.IllegalArgumentException - Thrown if p is invalid.

tangent

public Vector2D tangent()
Returns the tangent vector; ie the direction vector.

Returns:
The tangent vector.

torsion

public double torsion(double u)
               throws java.lang.IllegalArgumentException
Returns the torsion at u. Since the direction vector is constant then the returned value is independent of u.

Parameters:
u - Parametric-variable along the ray from the origin.
Returns:
The torsion at u; ie 0.
Throws:
java.lang.IllegalArgumentException - Thrown if u is invalid.

translate

public Curve2D translate(double tx,
                         double ty)
Translates this ray by the specified (tx,ty) translation vector.

Parameters:
tx - Translation in the x-direction.
ty - Translation in the y-direction.
Returns:
New translated Ray2D object.

scale

public Curve2D scale(double sx,
                     double sy,
                     Point2D fixedPoint)
Scales this ray by the specified scaling factors in the x and y directions.

Parameters:
sx - Scaling in the x-direction.
sy - Scaling in the y-direction.
fixedPoint - Fixed point abut which scaling occurs. If set to null then scaling is wrt the global origin.
Returns:
New scaled Ray2D object.

secondDerivative

public Vector2D secondDerivative(double u)
                          throws java.lang.IllegalArgumentException
Returns the second derivative at u. Since the direction vector is constant then the returned vector is independent of u and equal to Vector2D.ZERO.

Overrides:
secondDerivative in class Curve2D
Parameters:
u - Parametric-variable along the ray from the origin.
Returns:
Second derivative vector; ie Vector2D.ZERO.
Throws:
java.lang.IllegalArgumentException - Thrown if u is invalid.

parametricVariable

public double parametricVariable(Point2D p,
                                 double tolerance)
                          throws java.lang.IllegalArgumentException
Returns the value of the parametric variable, t, corresponding to the specified point. If the point does not lie on this ray then an excetion if thrown.

Overrides:
parametricVariable in class Curve2D
Parameters:
p - Point from which to determine parametric variable equivalent.
tolerance - Required tolerance.
Returns:
Parametric variable value corresponding to the specified point.
Throws:
java.lang.IllegalArgumentException - Thrown if p not on this ray.

intersection

public Point2D intersection(Ray2D ray,
                            double tolerance)
Returns the point of intersection between two rays, if any.

Parameters:
ray - Other ray to test for intersection.
tolerance - Required tolerance.
Returns:
Intersection point (if any), else null if no intersection.

intermediatePoint

public Point2D intermediatePoint(double c1,
                                 double c2)
                          throws java.lang.IllegalArgumentException
Returns null since method is undefined for a ray of infinite length.

Parameters:
c1 - Length coordinate c1, which is the distance between the origin and the required intermediate point.
c2 - Length coordinate c2, which is the distance between the required point and the end of this ray.
Returns:
Intermediate point.
Throws:
java.lang.IllegalArgumentException - Thrown if (c1,c2) are invalid.

intermediatePointLengthCoordinates

public void intermediatePointLengthCoordinates(Point2D p,
                                               double tolerance,
                                               HDouble c1,
                                               HDouble c2)
                                        throws java.lang.IllegalArgumentException
Returns, via reference, the distances c1 and c2 from origin to p and p to end-of ray.

Parameters:
p - Point to determine distance from.
tolerance - Required tolerance.
c1 - Set upon return to the distance between origin and p.
c2 - Set upon return to POSITIVE_INFINITE since a has infinite length.
Throws:
java.lang.IllegalArgumentException - Thrown if p does not lie on this ray.

rayThroughPointSet

public static Ray2D rayThroughPointSet(Point2DSet pset)
                                throws java.lang.IllegalArgumentException,
                                       InvalidObjectException

Returns a Ray2D object that passes through the specified point set. The method used is a least squares fit through the point set minimising the orthogonal distance from the ray to the point set.

The ray origin is set to the point set centroid. The ray direction may not be expected, and if, for example, testing the generated ray for intersection with a line then simply test the ray in both direcitons using Ray2D.reverse().

Note that no test is performed as to whether or not the point set consists of distinct points. If the number of points is equal to 2 and they are at the same position then an IllegalArgumentException will be thrown when building the ray. No such catch will occur for more than 2 points at the same position, so ensure that the point set is distributed. The only requirement is at least 2 points are distinct, which will generally be the case.

Parameters:
pset - Point set.
Returns:
Ray2D passing through the specified point set.
Throws:
java.lang.IllegalArgumentException - Thrown if the specified point set is null or has less than 2 points.
InvalidObjectException - Thrown if an internal error occurred performing the eigenvector solution of the least squares fit.

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 consisting of this object's Point2D origin and Vector2D direction.

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 added.
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.

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.