com.hedgehog.geo.twod.curves
Class PolyCurve2D

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.PolyCurve2D
All Implemented Interfaces:
ModelObject, java.lang.Comparable, java.util.Comparator
Direct Known Subclasses:
PolyStraightLine2D

public class PolyCurve2D
extends Curve2D
implements ModelObject

Title: PolyCurve2D - represents a curve as a vector of curve segments.

Description: Models a poly-curve by encapsulating a vector of curve segments.

It is assumed that adjacent vector elements refer to adjacent polycurve segments sharing a common point, forming a contiguous chain of segments.

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

Company: Hedgehog Software.

Since:
1.0
Version:
1.1

Field Summary
protected  java.util.Vector<Curve2D> mCurves
          Vector of curve segments.
 
Fields inherited from class com.hedgehog.geo.twod.curves.Curve2D
mp0, mp1
 
Fields inherited from class com.hedgehog.HObject
mID, mName
 
Constructor Summary
PolyCurve2D()
          Default constructor.
PolyCurve2D(ID id)
          Constructor.
PolyCurve2D(PolyCurve2D object)
          Copy constructor.
PolyCurve2D(java.lang.String name)
          Constructor.
PolyCurve2D(java.lang.String name, ID id)
          Constructor.
PolyCurve2D(java.util.Vector<Curve2D> curves)
          Constructor.
PolyCurve2D(java.util.Vector<Curve2D> curves, boolean ordered, double tolerance)
          Constructor.
 
Method Summary
 boolean addCurveSegment(Curve2D curve)
          Appends the specified curve to this poly-curves vector of curve segments.
 boolean addCurveSegment(Curve2D curve, int index)
          Adds the specified curve at the specified index.
 java.util.Vector<ModelObject> childModelObjects()
          Returns a vector of this object's child ModelObject objects.
 java.util.Vector<Point2D> curvePoints()
          Returns a vector of unique curve points that are the end-points of the curve segments that make up this polycurve.
 java.util.Vector<PairPQ<HInteger,java.lang.String>> curveSegmentIDTypes()
          Returns an array of this object's curve segment IDs and segment types.
 Interval curveSegmentInterval(int segment_number)
          Returns the parametric variable interval of the specified curve segment.
 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.
 Curve2D firstSegment()
          Returns the first curve segment.
 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.
 java.util.Vector<Curve2D> getCurves()
          Returns the curve segment vector.
 Curve2D getCurveSegment(int curveIndex)
          Returns the curve segment at the specified index.
 boolean isClosed(double tolerance)
          Tests whether or not this poly-curve is closed; ie p0 of the first curve segment is at the same geometric position as p1 of the last curve segment.
 Curve2D lastSegment()
          Returns the last curve segment.
 double length()
          Returns the total length of this poly-curve.
 Curve2D nearestSegment(Point2D p, double tolerance)
          Returns the segment nearest to the specified point.
 int nearestSegmentIndex(Point2D p, double tolerance)
          Returns the index of the segment nearest to the specified point.
 int numberCurvePoints()
          Returns the number of points on a poly-curve; ie, number of segments+1.
 int numberSegments()
          Returns the number of curve segments.
 Point2D pointOnCurve(double u, double tolerance)
          Returns a point on this curve.
 boolean pointOnCurve(Point2D p, double tolerance)
          Tests whether or not the specified point lies on this poly-curve.
 boolean pointOnLeft(Point2D p, double tolerance)
          Tests whether or not the specified point is on the lhs of this line, with the line's sense from p0 to p1.
 boolean pointOnRight(Point2D p, double tolerance)
          Tests whether or not the specified point is on the lhs of this line, with the line's sense from p0 to p1.
 boolean removeCurveSegment(int index)
          Removes the curve segment at the specified index.
 void setCurves(java.util.Vector<Curve2D> curves)
          Sets the curve segment vector.
 java.lang.String toString()
          Returns a String representation of a PolyCurve2D 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.
 
Methods inherited from class com.hedgehog.geo.twod.curves.Curve2D
commonEndPoint, curvature, curvePoints, distanceBetweenTwoPointsAlongCurve, distanceBetweenTwoPointsAlongCurve, equals, evenlySpacedIntermediatePoints, getP0, getP1, interpolation, is2D, is3D, isCurve, isEndPoint, isEndPointP0, isEndPointP1, isGrid, isMesh, isOpen, isP0Set, isP1Set, isPoint, isPointSet, isShape, isSurface, isValid, jacobianDeterminant, length, lengthCoordinates, lengthFunction, maximumX, maximumY, midPoint, minimumDistance, minimumX, minimumY, nearestEndPoint, nearestEndPoint, nearestPoint, nearestPointApprox, otherEndPoint, parametricVariable, pointOfCurve, pointXOnCurve, pointYOnCurve, randomPoint, reverse, sameCurve, sameEndPoints, secondDerivative, setP0, setP1, shapeFunctions, shapeFunctions, shapeFunctionsDerivatives, shareEndPoint, tangent, tangent, toPolyStraightLine2D, trihedron, unitBiNormalVector, unitPrincipalNormalVector
 
Methods inherited from class com.hedgehog.geo.GeometricObject
objectDimension
 
Methods inherited from class com.hedgehog.HObject
clone, compare, compareTo, copy, getID, getName, hashCode, hasID, hasName, setID, setName
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

mCurves

protected java.util.Vector<Curve2D> mCurves
Vector of curve segments.

Constructor Detail

PolyCurve2D

public PolyCurve2D()
Default constructor. Calls Curve2D() and creates a new non-null empty curves vector


PolyCurve2D

public PolyCurve2D(java.util.Vector<Curve2D> curves)
Constructor. Creates a new poly-curve from the specified vector of general curves. Assumes that the curves are ordered correctly.

Parameters:
curves - Vector of curves.

PolyCurve2D

public PolyCurve2D(java.util.Vector<Curve2D> curves,
                   boolean ordered,
                   double tolerance)
Constructor. Builds a poly-curve from the specified vector of curves. Caters for both open and closed poly-curves. If the vector of curves does not define a continuous poly-curve then the encapsulated curves vector is flushed to indicate an invalid supplied curves vector.

Parameters:
curves - Vector of curves making up poly-curve.
ordered - Boolean indicating whether or not the specified vector of curves is ordered in that the ordering of the curves forms a continuous poly-curve or not. If ordered is set to logical-false then curves[0] is first added to this poly-curve and all other curves added by testing for common end-points.
tolerance - Required tolerance.

PolyCurve2D

public PolyCurve2D(java.lang.String name)
Constructor. Calls Curve2D() and creates a new non-null empty curves vector.

Parameters:
name - Poly-curve name.

PolyCurve2D

public PolyCurve2D(ID id)
Constructor. Calls Curve2D() and creates a new non-null empty curves vector.

Parameters:
id - Poly-curve ID.

PolyCurve2D

public PolyCurve2D(java.lang.String name,
                   ID id)
Constructor. Calls Curve2D().

Parameters:
name - Poly-curve name.
id - Poly-curve ID.

PolyCurve2D

public PolyCurve2D(PolyCurve2D object)
Copy constructor.

Parameters:
object - Object to copy.
Method Detail

getCurves

public java.util.Vector<Curve2D> getCurves()
Returns the curve segment vector.

Returns:
The curve segment vector.

setCurves

public void setCurves(java.util.Vector<Curve2D> curves)
Sets the curve segment vector.

Parameters:
curves - New curve segment vector.

getCurveSegment

public Curve2D getCurveSegment(int curveIndex)
                        throws java.lang.IllegalArgumentException
Returns the curve segment at the specified index.

Parameters:
curveIndex - Curve segment index.
Returns:
Curve segment.
Throws:
java.lang.IllegalArgumentException - Thrown if the specified curve index is invalid.

addCurveSegment

public boolean addCurveSegment(Curve2D curve)
Appends the specified curve to this poly-curves vector of curve segments.

Parameters:
curve - Curve to add.
Returns:
Logical-true if curve added, else logical-false.

addCurveSegment

public boolean addCurveSegment(Curve2D curve,
                               int index)
Adds the specified curve at the specified index.

Parameters:
curve - Curve to add.
index - Index to add curve.
Returns:
Logical-true if curve added, else logical-false.

removeCurveSegment

public boolean removeCurveSegment(int index)
Removes the curve segment at the specified index.

Parameters:
index - Curve segment index.
Returns:
Logical-true if the curve segment at the specified index is removed, else logical-false if the specified index is out of range.

isClosed

public boolean isClosed(double tolerance)
Tests whether or not this poly-curve is closed; ie p0 of the first curve segment is at the same geometric position as p1 of the last curve segment.

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

numberSegments

public int numberSegments()
Returns the number of curve segments.

Returns:
The number of curve segments.

firstSegment

public Curve2D firstSegment()
Returns the first curve segment.

Returns:
The first curve segment. If there are no curve segments or mCurves is null then null is returned.

lastSegment

public Curve2D lastSegment()
Returns the last curve segment.

Returns:
The last curve segment. If there are no curve segments or mCurves is null then null is returned.

length

public double length()
Returns the total length of this poly-curve.

Overrides:
length in class Curve2D
Returns:
Total length.

toString

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

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

numberCurvePoints

public int numberCurvePoints()
Returns the number of points on a poly-curve; ie, number of segments+1.

Returns:
The number of curve points.

curveSegmentInterval

public Interval curveSegmentInterval(int segment_number)
                              throws java.lang.IllegalArgumentException
Returns the parametric variable interval of the specified curve segment.

Parameters:
segment_number - Number of segment for which interval is required.
Returns:
Parametric interval of specified interval.
Throws:
java.lang.IllegalArgumentException - Throws an InvalidArgumentException exception if segment_number is out of range.

curveSegmentIDTypes

public java.util.Vector<PairPQ<HInteger,java.lang.String>> curveSegmentIDTypes()
Returns an array of this object's curve segment IDs and segment types.

Returns:
An array of this object's curve segment IDs and segment types.

curvePoints

public java.util.Vector<Point2D> curvePoints()
Returns a vector of unique curve points that are the end-points of the curve segments that make up this polycurve.

Returns:
Vector of curve points.

nearestSegment

public Curve2D nearestSegment(Point2D p,
                              double tolerance)
Returns the segment nearest to the specified point.

Parameters:
p - Point.
tolerance - required tolerance.
Returns:
Polycurve segment nearest the specified point. A null value is returned if the polyline is either empty (no segments) or the nearest segment could not be determined.

nearestSegmentIndex

public int nearestSegmentIndex(Point2D p,
                               double tolerance)
Returns the index of the segment nearest to the specified point.

Parameters:
p - Point.
tolerance - Required tolerance.
Returns:
Polycurve segment index nearest the specified point. A value of -1 is returned if the polyline is either empty (no segments) or the nearest segment could not be determined.

pointOnCurve

public Point2D pointOnCurve(double u,
                            double tolerance)
                     throws java.lang.IllegalArgumentException
Returns a point on this curve. u now becomes the parametric variable of the entire curve with u=0 and u=1 at the first and last end-points resp. If u=0 then a copy ofmCurves.firstElement().getP0() is returned. If u=1 then a copy of mCurves.lastElement().getP1() is returned.

Specified by:
pointOnCurve in class Curve2D
Parameters:
u - Parametric-variable value. Must be in range [0:1].
tolerance - Required tolerance.
Returns:
Point on this poly-curve.
Throws:
java.lang.IllegalArgumentException - Thrown if u is out of range.

pointOnCurve

public boolean pointOnCurve(Point2D p,
                            double tolerance)
Tests whether or not the specified point lies on this poly-curve.

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

pointOnLeft

public boolean pointOnLeft(Point2D p,
                           double tolerance)
Tests whether or not the specified point is on the lhs of this line, with the line's sense from p0 to p1. Note that for a polyline the point-on-left test is slightly ambiguous, so the method used is to first find the segment nearest the specified point p. The point-on-left test is then performed for this nearest segment.

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

pointOnRight

public boolean pointOnRight(Point2D p,
                            double tolerance)
Tests whether or not the specified point is on the lhs of this line, with the line's sense from p0 to p1. Note that for a polyline the point-on-right test is slightly ambiguous, so the method used is to first find the segment nearest the specified point p. The point-on-right test is then performed for this nearest segment.

Specified by:
pointOnRight in class Curve2D
Parameters:
p - point to test.
tolerance - Required tolerance.
Returns:
Logical-true if p on the left of this line, 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 consisting of this object's vector of poly-curves.

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. Returns a node of this poly-curve's segment curves.

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.