math.geom2d.polygon
Class LinearCurve2D

java.lang.Object
  extended by math.geom2d.curve.AbstractContinuousCurve2D
      extended by math.geom2d.polygon.LinearCurve2D
All Implemented Interfaces:
java.lang.Cloneable, CirculinearContinuousCurve2D, CirculinearCurve2D, CirculinearShape2D, ContinuousCurve2D, Curve2D, ContinuousOrientedCurve2D, OrientedCurve2D, GeometricObject2D, Shape2D
Direct Known Subclasses:
LinearRing2D, Polyline2D

public abstract class LinearCurve2D
extends AbstractContinuousCurve2D
implements CirculinearContinuousCurve2D

Abstract class that is the base implementation of Polyline2D and LinearRing2D.

Author:
dlegland

Field Summary
 
Fields inherited from interface math.geom2d.Shape2D
ACCURACY
 
Method Summary
 boolean addVertex(Point2D vertex)
          Adds a vertex at the end of this polyline.
 java.awt.geom.GeneralPath asGeneralPath()
          Returns a general path iterator.
 Box2D boundingBox()
          Returns the bounding box of this linear curve.
 CirculinearDomain2D buffer(double dist)
          Computes the buffer of the shape, formed by the set of points located at a distance from the shape that is lower or equal to d.
 void clearVertices()
           
 CurveSet2D<? extends LinearCurve2D> clip(Box2D box)
          Clips the polyline by a box.
 int closestVertexIndex(Point2D point)
          Computes the index of the closest vertex to the input point.
 boolean contains(double x, double y)
          Checks if the shape contains the planar point defined by (x,y).
 boolean contains(Point2D point)
          Checks if the shape contains the given point.
 java.util.Collection<? extends LinearCurve2D> continuousCurves()
          Returns the collection of continuous curves which constitute this curve.
 double curvature(double t)
          Computes the curvature at the given position.
 double distance(double x, double y)
          Returns the distance of the shape to the given point, specified by x and y, or the distance of point to the frontier of the shape in the case of a plain (i.e. fillable) shape.
 double distance(Point2D point)
          Returns the distance of the shape to the given point, or the distance of point to the frontier of the shape in the case of a plain shape.
 void draw(java.awt.Graphics2D g2)
          Draws the curve on the given Graphics2D object.
abstract  LineSegment2D edge(int index)
          Returns the i-th edge of this linear curve.
abstract  int edgeNumber()
          Returns the number of edges of this linear curve.
abstract  java.util.Collection<LineSegment2D> edges()
          Returns a collection of LineSegment2D that represent the individual edges of this linear curve.
 LineSegment2D firstEdge()
           
 Point2D firstPoint()
          Returns the first point of the linear curve.
 double getT0()
          Deprecated. replaced by t0() (since 0.11.1).
 void insertVertex(int index, Point2D vertex)
          Inserts a vertex at a given position in the polyline.
 java.util.Collection<Point2D> intersections(LinearShape2D line)
          Returns the intersection points of the curve with the specified line.
 boolean isBounded()
          Always returns true, because a linear curve is always bounded.
 boolean isEmpty()
          Returns true if the polyline does not contain any point.
 boolean isSingular(double pos)
          Checks if a point is singular.
abstract  LineSegment2D lastEdge()
           
 Vector2D leftTangent(double t)
          Computes the left tangent at the given position.
 double length()
           
 double length(double pos)
           
 CirculinearContinuousCurve2D parallel(double d)
          Creates a new curve, formed by the points with parameterization: p(t) = c(t) + d*n(t)/|n(t)|, with p(t) being a point of the original curve, n(t) the normal of the curve, and |n| being the norm of n.
 double position(double length)
           
 double position(Point2D point)
          Computes the position of the point on the curve.
 double project(Point2D point)
          Returns the position of the closest orthogonal projection of the point on the curve, or of the closest singular point.
 Point2D removeVertex(int index)
          Removes the vertex specified by the index.
 boolean removeVertex(Point2D vertex)
          Removes the first instance of the given vertex from this polyline.
 Vector2D rightTangent(double t)
          Computes the right tangent at the given position.
 void setVertex(int index, Point2D position)
          Changes the position of the i-th vertex.
 double signedDistance(double x, double y)
          The same as distanceSigned(Point2D), but by passing 2 double as arguments.
 double signedDistance(Point2D point)
          Returns the signed distance of the curve to the given point.
 java.util.Collection<Point2D> singularPoints()
          Returns a set of singular points, i. e. which do not locally admit derivative.
 java.util.Collection<? extends LineSegment2D> smoothPieces()
          Returns a set of circulinear elements, which are basis for circulinear curves.
 double t0()
          Returns 0.
 Point2D vertex(int i)
          Returns the i-th vertex of the polyline.
 Point2D[] vertexArray()
          Returns the collection of vertices as an array of Point2D.
 java.util.Iterator<Point2D> vertexIterator()
          Returns an iterator on the collection of points.
 int vertexNumber()
          Returns the number of vertices.
 java.util.Collection<Point2D> vertices()
          Returns the vertices of the polyline.
 
Methods inherited from class math.geom2d.curve.AbstractContinuousCurve2D
asAwtShape, asPolyline, clone, lastPoint
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface math.geom2d.circulinear.CirculinearContinuousCurve2D
reverse, subCurve, transform
 
Methods inherited from interface math.geom2d.domain.ContinuousOrientedCurve2D
transform
 
Methods inherited from interface math.geom2d.curve.ContinuousCurve2D
appendPath, asPolyline, isClosed
 
Methods inherited from interface math.geom2d.domain.OrientedCurve2D
isInside, windingAngle
 
Methods inherited from interface math.geom2d.curve.Curve2D
asAwtShape, clone, getT1, lastPoint, point, t1
 
Methods inherited from interface math.geom2d.GeometricObject2D
almostEquals
 

Method Detail

vertexIterator

public java.util.Iterator<Point2D> vertexIterator()
Returns an iterator on the collection of points.


vertexArray

public Point2D[] vertexArray()
Returns the collection of vertices as an array of Point2D.

Returns:
an array of Point2D

addVertex

public boolean addVertex(Point2D vertex)
Adds a vertex at the end of this polyline.

Returns:
true if the vertex was correctly added
Since:
0.9.3

insertVertex

public void insertVertex(int index,
                         Point2D vertex)
Inserts a vertex at a given position in the polyline.

Since:
0.9.3

removeVertex

public boolean removeVertex(Point2D vertex)
Removes the first instance of the given vertex from this polyline.

Parameters:
vertex - the position of the vertex to remove
Returns:
true if the vertex was actually removed
Since:
0.9.3

removeVertex

public Point2D removeVertex(int index)
Removes the vertex specified by the index.

Parameters:
index - the index of the vertex to remove
Returns:
the position of the vertex removed from the polyline
Since:
0.9.3

setVertex

public void setVertex(int index,
                      Point2D position)
Changes the position of the i-th vertex.

Since:
0.9.3

clearVertices

public void clearVertices()

vertices

public java.util.Collection<Point2D> vertices()
Returns the vertices of the polyline.

Specified by:
vertices in interface Curve2D
Returns:
a collection of Point2D.
See Also:
Curve2D.singularPoints()

vertex

public Point2D vertex(int i)
Returns the i-th vertex of the polyline.

Parameters:
i - index of the vertex, between 0 and the number of vertices

vertexNumber

public int vertexNumber()
Returns the number of vertices.

Returns:
the number of vertices

closestVertexIndex

public int closestVertexIndex(Point2D point)
Computes the index of the closest vertex to the input point.


edge

public abstract LineSegment2D edge(int index)
Returns the i-th edge of this linear curve.


edgeNumber

public abstract int edgeNumber()
Returns the number of edges of this linear curve.


edges

public abstract java.util.Collection<LineSegment2D> edges()
Returns a collection of LineSegment2D that represent the individual edges of this linear curve.

Returns:
the edges of the polyline

firstEdge

public LineSegment2D firstEdge()

lastEdge

public abstract LineSegment2D lastEdge()

length

public double length()
Specified by:
length in interface CirculinearCurve2D
Returns:
the length of the curve

length

public double length(double pos)
Specified by:
length in interface CirculinearCurve2D
Returns:
the length from the beginning to the position given by pos

position

public double position(double length)
Specified by:
position in interface CirculinearCurve2D
Returns:
the position located at a given geodesic distance from the origin

buffer

public CirculinearDomain2D buffer(double dist)
Description copied from interface: CirculinearShape2D
Computes the buffer of the shape, formed by the set of points located at a distance from the shape that is lower or equal to d.

Specified by:
buffer in interface CirculinearShape2D
Parameters:
dist - the maximal distance between a point of the buffer and the shape
Returns:
the buffer of the shape

parallel

public CirculinearContinuousCurve2D parallel(double d)
Description copied from interface: CirculinearCurve2D
Creates a new curve, formed by the points with parameterization: p(t) = c(t) + d*n(t)/|n(t)|, with p(t) being a point of the original curve, n(t) the normal of the curve, and |n| being the norm of n.
In the case of a continuous curve formed by several smooth circulinear elements, the parallels of contiguous elements are joined by a circle arc.

Specified by:
parallel in interface CirculinearContinuousCurve2D
Specified by:
parallel in interface CirculinearCurve2D
Parameters:
d - the distance between the original curve and he parallel curve.
Returns:
the parallel curve

signedDistance

public double signedDistance(Point2D point)
Description copied from interface: OrientedCurve2D
Returns the signed distance of the curve to the given point. The distance is positive if the point lies outside the shape, and negative if the point lies inside the shape. In both cases, absolute value of distance is equals to the distance to the border of the shape.

Specified by:
signedDistance in interface OrientedCurve2D
Parameters:
point - a point of the plane
Returns:
the signed distance to the curve

signedDistance

public double signedDistance(double x,
                             double y)
Description copied from interface: OrientedCurve2D
The same as distanceSigned(Point2D), but by passing 2 double as arguments.

Specified by:
signedDistance in interface OrientedCurve2D
Parameters:
x - x-coord of a point
y - y-coord of a point
Returns:
the signed distance of the point (x,y) to the curve

leftTangent

public Vector2D leftTangent(double t)
Description copied from interface: ContinuousCurve2D
Computes the left tangent at the given position. If the curve is smooth at position t, the result is the same as the tangent computed for the corresponding smooth curve, and is equal to the result of rightTangent(double). If the position t corresponds to a singular point, the tangent of the smooth portion before t is computed.

Specified by:
leftTangent in interface ContinuousCurve2D
Parameters:
t - the position on the curve
Returns:
the left tangent vector at the curve for position t

rightTangent

public Vector2D rightTangent(double t)
Description copied from interface: ContinuousCurve2D
Computes the right tangent at the given position. If the curve is smooth at position t, the result is the same as the tangent computed for the corresponding smooth curve, and is equal to the result of leftTangent(double). If the position t corresponds to a singular point, the tangent of the smooth portion after t is computed.

Specified by:
rightTangent in interface ContinuousCurve2D
Parameters:
t - the position on the curve
Returns:
the right tangent vector at the curve for position t

curvature

public double curvature(double t)
Description copied from interface: ContinuousCurve2D
Computes the curvature at the given position. The curvature is finite for positions t that correspond to smooth parts, and is infinite for singular points.

Specified by:
curvature in interface ContinuousCurve2D
Parameters:
t - the position on the curve
Returns:
the curvature of the curve for position t

smoothPieces

public java.util.Collection<? extends LineSegment2D> smoothPieces()
Description copied from interface: CirculinearContinuousCurve2D
Returns a set of circulinear elements, which are basis for circulinear curves.

Specified by:
smoothPieces in interface CirculinearContinuousCurve2D
Specified by:
smoothPieces in interface ContinuousCurve2D

t0

public double t0()
Returns 0.

Specified by:
t0 in interface Curve2D

getT0

@Deprecated
public double getT0()
Deprecated. replaced by t0() (since 0.11.1).

Specified by:
getT0 in interface Curve2D

firstPoint

public Point2D firstPoint()
Returns the first point of the linear curve.

Specified by:
firstPoint in interface Curve2D
Overrides:
firstPoint in class AbstractContinuousCurve2D
Returns:
the first point of the curve
See Also:
Curve2D.t0(), Curve2D.point(double)

singularPoints

public java.util.Collection<Point2D> singularPoints()
Description copied from interface: Curve2D
Returns a set of singular points, i. e. which do not locally admit derivative.

Specified by:
singularPoints in interface Curve2D
Returns:
a collection of Point2D.
See Also:
Curve2D.vertices()

isSingular

public boolean isSingular(double pos)
Description copied from interface: Curve2D
Checks if a point is singular.

Specified by:
isSingular in interface Curve2D
Parameters:
pos - the position of the point on the curve
Returns:
true if the point at this location is singular

position

public double position(Point2D point)
Description copied from interface: Curve2D
Computes the position of the point on the curve. If the point does not belong to the curve, return Double.NaN. It is complementary to the point(double) method.

Specified by:
position in interface Curve2D
Parameters:
point - a point belonging to the curve
Returns:
the position of the point on the curve
See Also:
Curve2D.point(double)

intersections

public java.util.Collection<Point2D> intersections(LinearShape2D line)
Description copied from interface: Curve2D
Returns the intersection points of the curve with the specified line. The length of the result array is the number of intersection points.

Specified by:
intersections in interface Curve2D

continuousCurves

public java.util.Collection<? extends LinearCurve2D> continuousCurves()
Description copied from interface: Curve2D
Returns the collection of continuous curves which constitute this curve.

Specified by:
continuousCurves in interface CirculinearCurve2D
Specified by:
continuousCurves in interface Curve2D
Overrides:
continuousCurves in class AbstractContinuousCurve2D
Returns:
a collection of continuous curves.

project

public double project(Point2D point)
Description copied from interface: Curve2D
Returns the position of the closest orthogonal projection of the point on the curve, or of the closest singular point. This function should always returns a valid value.

Specified by:
project in interface Curve2D
Parameters:
point - a point to project
Returns:
the position of the closest orthogonal projection

distance

public double distance(double x,
                       double y)
Description copied from interface: Shape2D
Returns the distance of the shape to the given point, specified by x and y, or the distance of point to the frontier of the shape in the case of a plain (i.e. fillable) shape.

Specified by:
distance in interface Shape2D

distance

public double distance(Point2D point)
Description copied from interface: Shape2D
Returns the distance of the shape to the given point, or the distance of point to the frontier of the shape in the case of a plain shape.

Specified by:
distance in interface Shape2D

isEmpty

public boolean isEmpty()
Returns true if the polyline does not contain any point.

Specified by:
isEmpty in interface Shape2D
Returns:
true if the shape does not contain any point.

isBounded

public boolean isBounded()
Always returns true, because a linear curve is always bounded.

Specified by:
isBounded in interface Shape2D

boundingBox

public Box2D boundingBox()
Returns the bounding box of this linear curve.

Specified by:
boundingBox in interface Shape2D
Returns:
the bounding box of the shape.

contains

public boolean contains(double x,
                        double y)
Description copied from interface: Shape2D
Checks if the shape contains the planar point defined by (x,y).

Specified by:
contains in interface Shape2D

contains

public boolean contains(Point2D point)
Description copied from interface: Shape2D
Checks if the shape contains the given point.

Specified by:
contains in interface Shape2D

clip

public CurveSet2D<? extends LinearCurve2D> clip(Box2D box)
Clips the polyline by a box. The result is an instance of CurveSet2D, which contains only instances of Polyline2D. If the polyline is not clipped, the result is an instance of CurveSet2D which contains 0 curves.

Specified by:
clip in interface CirculinearContinuousCurve2D
Specified by:
clip in interface CirculinearCurve2D
Specified by:
clip in interface ContinuousCurve2D
Specified by:
clip in interface Curve2D
Specified by:
clip in interface ContinuousOrientedCurve2D
Specified by:
clip in interface OrientedCurve2D
Specified by:
clip in interface Shape2D
Parameters:
box - the clipping box
Returns:
the clipped shape

asGeneralPath

public java.awt.geom.GeneralPath asGeneralPath()
Returns a general path iterator.


draw

public void draw(java.awt.Graphics2D g2)
Description copied from interface: Curve2D
Draws the curve on the given Graphics2D object.

Specified by:
draw in interface Curve2D
Specified by:
draw in interface Shape2D
Overrides:
draw in class AbstractContinuousCurve2D
Parameters:
g2 - the graphics to draw the curve in