math.geom2d.line
Class ClosedPolyline2D

java.lang.Object
  extended by math.geom2d.line.Polyline2D
      extended by math.geom2d.line.ClosedPolyline2D
All Implemented Interfaces:
java.awt.Shape, Boundary2D, ContinuousBoundary2D, ContinuousCurve2D, ContinuousOrientedCurve2D, Curve2D, OrientedCurve2D, Shape2D

public class ClosedPolyline2D
extends Polyline2D
implements ContinuousBoundary2D

Extends Polyline2D, by considering the last point is connected to the first one. A ClosedPolyline2D can be used as boundary for Polygons.

Author:
dlegland

Field Summary
 
Fields inherited from class math.geom2d.line.Polyline2D
points
 
Fields inherited from interface math.geom2d.curve.ContinuousCurve2D
CIRCLE, CLOSED_EDGE, LOOP, OPEN_EDGE
 
Fields inherited from interface math.geom2d.Shape2D
ACCURACY, defaultClipWindow, EMPTY_SET
 
Constructor Summary
ClosedPolyline2D()
           
ClosedPolyline2D(java.util.Collection<? extends Point2D> points)
           
ClosedPolyline2D(double[] xcoords, double[] ycoords)
           
ClosedPolyline2D(Point2D initialPoint)
           
ClosedPolyline2D(Point2D[] points)
           
 
Method Summary
 java.awt.geom.GeneralPath appendPath(java.awt.geom.GeneralPath path)
          Append the path of the curve to the given path.
 double getArea()
          Computes area of the polyline, by returning the absolute value of the signed area.
 java.util.Collection<ContinuousBoundary2D> getBoundaryCurves()
          Return the different continuous curves composing the boundary
 java.util.Collection<LineSegment2D> getEdges()
          return an array of LineSegment2D.
 Point2D getFirstPoint()
          return the first point of the polyline.
 java.awt.geom.GeneralPath getGeneralPath()
          Return a general path iterator.
 Point2D getLastPoint()
          return the first point, as this is the same as the last point.
 java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform trans)
          Return pathiterator for this polyline.
 java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform trans, double flatness)
          Return pathiterator for this polyline.
 Point2D getPoint(double t, Point2D point)
          return point from position as double.
 ClosedPolyline2D getReverseCurve()
          Returns the closed polyline with same points taken in reverse order.
 double getSignedArea()
          Computes the signed area of the polyline.
 double getSignedDistance(double x, double y)
          The same as getSignedDistance(Point2D), but by passing 2 double as arguments.
 double getSignedDistance(java.awt.geom.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.
 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.
 double getWindingAngle(java.awt.geom.Point2D point)
          Return the angle portion that the curve turn around the given point.
 boolean isClosed()
          return true, by definition.
 boolean isInside(java.awt.geom.Point2D point)
          return true if the point is 'inside' the domain bounded by the curve.
 ClosedPolyline2D transform(AffineTransform2D trans)
          Return the transformed shape, as a ClosePolyline2D.
 
Methods inherited from class math.geom2d.line.Polyline2D
addPoint, clearPoints, clip, contains, contains, contains, contains, equals, getAsPolyline, getBoundingBox, getBounds, getBounds2D, getContinuousCurves, getDistance, getDistance, getIntersections, getPoint, getPointArray, getPoints, getPointsIterator, getPosition, getSmoothPieces, getVerticesNumber, intersects, intersects, isBounded, project, removePoint
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface math.geom2d.curve.ContinuousOrientedCurve2D
clip
 
Methods inherited from interface math.geom2d.curve.ContinuousCurve2D
getAsPolyline, getSmoothPieces
 
Methods inherited from interface math.geom2d.curve.Curve2D
getContinuousCurves, getIntersections, getPoint, getPosition, project
 
Methods inherited from interface math.geom2d.Shape2D
getBoundingBox, getDistance, getDistance, isBounded
 
Methods inherited from interface java.awt.Shape
contains, contains, contains, contains, getBounds, getBounds2D, intersects, intersects
 

Constructor Detail

ClosedPolyline2D

public ClosedPolyline2D()

ClosedPolyline2D

public ClosedPolyline2D(Point2D initialPoint)

ClosedPolyline2D

public ClosedPolyline2D(Point2D[] points)

ClosedPolyline2D

public ClosedPolyline2D(double[] xcoords,
                        double[] ycoords)

ClosedPolyline2D

public ClosedPolyline2D(java.util.Collection<? extends Point2D> points)
Method Detail

getArea

public double getArea()
Computes area of the polyline, by returning the absolute value of the signed area.


getSignedArea

public double getSignedArea()
Computes the signed area of the polyline. Algorithm is taken from page: http://local.wasp.uwa.edu.au/~pbourke/geometry/polyarea/. Signed are is positive if polyline is oriented counter-clockwise, and negative otherwise. Result is wrong if polyline is self-intersecting.

Returns:
the signed area of the polyline.

getEdges

public java.util.Collection<LineSegment2D> getEdges()
return an array of LineSegment2D. The number of edges is the sazme as the number of vertices.

Overrides:
getEdges in class Polyline2D
Returns:
the edges of the polyline

getBoundaryCurves

public java.util.Collection<ContinuousBoundary2D> getBoundaryCurves()
Description copied from interface: Boundary2D
Return the different continuous curves composing the boundary

Specified by:
getBoundaryCurves in interface Boundary2D

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
Overrides:
getSignedDistance in class Polyline2D
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(java.awt.geom.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
Overrides:
getSignedDistance in class Polyline2D
Parameters:
point - a point of the plane
Returns:
the signed distance to the curve

getWindingAngle

public double getWindingAngle(java.awt.geom.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
Overrides:
getWindingAngle in class Polyline2D
Parameters:
point - a point of the plane
Returns:
a signed angle

isInside

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

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

isClosed

public boolean isClosed()
return true, by definition.

Specified by:
isClosed in interface ContinuousCurve2D
Overrides:
isClosed in class Polyline2D

getPoint

public Point2D getPoint(double t,
                        Point2D point)
return point from position as double. Position t can be from 0 to n, with n equal to the number of vertices of the polyline.

Specified by:
getPoint in interface Curve2D
Overrides:
getPoint in class Polyline2D

getT0

public double getT0()
returns 0.

Specified by:
getT0 in interface Curve2D
Overrides:
getT0 in class Polyline2D

getT1

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

Specified by:
getT1 in interface Curve2D
Overrides:
getT1 in class Polyline2D

getFirstPoint

public Point2D getFirstPoint()
return the first point of the polyline.

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

getLastPoint

public Point2D getLastPoint()
return the first point, as this is the same as the last point.

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

getReverseCurve

public ClosedPolyline2D getReverseCurve()
Returns the closed polyline with same points taken in reverse order. The first points is still the same. Points of reverse curve are the same as the original curve (same pointers).

Specified by:
getReverseCurve in interface Boundary2D
Specified by:
getReverseCurve in interface ContinuousBoundary2D
Specified by:
getReverseCurve in interface ContinuousCurve2D
Specified by:
getReverseCurve in interface ContinuousOrientedCurve2D
Specified by:
getReverseCurve in interface Curve2D
Specified by:
getReverseCurve in interface OrientedCurve2D
Overrides:
getReverseCurve in class Polyline2D

getSubCurve

public Polyline2D getSubCurve(double t0,
                              double t1)
Return an instance of Polyline2D. If t1 is lower than t0, the returned Polyline contains the origin of the curve.

Specified by:
getSubCurve in interface ContinuousCurve2D
Specified by:
getSubCurve in interface ContinuousOrientedCurve2D
Specified by:
getSubCurve in interface Curve2D
Overrides:
getSubCurve in class Polyline2D
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.

transform

public ClosedPolyline2D transform(AffineTransform2D trans)
Return the transformed shape, as a ClosePolyline2D.

Specified by:
transform in interface Boundary2D
Specified by:
transform in interface ContinuousBoundary2D
Specified by:
transform in interface ContinuousCurve2D
Specified by:
transform in interface ContinuousOrientedCurve2D
Specified by:
transform in interface Curve2D
Specified by:
transform in interface OrientedCurve2D
Specified by:
transform in interface Shape2D
Overrides:
transform in class Polyline2D
Parameters:
trans - an affine transform
Returns:
the transformed shape

appendPath

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

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

getGeneralPath

public java.awt.geom.GeneralPath getGeneralPath()
Return a general path iterator.

Overrides:
getGeneralPath in class Polyline2D

getPathIterator

public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform trans)
Return pathiterator for this polyline.

Specified by:
getPathIterator in interface java.awt.Shape
Overrides:
getPathIterator in class Polyline2D

getPathIterator

public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform trans,
                                                  double flatness)
Return pathiterator for this polyline.

Specified by:
getPathIterator in interface java.awt.Shape
Overrides:
getPathIterator in class Polyline2D