com.hedgehog.geo.twod.curves
Class Curve2D

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
All Implemented Interfaces:
ModelObject, java.lang.Comparable, java.util.Comparator
Direct Known Subclasses:
CircularArc2D, LinearLine2D, ParametricLine2D, PolyCurve2D, Ray2D, StraightLine2D, SymbolicFunctionCurve2D, SymbolicParametricCurve2D

public abstract class Curve2D
extends GeometricObject2D

Title: Curve2D - abstract base class of 2D curves.

Description: Abstract base class of 2D curve hierarchy.

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

Company: Hedgehog Software

Since:
1.0
Version:
1.1

Field Summary
protected  Point2D mp0
          Curve end-point p0.
protected  Point2D mp1
          Curve end-point p1.
 
Fields inherited from class com.hedgehog.HObject
mID, mName
 
Constructor Summary
Curve2D()
          Default constructor.
Curve2D(Curve2D object)
          Copy constructor.
Curve2D(ID id)
          Constructor.
Curve2D(Point2D p0, Point2D p1)
          Constructor.
Curve2D(Point2D p0, Point2D p1, java.lang.String name, ID id)
          Constructor.
Curve2D(java.lang.String name)
          Constructor.
Curve2D(java.lang.String name, ID id)
          Constructor.
 
Method Summary
 Point2D commonEndPoint(Curve2D c)
          Returns the end point which is common to both Curves (if one exists).
 double curvature(double u)
          Returns the curvature of a curve at parametric point u.
 java.util.Vector<Point2D> curvePoints(int uPoints, double umin, double umax, double tolerance)
          Returns a vector of curve points that are evenly spaced between the specified umin and umax parametric variable values.
 double distanceBetweenTwoPointsAlongCurve(ParametricSegment segment)
          Returns the distance measured along this curve between the two specified parametric variable points.
 double distanceBetweenTwoPointsAlongCurve(Point2D p, Point2D q, double tolerance)
          Returns the distance measured along this curve between the two specified points.
 boolean equals(java.lang.Object object)
          Tests whether or not two curves are equal, ie (p0,p1) is equivalent to (c.p0,c.p1); ie preserving the curve of p0 to p1.
 java.util.Vector<Point2D> evenlySpacedIntermediatePoints(int nPoints, double tolerance)
          Returns a vector of intermediate evenly spaced points on the curve (default is 10).
 Point2D getP0()
          Returns the curve end-point p0.
 Point2D getP1()
          Returns the curve end-point p1.
 double interpolation(FloatingPointVector vi, double u)
          Returns an interpolated value at the parametric point u from the values vi.
 boolean is2D()
          Tests whether or not this object is a 2D object; ie true.
 boolean is3D()
          Tests whether or not this object is a 3D object; ie false.
 boolean isCurve()
          Tests whether or not this object is a curve; ie true.
 boolean isEndPoint(Point2D p, double tolerance)
          Returns logical-true if p is an end-point of a curve, else logical-false.
 boolean isEndPointP0(Point2D p, double tolerance)
          Returns logical-true if p is end-point p0 of this curve, else logical-false.
 boolean isEndPointP1(Point2D p, double tolerance)
          Returns logical-true if p is end-point p1 of this curve, else logical-false.
 boolean isGrid()
          Tests whether or not this object is a grid; ie false.
 boolean isMesh()
          Tests whether or not this object is a mesh; ie false.
 boolean isOpen()
          Tests whether or not this curve is open; ie the end-points p0 and p1 are not the same point.
 boolean isP0Set()
          Tests whether or not end-point p0 is non-null.
 boolean isP1Set()
          Tests whether or not end-point p1 is non-null.
 boolean isPoint()
          Tests whether or not this object is a point; ie false.
 boolean isPointSet()
          Tests whether or not this object is a point set; ie false.
 boolean isShape()
          Tests whether or not this object is a shape; ie false.
 boolean isSurface()
          Tests whether or not this object is a surface; ie false.
 boolean isValid()
          Tests whether or not a Curve2D object is valid.
 double jacobianDeterminant(double zeta, InterpolationOrder order, Vector2D lx, Vector2D ly)
          Returns the Jacobian matrix (i.e.
 double length()
          Returns the total length of this general 2D curve using approximate Gauss integration by integrating a length function based on the approximate tangent() method.
 double length(ParametricSegment segment)
          Returns the length of this general 2D curve along the parametric segment [u1:u2] using approximate Gauss integration.
 PairDouble lengthCoordinates(Point2D p, double tolerance)
          Returns the length coordinates (pair) of a specified point; ie zeta1 being the normalised distance between p and end-point p1 and zeta2 being the normalised distance between end-point p0 and p.
 double lengthFunction(HDouble u)
          Private method for computing the of a general curve for use with OneVariableFunction.
 double maximumX(double tolerance)
          Returns the maximum x-value of this curve.
 double maximumY(double tolerance)
          Returns the minimum y-value of this curve.
 Point2D midPoint()
          Returns the mid-point of this curve.
 double minimumDistance(Point2D p, double tolerance)
          Returns the minimum distance between the specified point and this curve.
 double minimumX(double tolerance)
          Returns the minimum x-value of this curve.
 double minimumY(double tolerance)
          Returns the minimum y-value of this curve.
 Point2D nearestEndPoint(double u, double tolerance)
          Returns the nearest end point to the specified parametric variable.
 Point2D nearestEndPoint(Point2D p, int method, double tolerance)
          Returns the nearest end-point to the specified point, p, using the indicated method.
 Point2D nearestPoint(Point2D q, double tolerance, HDouble uNearest)
          Returns the nearest point on this curve to the specified point.
 Point2D nearestPointApprox(Point2D q, int nuPoints, double tolerance, HDouble uNearest)
          Returns the approximate nearest point on this curve to the specified point.
 Point2D otherEndPoint(Point2D p, double tolerance)
          Returns an end-point other than the one specified.
 double parametricVariable(Point2D p, double tolerance)
          Returns the parametric variable distance [0:1] between the specified point and end-point p0 of this curve to the specified tolerance.
 boolean pointOfCurve(Point2D p, double tolerance)
          Tests if the specified point is an end-point of this curve.
abstract  Point2D pointOnCurve(double u, double tolerance)
          Returns a point on this curve at the specified parametric distance from end-point p0.
abstract  boolean pointOnCurve(Point2D p, double tolerance)
          Tests whether or not the specified point is on this curve.
abstract  boolean pointOnLeft(Point2D p, double tolerance)
          Tests whether or not the specified point is on the left of this curve.
abstract  boolean pointOnRight(Point2D p, double tolerance)
          Tests whether or not the specified point is on the right of this curve.
 HDouble pointXOnCurve(HDouble u)
          Returns the x value of the specified parametric-variable value.
 HDouble pointYOnCurve(HDouble u)
          Returns the y value of the specified parametric-variable value.
 Point2D randomPoint()
          Returns a random point on the curve between the end-points.
 void reverse()
          Reverses the end-points p0 and p1 such that p0 points to p1 and p1 points to p0.
 boolean sameCurve(Curve2D c, boolean bothSenses, double tolerance)
          Tests whether or not two curves are equivalent.
 boolean sameEndPoints(Curve2D c, double tolerance)
          Tests whether or not two curves share the same end-points, irrespective of curve sense.
 Vector2D secondDerivative(double u)
          Returns the second derivative of a curve at parametric point u using 3 point approximate differentiation formulae with h=1e-03.
 void setP0(Point2D p0)
          Sets end-point p0.
 void setP1(Point2D p1)
          Sets end-point p1.
 FloatingPointFullMatrix shapeFunctions(double u, InterpolationOrder order)
          Returns the shape functions of a curve given a specified point.
 FloatingPointFullMatrix shapeFunctions(Point2D p, InterpolationOrder order, double tolerance)
          Returns the shape functions of a curve given a specified point.
 double shapeFunctionsDerivatives(int ni, double zeta, InterpolationOrder order)
          Returns the derivative of a shape function Ni at parametric point zeta=zeta2 with respect to zeta for a given interpolation order.
 Point2D shareEndPoint(Curve2D c, double tolerance)
          Tests whether or not two curves share the same end-point.
 Vector2D tangent(double u)
          Returns the tangent vector at parametric point u.
 Vector2D tangent(Point2D p)
          Returns the tangent vector at the specified point.
 PolyStraightLine2D toPolyStraightLine2D(int nPoints, double umin, double umax, double tolerance)
          Returns a PolyStraightLine2D equivalent object of this genral Curve2D object.
 java.lang.String toString()
          Returns a String representation of a Curve2D object.
 TriplePQR<Vector2D,Vector2D,HDouble> trihedron(double u)
          Returns the trihedron triple (t,p,b) at parametric point u[0:1].
 double unitBiNormalVector(double u)
          Returns the unit bi-normal vector (uxp) at parametric point u.
 Vector2D unitPrincipalNormalVector(double u)
          Returns the unit principal normal vector (u'/curvature) at parametric point u.
 
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
 
Methods inherited from interface com.hedgehog.model.ModelObject
childModelObjects, databaseInsertStatement, databaseUpdateStatement, fromDatabase, fromXMLNode, toX3DNode, toXMLNode
 

Field Detail

mp0

protected Point2D mp0
Curve end-point p0.


mp1

protected Point2D mp1
Curve end-point p1.

Constructor Detail

Curve2D

public Curve2D()
Default constructor. Initialises both end-points to null.


Curve2D

public Curve2D(Point2D p0,
               Point2D p1)
Constructor. Initialises the end-points to the specified points.

Parameters:
p0 - End-point p0.
p1 - End-point p1.

Curve2D

public Curve2D(Point2D p0,
               Point2D p1,
               java.lang.String name,
               ID id)
Constructor. Initialises the end-points to the specified points.

Parameters:
p0 - End-point p0.
p1 - End-point p1.
name - Object name.
id - Object ID.

Curve2D

public Curve2D(java.lang.String name)
Constructor. Initialises both end-points to null and sets the name to the specified string.

Parameters:
name - Object name.

Curve2D

public Curve2D(ID id)
Constructor. Initialises both end-points to null and sets the ID to the specified object.

Parameters:
id - Object ID.

Curve2D

public Curve2D(java.lang.String name,
               ID id)
Constructor. Initialises both end-points to null and sets the name and ID to the specified objects.

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

Curve2D

public Curve2D(Curve2D object)
Copy constructor.

Parameters:
object - Object to copy.
Method Detail

equals

public boolean equals(java.lang.Object object)
Tests whether or not two curves are equal, ie (p0,p1) is equivalent to (c.p0,c.p1); ie preserving the curve of p0 to p1. To test if a curve has the same vertices irrespective of sense then use sameVertices().

Specified by:
equals in interface java.util.Comparator
Overrides:
equals in class HObject
Parameters:
object - Objectto compare against this object.
Returns:
Logical-true if the specified object is equal (same name and ID) as this object, else logical-false.

tangent

public Vector2D tangent(double u)
                 throws java.lang.IllegalArgumentException
Returns the tangent vector at parametric point u. Uses approximate 2-point differentiation formulae with h=1e-03.

Parameters:
u - Parametric variable u. Must be in the range [0:1].
Returns:
Tangent vector at u.
Throws:
java.lang.IllegalArgumentException - Throws exception if u is outside the range [0:1].

tangent

public Vector2D tangent(Point2D p)
                 throws java.lang.IllegalArgumentException
Returns the tangent vector at the specified point.

Parameters:
p - Point at which to determine tanget.
Returns:
Tangent vector to curve at specified point.
Throws:
java.lang.IllegalArgumentException - Thrown if p is null or not on this curve.

trihedron

public TriplePQR<Vector2D,Vector2D,HDouble> trihedron(double u)
Returns the trihedron triple (t,p,b) at parametric point u[0:1].

Parameters:
u - Parametric variable value at which the trihedron is to be determined.
Returns:
Triple.

unitBiNormalVector

public double unitBiNormalVector(double u)
                          throws java.lang.IllegalArgumentException
Returns the unit bi-normal vector (uxp) at parametric point u.

Parameters:
u - Parametric variable value at which the unit bi-normal is to be determined. Must be in the range [0:1].
Returns:
Unit normal bi-normal value.
Throws:
java.lang.IllegalArgumentException - Thrown if u is out of range [0:1].

unitPrincipalNormalVector

public Vector2D unitPrincipalNormalVector(double u)
                                   throws java.lang.IllegalArgumentException
Returns the unit principal normal vector (u'/curvature) at parametric point u. Note: if the curvature at point u is 0 then a zero vector is returned.

Parameters:
u - Parametric variable value at which the unit principal normal is to be determined. Must be in the range [0:1].
Returns:
Unit principal normal vector.
Throws:
java.lang.IllegalArgumentException - Thrown if u is out of range [0:1].

curvature

public double curvature(double u)
                 throws java.lang.IllegalArgumentException
Returns the curvature of a curve at parametric point u. The curvature is equal to |dT/ds|, ie the rate of change of the tangent vector wrt arc length, position on the curve. It can be shown that the curvature is equal to |pu x puu| / |pu|^3 where pu=dp(u)/du and puu=dpu(u)/du

Parameters:
u - Parametric variable value on curve measured from end-point p0. Must be in the range [0:1].
Returns:
Curvature at u.
Throws:
java.lang.IllegalArgumentException - Thrown if u not in the range [0:1].

secondDerivative

public Vector2D secondDerivative(double u)
                          throws java.lang.IllegalArgumentException
Returns the second derivative of a curve at parametric point u using 3 point approximate differentiation formulae with h=1e-03.

Parameters:
u - Parametric variable value on curve measured from end-point p0. Must be in the range [0:1].
Returns:
Second derivative.
Throws:
java.lang.IllegalArgumentException - Thrown if u not in range [0:1].

jacobianDeterminant

public double jacobianDeterminant(double zeta,
                                  InterpolationOrder order,
                                  Vector2D lx,
                                  Vector2D ly)
                           throws java.lang.IllegalArgumentException
Returns the Jacobian matrix (i.e. |J|) of a point on a curve for the following interpolation orders: linear(default) 2 end-points, quadratic 2 end-points and 1 mid-point or cubic 2 end-points and 2 interior points at t=(1/3) and t=(2/3). Note: [J] evaluated wrt to the local axes (lx,ly) which, by default, are set to (1,0), (0,1) and with p0 taken as the local origin.

Parameters:
zeta - Parametric-variable value. Must be in range [0:1].
order - Interpolation order. Must be LINEAR, QUADRATIC or CUBIC.
lx - Local x'-axis.
ly - Local y'-axis.
Returns:
Deternimant of the Jacobian matrix; ie |J|.
Throws:
java.lang.IllegalArgumentException - Thrown if zeta is not on the curve.

midPoint

public Point2D midPoint()
Returns the mid-point of this curve. Returns the point at parametric distance 0.5.

Returns:
Mid-point of this curve.

lengthFunction

public double lengthFunction(HDouble u)
Private method for computing the of a general curve for use with OneVariableFunction.

Parameters:
u - Parametric variable u.
Returns:
Evaluation of length function at u.

length

public double length()
Returns the total length of this general 2D curve using approximate Gauss integration by integrating a length function based on the approximate tangent() method.

Returns:
Length of this curve. A value of -1 is returned if an internal error occurred.

length

public double length(ParametricSegment segment)
              throws java.lang.IllegalArgumentException
Returns the length of this general 2D curve along the parametric segment [u1:u2] using approximate Gauss integration.

Parameters:
segment - Parametric segment.
Returns:
Length of this curve along the specified parametric segment. A value of -1 is returned if an interbal error occurred.
Throws:
java.lang.IllegalArgumentException - Thrown if segment is invalid.

parametricVariable

public double parametricVariable(Point2D p,
                                 double tolerance)
Returns the parametric variable distance [0:1] between the specified point and end-point p0 of this curve to the specified tolerance. It is assumed that p lies on this curve. OneVariableFunction.optimisationBFGS() is used to perform the minimisation using CurvePoint2D.parametricVariableObjectiveFunction() as the objective funtion. The initial search commences from the curve mid-point (u=0.5).

Parameters:
p - Point on this curve to determine minimum distance between and this curve.
tolerance - Required tolerance.
Returns:
Parametric variable distance of end-point p0 to the specified point, p. If an error occurs in OneVariableFunction.optimisationBFGS() then a value of -1.0 is returned. For example, with overridden StraightLine2D.parametricVariable() removed this method gives: StraightLine2D sline = new StraightLine2D(new Point2D(1,0),new Point2D(5,0)); Point2D p = new Point2D(2.0,0.0); double u = sline.parametricVariable(p,1e-03); java.lang.System.out.println("sline p u: " + u); with output: sline p u: 0.25000017446238687 with the exact answer being 0.25.

lengthCoordinates

public PairDouble lengthCoordinates(Point2D p,
                                    double tolerance)
                             throws java.lang.IllegalArgumentException
Returns the length coordinates (pair) of a specified point; ie zeta1 being the normalised distance between p and end-point p1 and zeta2 being the normalised distance between end-point p0 and p. The length coordinates are noramlised with respect to the curve length so that they are both in the range [0:1]. Thus, zeta1=0 indicates that p is at p1 and zeta1=1 indicates that p is at p0 and zeta1=0.5 indicates that p is at the curve mid-point. It follows that zeta2=1.0-zeta1.

Parameters:
p - Test point.
tolerance - Required tolerance.
Returns:
Length coordinates pair.
Throws:
java.lang.IllegalArgumentException - Thrown if p not on this curve.

shapeFunctions

public FloatingPointFullMatrix shapeFunctions(Point2D p,
                                              InterpolationOrder order,
                                              double tolerance)
                                       throws java.lang.IllegalArgumentException
Returns the shape functions of a curve given a specified point. Uses lengthCoordinates().

Parameters:
p - Point on curve at which require shape functions.
order - Interpolation order: linear, quadratic and cubic.
tolerance - Required tolerance.
Returns:
Shape function matrix of size [1x2] for linear, [1x3] for quadratic and [1x4] for cubic interpolation orders.
Throws:
java.lang.IllegalArgumentException - Thrown if p is null of not on this curve.

shapeFunctions

public FloatingPointFullMatrix shapeFunctions(double u,
                                              InterpolationOrder order)
                                       throws java.lang.IllegalArgumentException
Returns the shape functions of a curve given a specified point. Uses lengthCoordinates().

Parameters:
u - Parametric-variable value at point where shape functions are required.
order - Interpolation order: linear, quadratic and cubic.
Returns:
Shape function matrix of size [1x2] for linear, [1x3] for quadratic and [1x4] for cubic interpolation orders.
Throws:
java.lang.IllegalArgumentException - Thrown if p is null of not on this curve.

shapeFunctionsDerivatives

public double shapeFunctionsDerivatives(int ni,
                                        double zeta,
                                        InterpolationOrder order)
                                 throws java.lang.IllegalArgumentException
Returns the derivative of a shape function Ni at parametric point zeta=zeta2 with respect to zeta for a given interpolation order.

Parameters:
ni - Indicates which shape function the derivative is with respect to, which is dependent on the interpolation order: linear interpolation the vertices are 1(zeta=1) and 2(zeta=0); 1<=ni<=2. quadratic interpolation the end-vertices 1(zeta=1), 3(zeta=0) and mid-edge vertex 2(zeta=0.5); 1<=ni<=3. cubic interpolation the end-vertices 1(zeta=1), 4(zeta=0) and edge vertices 2(zeta=1/3) and 3(zeta=2/3); 1<=ni<=4.
zeta - Parametric variable.
order - Interpolation order: LINEAR, QUDARATIC or CUBIC.
Returns:
Shape function derivative.
Throws:
java.lang.IllegalArgumentException - Thrown if t is outside the range [0:1] or ni is out of range for the specified interpolation order: LINEAR: 1<=ni<=2 QUDARATIC: 1<=ni<=3 CUBIC: 1<=ni<=4

interpolation

public double interpolation(FloatingPointVector vi,
                            double u)
                     throws java.lang.IllegalArgumentException
Returns an interpolated value at the parametric point u from the values vi. Uses shapeFunctions() to perform the interpolation with the order of interpolation (up to cubic) determined by the number of points in vi: 2 (2 end-points, u=0,1): linear 3 (2 end-points and 1 mid-point, u=0,1/2,1): quadratic 4 (2 end-points and 2 edge-points, u=0,1/3,2/3,1): cubic

Parameters:
vi - Vector of values to interpolate. Must be of size 2 for linear interpolation, size 3 or quadratic interpolation and size 4 for cubic interpolation.
u - Parametric-variable value at which interpolated value is required.
Returns:
Interpolated value.
Throws:
java.lang.IllegalArgumentException - Thrown if t is out of range 0<=t<=1 or the number of elements of vi is out of range 2<=vi<=4.

minimumDistance

public double minimumDistance(Point2D p,
                              double tolerance)
Returns the minimum distance between the specified point and this curve. Point p is assumed not to be on this curve. OneVariableFunction.optimisationBFGS() is used to perform the minimisation using CurvePoint2D.minimumDistanceObjectiveFunction() as the objective funtion. The initial search commences from the curve mid-point (u=0.5).

Parameters:
p - Point from which to determine the minimum distance between and this curve.
tolerance - Required tolerance.
Returns:
Minimum distance between specified point and this curve.

nearestEndPoint

public Point2D nearestEndPoint(Point2D p,
                               int method,
                               double tolerance)
                        throws java.lang.IllegalArgumentException
Returns the nearest end-point to the specified point, p, using the indicated method. If p lies exactly mid way between p0 and p1 then p0 is returned.

Parameters:
p - Point to test.
method - Method used: 0(parametric variable) or 1(straight-line distance).
tolerance - Required tolerance used for testing p lies on this curve.
Returns:
Nearest end-point.
Throws:
java.lang.IllegalArgumentException - Thrown if p is null or method is invalid.

nearestEndPoint

public Point2D nearestEndPoint(double u,
                               double tolerance)
                        throws java.lang.IllegalArgumentException
Returns the nearest end point to the specified parametric variable. If u<=0.5 then p0 is returned, else p1.

Parameters:
u - Parametric-variable. Must be in the range [0:1].
tolerance - Required tolerance.
Returns:
Nearest end-point.
Throws:
java.lang.IllegalArgumentException - Thrown if u is out of range [0:1].

nearestPointApprox

public Point2D nearestPointApprox(Point2D q,
                                  int nuPoints,
                                  double tolerance,
                                  HDouble uNearest)
                           throws java.lang.IllegalArgumentException
Returns the approximate nearest point on this curve to the specified point. This method simply subdivides the curve into nuPoints parametric points and returns the nearest point using pointOnCurve(u). This method is an approximate method but if nuPoints is sufficiently large (~100) then probably sufficiently accurate for most purposes or to use as an initial value for more refined searches.

Parameters:
q - Point to find nearest point.
nuPoints - Number of sample u points to test for the nearest point. Must be >= 2. Typically set to 100.
tolerance - Required tolerance.
uNearest - Set upon return to the approximate nearest parametric-variable u.
Returns:
Approximate nearest curve point to the specified point. Returns null if unable to determine the nearest point.
Throws:
java.lang.IllegalArgumentException - Thrown if nuPoints < 2.
Since:
1.1

nearestPoint

public Point2D nearestPoint(Point2D q,
                            double tolerance,
                            HDouble uNearest)
Returns the nearest point on this curve to the specified point. This is a generic method nad based entirely on pointOnCuve(u), which is required to be overridden by derived classes. OneVariableBisectionOptimiser is used to find the nearest point with min/max function CurveNearestPointOpt.evaluate() to perform the optimisation.

Parameters:
q - Point to find nearest point.
tolerance - Required tolerance.
uNearest - Set upon return to the approximate nearest parametric-variable u.
Returns:
Nearest curve point to the specified point. Returns null if unable to determine the nearest point.
Since:
1.1

distanceBetweenTwoPointsAlongCurve

public double distanceBetweenTwoPointsAlongCurve(ParametricSegment segment)
Returns the distance measured along this curve between the two specified parametric variable points.

Parameters:
segment - Parametric curve segment.
Returns:
Distance along curve between the two points.

distanceBetweenTwoPointsAlongCurve

public double distanceBetweenTwoPointsAlongCurve(Point2D p,
                                                 Point2D q,
                                                 double tolerance)
Returns the distance measured along this curve between the two specified points.

Parameters:
p - Left-hand point on curve.
q - Right-hand point on curve.
tolerance - Required tolerance.
Returns:
Distance along curve between the two points.

evenlySpacedIntermediatePoints

public java.util.Vector<Point2D> evenlySpacedIntermediatePoints(int nPoints,
                                                                double tolerance)
                                                         throws java.lang.IllegalArgumentException
Returns a vector of intermediate evenly spaced points on the curve (default is 10).

Parameters:
nPoints - Number of points.
tolerance - Required tolerance.
Returns:
Vector of evenly spaced points.
Throws:
java.lang.IllegalArgumentException - Thrown if nPoints<=0.

curvePoints

public java.util.Vector<Point2D> curvePoints(int uPoints,
                                             double umin,
                                             double umax,
                                             double tolerance)
                                      throws java.lang.IllegalArgumentException
Returns a vector of curve points that are evenly spaced between the specified umin and umax parametric variable values. This method is similar to EvenlySpacedIntermediatePoints() except that it caters for minimum and maximum parametric variable values. By setting umin to 0 and umax to 1 then the end-points are included in the returned vector of points.

Parameters:
uPoints - Number of points along the curve, including the end-points.
umin - Minimum u value.
umax - Maximum u value.
tolerance - Required tolerance.
Returns:
Vector of curve points.
Throws:
java.lang.IllegalArgumentException - Thrown if upoints<2 or umin and umax are out of range [0:1] or umin>=umax.

randomPoint

public Point2D randomPoint()
Returns a random point on the curve between the end-points.

Returns:
Random point on this curve.

isOpen

public boolean isOpen()
Tests whether or not this curve is open; ie the end-points p0 and p1 are not the same point.

Returns:
Logical-true if this curve is open, else logical-false if closed.

isValid

public boolean isValid()
Tests whether or not a Curve2D object is valid. Tests GeometricObject::isValid() and then tests that both p0 and p1 are non-null.

Returns:
Logical-true if a valid object, else logical-false.

isP0Set

public boolean isP0Set()
Tests whether or not end-point p0 is non-null.

Returns:
Logical-true if end-point p0 is non-null, else logical-false.

isP1Set

public boolean isP1Set()
Tests whether or not end-point p1 is non-null.

Returns:
Logical-true if end-point p1 is non-null, else logical-false.

isEndPoint

public boolean isEndPoint(Point2D p,
                          double tolerance)
Returns logical-true if p is an end-point of a curve, else logical-false. Uses Point2D.samePoint() to compare the points.

Parameters:
p - End-point to test.
tolerance - Required tolerance.
Returns:
Logical-true if p is an end-point, else logical-false.

isEndPointP0

public boolean isEndPointP0(Point2D p,
                            double tolerance)
Returns logical-true if p is end-point p0 of this curve, else logical-false. Uses Point2D.samePoint() to compare the points.

Parameters:
p - End-point to test.
tolerance - Required tolerance.
Returns:
Logical-true if p is end-point p0, else logical-false.

isEndPointP1

public boolean isEndPointP1(Point2D p,
                            double tolerance)
Returns logical-true if p is end-point p1 of this curve, else logical-false. Uses Point2D.samePoint() to compare the points.

Parameters:
p - End-point to test.
tolerance - Required tolerance.
Returns:
Logical-true if p is end-point p1, else logical-false.

otherEndPoint

public Point2D otherEndPoint(Point2D p,
                             double tolerance)
Returns an end-point other than the one specified.

Parameters:
p - Point on this curve for which the other end-point is returned.
tolerance - Required tolerance.
Returns:
Other end-point to specified end-point. If p is either null or not an end-point of this curve then null is returned.

pointOfCurve

public boolean pointOfCurve(Point2D p,
                            double tolerance)
Tests if the specified point is an end-point of this curve.

Parameters:
p - Point to test.
tolerance - Require tolerance.
Returns:
Logical-true if p is an end-point, else logical-false.

getP0

public Point2D getP0()
Returns the curve end-point p0.

Returns:
End-point p0.

getP1

public Point2D getP1()
Returns the curve end-point p1.

Returns:
End-point p1.

setP0

public void setP0(Point2D p0)
Sets end-point p0.

Parameters:
p0 - New end-point p0.

setP1

public void setP1(Point2D p1)
Sets end-point p1.

Parameters:
p1 - New end-point p1.

sameEndPoints

public boolean sameEndPoints(Curve2D c,
                             double tolerance)
Tests whether or not two curves share the same end-points, irrespective of curve sense.

Parameters:
c - Curve to compare.
tolerance - Required tolerance.
Returns:
Logical-true if two curves share the same end-points, else logical-false.

sameCurve

public boolean sameCurve(Curve2D c,
                         boolean bothSenses,
                         double tolerance)
Tests whether or not two curves are equivalent.

Parameters:
c - Curve to compare with this curve.
bothSenses - If true then both senses of the curve are compared, else just sense (p0-p1) sense.
tolerance - Required tolerance.
Returns:
True if two curves are equivalent, else false.

commonEndPoint

public Point2D commonEndPoint(Curve2D c)
Returns the end point which is common to both Curves (if one exists). If no common end-point then returns null.

Parameters:
c - Curve to compare against this curve.
Returns:
Common end-point (if any) or null if no point in common.

shareEndPoint

public Point2D shareEndPoint(Curve2D c,
                             double tolerance)
Tests whether or not two curves share the same end-point. If there is a common end point then common_point is set to this point.

Parameters:
c - Curve to test with this curve for common end-point.
tolerance - Required tolerance.
Returns:
The common end-point (if any), else set to null..

reverse

public void reverse()
Reverses the end-points p0 and p1 such that p0 points to p1 and p1 points to p0. This operation effectively reverses the sense of a curve.


toString

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

Overrides:
toString in class java.lang.Object
Returns:
A String representation of a Curve2D object.

toPolyStraightLine2D

public PolyStraightLine2D toPolyStraightLine2D(int nPoints,
                                               double umin,
                                               double umax,
                                               double tolerance)
                                        throws java.lang.IllegalArgumentException
Returns a PolyStraightLine2D equivalent object of this genral Curve2D object.

Parameters:
nPoints - Number of points on poly-straight line.
umin - Minimum parametric-variable value.
umax - Maximum parametric-variable value.
tolerance - Required tolerance.
Returns:
Poly straight-line equivalent of this curve.
Throws:
java.lang.IllegalArgumentException - Thrown if nPoints<2, umin/umax out of range [0:1] or umin>=umax.

pointXOnCurve

public HDouble pointXOnCurve(HDouble u)
                      throws java.lang.IllegalArgumentException
Returns the x value of the specified parametric-variable value. Used for optimiation routines in finding the minimum xcoordinate of a curve.

Parameters:
u - Parametric-variable value.
Returns:
x coordinate of point on this curve at the specified parametric-variable value.
Throws:
java.lang.IllegalArgumentException - Thrown if u is out of range [0:1].

pointYOnCurve

public HDouble pointYOnCurve(HDouble u)
                      throws java.lang.IllegalArgumentException
Returns the y value of the specified parametric-variable value. Used for optimiation routines in finding the minimum xcoordinate of a curve.

Parameters:
u - Parametric-variable value.
Returns:
y coordinate of point on this curve at the specified parametric-variable value.
Throws:
java.lang.IllegalArgumentException - Thrown if u is out of range [0:1].

minimumX

public double minimumX(double tolerance)
                throws FunctionEvaluationException
Returns the minimum x-value of this curve. Uses OneVariableFunction.optimisationBFGS() and pointXOnCurve() to find the minimum x-value for a general 2D curve. Uses end-point p0.x as the initial minimum value.

Parameters:
tolerance - Required tolerance.
Returns:
Minimum x-value of this curve.
Throws:
FunctionEvaluationException - Thrown if an error occurred calling optimisationBFGS().

minimumY

public double minimumY(double tolerance)
                throws FunctionEvaluationException
Returns the minimum y-value of this curve. Uses OneVariableFunction.optimisationBFGS() and pointXOnCurve() to find the minimum y-value for a general 2D curve. Uses end-point p0.y as the initial minimum value.

Parameters:
tolerance - Required tolerance.
Returns:
Minimum y-value of this curve.
Throws:
FunctionEvaluationException - Thrown if an error occurred calling optimisationBFGS().

maximumX

public double maximumX(double tolerance)
                throws FunctionEvaluationException
Returns the maximum x-value of this curve. Uses OneVariableFunction.optimisationBFGS() and pointXOnCurve() to find the minimum x-value for a general 2D curve. Uses end-point p0.x as the initial minimum value.

Parameters:
tolerance - Required tolerance.
Returns:
Minimum x-value of this curve.
Throws:
FunctionEvaluationException - Thrown if an error occurred calling optimisationBFGS().

maximumY

public double maximumY(double tolerance)
                throws FunctionEvaluationException
Returns the minimum y-value of this curve. Uses OneVariableFunction.optimisationBFGS() and pointXOnCurve() to find the minimum y-value for a general 2D curve. Uses end-point p0.y as the initial minimum value.

Parameters:
tolerance - Required tolerance.
Returns:
Minimum y-value of this curve.
Throws:
FunctionEvaluationException - Thrown if an error occurred calling optimisationBFGS().

is2D

public boolean is2D()
Tests whether or not this object is a 2D object; ie true.

Overrides:
is2D in class GeometricObject2D
Returns:
Logical-true.

is3D

public boolean is3D()
Tests whether or not this object is a 3D object; ie false.

Overrides:
is3D in class GeometricObject2D
Returns:
Logical-false.

isPoint

public boolean isPoint()
Tests whether or not this object is a point; ie false.

Specified by:
isPoint in class GeometricObject
Returns:
Logical-false.

isPointSet

public boolean isPointSet()
Tests whether or not this object is a point set; ie false.

Specified by:
isPointSet in class GeometricObject
Returns:
Logical-false.

isCurve

public boolean isCurve()
Tests whether or not this object is a curve; ie true.

Specified by:
isCurve in class GeometricObject
Returns:
Logical-true.

isGrid

public boolean isGrid()
Tests whether or not this object is a grid; ie false.

Specified by:
isGrid in class GeometricObject
Returns:
Logical-false.

isMesh

public boolean isMesh()
Tests whether or not this object is a mesh; ie false.

Specified by:
isMesh in class GeometricObject
Returns:
Logical-false.

isSurface

public boolean isSurface()
Tests whether or not this object is a surface; ie false.

Specified by:
isSurface in class GeometricObject
Returns:
Logical-false.

isShape

public boolean isShape()
Tests whether or not this object is a shape; ie false.

Specified by:
isShape in class GeometricObject
Returns:
Logical-false.

pointOnCurve

public abstract Point2D pointOnCurve(double u,
                                     double tolerance)
                              throws java.lang.IllegalArgumentException
Returns a point on this curve at the specified parametric distance from end-point p0.

Parameters:
u - Parametric variable in range [0:1].
tolerance - Required tolerance.
Returns:
Point at specified parametric distance from p0.
Throws:
java.lang.IllegalArgumentException - Thrown if u is out of range.

pointOnCurve

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

Parameters:
p - Point to test.
tolerance - Required tolerance.
Returns:
Logical-true if p is on this curve, else logicl-false.

pointOnLeft

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

Parameters:
p - Point to test.
tolerance - Required tolerance.
Returns:
Logical-true if p is on the left of this curve, else logicl-false.

pointOnRight

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

Parameters:
p - Point to test.
tolerance - Required tolerance.
Returns:
Logical-true if p is on the right of this curve, else logicl-false.