math.geom2d.polygon
Class Polyline2D

Package class diagram package Polyline2D
java.lang.Object
  extended by math.geom2d.curve.AbstractContinuousCurve2D
      extended by math.geom2d.polygon.Polyline2D
All Implemented Interfaces:
Serializable, Cloneable, CirculinearContinuousCurve2D, CirculinearCurve2D, CirculinearShape2D, ContinuousCirculinearCurve2D, ContinuousCurve2D, Curve2D, ContinuousOrientedCurve2D, OrientedCurve2D, Shape2D
Direct Known Subclasses:
LinearRing2D, Polyline2D

public class Polyline2D
extends AbstractContinuousCurve2D
implements CirculinearContinuousCurve2D, Cloneable

A polyline is a continuous curve where each piece of the curve is a LineSegment2D.

Author:
dlegland
See Also:
Serialized Form

Field Summary
protected  ArrayList<Point2D> points
           
 
Fields inherited from interface math.geom2d.Shape2D
ACCURACY
 
Constructor Summary
Polyline2D()
           
Polyline2D(Collection<? extends Point2D> points)
           
Polyline2D(double[] xcoords, double[] ycoords)
           
Polyline2D(Point2D initialPoint)
           
Polyline2D(Point2D[] points)
           
 
Method Summary
 void addPoint(Point2D point)
           
 GeneralPath appendPath(GeneralPath path)
          Append the path of the curve to the given path.
 void clearPoints()
          Deprecated. replaced by clearVertices()
 void clearVertices()
           
 CurveSet2D<? extends Polyline2D> clip(Box2D box)
          Clip the polyline by a box.
 Polyline2D clone()
          Overrides Object declaration to ensure Curve2D implementation are cloned as Curve2D.
 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.
static Polyline2D create(Collection<? extends Point2D> points)
          Static factory for creating a new Polyline2D from a collection of points.
static Polyline2D create(Point2D[] points)
          Static factory for creating a new Polyline2D from an array of points.
 boolean equals(Object object)
           
 Box2D getBoundingBox()
          Returns the bounding box of the shape.
 CirculinearDomain2D getBuffer(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.
 Collection<? extends Polyline2D> getContinuousCurves()
          Returns the collection of continuous curves which constitute this curve.
 double getDistance(double x, double y)
          get 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.
 double getDistance(Point2D point)
          get 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.
 LineSegment2D getEdge(int index)
           
 Collection<LineSegment2D> getEdges()
          Returns an array of LineSegment2D.
 LineSegment2D getFirstEdge()
           
 Point2D getFirstPoint()
          Get the first point of the curve.
 GeneralPath getGeneralPath()
          Return a general path iterator.
 Collection<Point2D> getIntersections(LinearShape2D line)
          Returns the intersection points of the curve with the specified line.
 LineSegment2D getLastEdge()
           
 Point2D getLastPoint()
          if polyline is closed, return the first point.
 Vector2D getLeftTangent(double t)
           
 double getLength()
           
 double getLength(double pos)
           
 CirculinearContinuousCurve2D getParallel(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.
In the case of a continuous curve formed by several smooth circulinear elements, the parallels of contiguous elements are joined by a circle arc.
 Point2D getPoint(double t)
          Gets the point from a parametric representation of the curve.
 Point2D[] getPointArray()
          Return the collection of points as an array of Point2D.
 Iterator<Point2D> getPointsIterator()
          Return an iterator on the collection of points.
 double getPosition(double length)
           
 double getPosition(Point2D point)
          Get position of the point on the curve.
 Polyline2D getReverseCurve()
          Returns the polyline with same points considered in reverse order.
 Vector2D getRightTangent(double t)
           
 double getSignedDistance(double x, double y)
          The same as getSignedDistance(Point2D), but by passing 2 double as arguments.
 double getSignedDistance(Point2D point)
          Get the signed distance of the curve to the given point: this distance is positive if the point lies outside the shape, and is negative if the point lies inside the shape.
 Collection<Point2D> getSingularPoints()
          Returns a set of singular points, i.
 Collection<? extends LineSegment2D> getSmoothPieces()
          Returns a set of circulinear elements, which are basis for circulinear curves.
 Polyline2D getSubCurve(double t0, double t1)
          Return an instance of Polyline2D.
 double getT0()
          returns 0.
 double getT1()
          return the number of points in the polyline, minus one.
 Point2D getVertex(int i)
          Returns the i-th vertex of the polyline.
 int getVertexNumber()
          Returns the number of vertices.
 Collection<Point2D> getVertices()
          Returns the vertices of the polyline.
 double getWindingAngle(Point2D point)
          Return the angle portion that the curve turn around the given point.
 boolean isBounded()
          Always returns true, because a polyline is always bounded.
 boolean isClosed()
          return false, as Polyline2D is not closed by definition.
 boolean isEmpty()
          Returns true if the polyline does not contain any point.
 boolean isInside(Point2D pt)
          Returns true if the point is 'inside' the domain bounded by the curve.
 boolean isSingular(double pos)
          Checks if a point is singular.
 double project(Point2D point)
          Returns the position of the closest orthogonal projection of the point on the curve, or of the closest singular point.
 void removePoint(Point2D point)
           
 Polyline2D transform(AffineTransform2D trans)
          Transforms the shape by an affine transform.
 CirculinearContinuousCurve2D transform(CircleInversion2D inv)
          Transforms the shape by a circle inversion.
 
Methods inherited from class math.geom2d.curve.AbstractContinuousCurve2D
draw, getAsAWTShape, getAsPolyline, wrapCurve
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface math.geom2d.curve.ContinuousCurve2D
getAsPolyline
 
Methods inherited from interface math.geom2d.curve.Curve2D
draw, getAsAWTShape
 

Field Detail

points

protected ArrayList<Point2D> points
Constructor Detail

Polyline2D

public Polyline2D()

Polyline2D

public Polyline2D(Point2D initialPoint)

Polyline2D

public Polyline2D(Point2D[] points)

Polyline2D

public Polyline2D(Collection<? extends Point2D> points)

Polyline2D

public Polyline2D(double[] xcoords,
                  double[] ycoords)
Method Detail

create

public static Polyline2D create(Collection<? extends Point2D> points)
Static factory for creating a new Polyline2D from a collection of points.

Since:
0.8.1

create

public static Polyline2D create(Point2D[] points)
Static factory for creating a new Polyline2D from an array of points.

Since:
0.8.1

getPointsIterator

public Iterator<Point2D> getPointsIterator()
Return an iterator on the collection of points.


getPointArray

public Point2D[] getPointArray()
Return the collection of points as an array of Point2D.

Returns:
an array of Point2D

addPoint

public void addPoint(Point2D point)

removePoint

public void removePoint(Point2D point)

clearPoints

@Deprecated
public void clearPoints()
Deprecated. replaced by clearVertices()


clearVertices

public void clearVertices()

getVertices

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


getVertex

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

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

getVertexNumber

public int getVertexNumber()
Returns the number of vertices.

Returns:
the number of vertices

getEdges

public Collection<LineSegment2D> getEdges()
Returns an array of LineSegment2D. The number of edges is the number of vertices minus one.

Returns:
the edges of the polyline

getEdge

public LineSegment2D getEdge(int index)

getFirstEdge

public LineSegment2D getFirstEdge()

getLastEdge

public LineSegment2D getLastEdge()

getLength

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

getLength

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

getPosition

public double getPosition(double length)
Specified by:
getPosition in interface CirculinearCurve2D
Returns:
the position located at distance 'length' from the origin

getBuffer

public CirculinearDomain2D getBuffer(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:
getBuffer in interface CirculinearShape2D
Parameters:
dist - the maximal distance between a point of the buffer and the shape
Returns:
the buffer of the shape

getParallel

public CirculinearContinuousCurve2D getParallel(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:
getParallel in interface CirculinearContinuousCurve2D
Specified by:
getParallel in interface CirculinearCurve2D
Specified by:
getParallel in interface ContinuousCirculinearCurve2D
Parameters:
d - the distance between the original curve and he parallel curve.
Returns:
the parallel curve

transform

public CirculinearContinuousCurve2D transform(CircleInversion2D inv)
Description copied from interface: CirculinearShape2D
Transforms the shape by a circle inversion. The result is still an instance a CirculinearShape2D.

Specified by:
transform in interface CirculinearContinuousCurve2D
Specified by:
transform in interface CirculinearCurve2D
Specified by:
transform in interface CirculinearShape2D
Specified by:
transform in interface ContinuousCirculinearCurve2D
Parameters:
inv - the circle inversion
Returns:
the transformed shape

getLeftTangent

public Vector2D getLeftTangent(double t)
Specified by:
getLeftTangent in interface ContinuousCurve2D

getRightTangent

public Vector2D getRightTangent(double t)
Specified by:
getRightTangent in interface ContinuousCurve2D

getSignedDistance

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

Specified by:
getSignedDistance 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

getSignedDistance

public double getSignedDistance(Point2D point)
Description copied from interface: OrientedCurve2D
Get the signed distance of the curve to the given point: this distance is positive if the point lies outside the shape, and is negative if the point lies inside the shape. In this case, absolute value of distance is equals to the distance to the border of the shape.

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

getWindingAngle

public double getWindingAngle(Point2D point)
Description copied from interface: OrientedCurve2D
Return the angle portion that the curve turn around the given point. Result is a signed angle.

Specified by:
getWindingAngle in interface OrientedCurve2D
Parameters:
point - a point of the plane
Returns:
a signed angle

isInside

public boolean isInside(Point2D pt)
Description copied from interface: OrientedCurve2D
Returns true if the point is 'inside' the domain bounded by the curve.

Specified by:
isInside in interface OrientedCurve2D
Parameters:
pt - a point in the plane
Returns:
true if the point is on the left side of the curve.

isClosed

public boolean isClosed()
return false, as Polyline2D is not closed by definition.

Specified by:
isClosed in interface ContinuousCurve2D

getSmoothPieces

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

Specified by:
getSmoothPieces in interface CirculinearContinuousCurve2D
Specified by:
getSmoothPieces in interface ContinuousCirculinearCurve2D
Specified by:
getSmoothPieces in interface ContinuousCurve2D

getIntersections

public Collection<Point2D> getIntersections(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:
getIntersections in interface Curve2D

getPoint

public Point2D getPoint(double t)
Description copied from interface: Curve2D
Gets the point from a parametric representation of the curve. If the parameter lies outside the definition range, the parameter corresponding to the closest bound is used instead. This method can be used to draw an approximated outline of a curve, by selecting multiple values for t and drawing lines between them.

Specified by:
getPoint in interface Curve2D

getPosition

public double getPosition(Point2D point)
Description copied from interface: Curve2D
Get position of the point on the curve. If the point does not belong to the curve, return Double.NaN.

Specified by:
getPosition in interface Curve2D
Parameters:
point - a point belonging to the curve
Returns:
the position of the point on the curve

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

getT0

public double getT0()
returns 0.

Specified by:
getT0 in interface Curve2D

getT1

public double getT1()
return the number of points in the polyline, minus one.

Specified by:
getT1 in interface Curve2D

getFirstPoint

public Point2D getFirstPoint()
Description copied from interface: Curve2D
Get the first point of the curve. It must returns the same result as getPoint(getT0()).

Specified by:
getFirstPoint in interface Curve2D
Overrides:
getFirstPoint in class AbstractContinuousCurve2D
Returns:
the first point of the curve

getLastPoint

public Point2D getLastPoint()
if polyline is closed, return the first point.

Specified by:
getLastPoint in interface Curve2D
Overrides:
getLastPoint in class AbstractContinuousCurve2D
Returns:
the last point of the curve.

getSingularPoints

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

Specified by:
getSingularPoints in interface Curve2D
Returns:
a collection of Point2D.

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

getReverseCurve

public Polyline2D getReverseCurve()
Returns the polyline with same points considered in reverse order. Reversed polyline keep same references as original polyline.

Specified by:
getReverseCurve in interface CirculinearContinuousCurve2D
Specified by:
getReverseCurve in interface CirculinearCurve2D
Specified by:
getReverseCurve in interface ContinuousCirculinearCurve2D
Specified by:
getReverseCurve in interface ContinuousCurve2D
Specified by:
getReverseCurve in interface Curve2D
Specified by:
getReverseCurve in interface ContinuousOrientedCurve2D
Specified by:
getReverseCurve in interface OrientedCurve2D

getContinuousCurves

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

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

getSubCurve

public Polyline2D getSubCurve(double t0,
                              double t1)
Return an instance of Polyline2D. If t1 is lower than t0, return an instance of Polyline2D with zero points.

Specified by:
getSubCurve in interface CirculinearContinuousCurve2D
Specified by:
getSubCurve in interface CirculinearCurve2D
Specified by:
getSubCurve in interface ContinuousCirculinearCurve2D
Specified by:
getSubCurve in interface ContinuousCurve2D
Specified by:
getSubCurve in interface Curve2D
Specified by:
getSubCurve in interface ContinuousOrientedCurve2D
Parameters:
t0 - position of the start of the sub-curve
t1 - position of the end of the sub-curve
Returns:
the portion of original curve comprised between t0 and t1.

isBounded

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

Specified by:
isBounded 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.

clip

public CurveSet2D<? extends Polyline2D> clip(Box2D box)
Clip the polyline by a box. The result is an instance of CurveSet2D, which contains only instances of Polyline2D. If the ellipse arc 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 ContinuousCirculinearCurve2D
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

getBoundingBox

public Box2D getBoundingBox()
Description copied from interface: Shape2D
Returns the bounding box of the shape.

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

getDistance

public double getDistance(double x,
                          double y)
Description copied from interface: Shape2D
get 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:
getDistance in interface Shape2D

getDistance

public double getDistance(Point2D point)
Description copied from interface: Shape2D
get 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:
getDistance in interface Shape2D

transform

public Polyline2D transform(AffineTransform2D trans)
Description copied from interface: Shape2D
Transforms the shape by an affine transform. Subclasses may override the type of returned shape.

Specified by:
transform in interface ContinuousCurve2D
Specified by:
transform in interface Curve2D
Specified by:
transform in interface ContinuousOrientedCurve2D
Specified by:
transform in interface OrientedCurve2D
Specified by:
transform in interface Shape2D
Parameters:
trans - an affine transform
Returns:
the transformed 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

appendPath

public GeneralPath appendPath(GeneralPath path)
Description copied from interface: ContinuousCurve2D
Append the path of the curve to the given path.

Specified by:
appendPath in interface ContinuousCurve2D
Parameters:
path - a path to modify
Returns:
the modified path

getGeneralPath

public GeneralPath getGeneralPath()
Return a general path iterator.


equals

public boolean equals(Object object)
Overrides:
equals in class Object

clone

public Polyline2D clone()
Description copied from interface: Curve2D
Overrides Object declaration to ensure Curve2D implementation are cloned as Curve2D.

Specified by:
clone in interface Curve2D
Specified by:
clone in class AbstractContinuousCurve2D
Returns:
the cloned curve


Copyright © 2015 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.