math.geom2d.curve
Class PolyCurve2D<T extends ContinuousCurve2D>
- java.lang.Object
-
- math.geom2d.curve.CurveArray2D<T>
-
- math.geom2d.curve.PolyCurve2D<T>
-
- All Implemented Interfaces:
- java.lang.Cloneable, java.lang.Iterable<T>, ContinuousCurve2D, Curve2D, CurveSet2D<T>, GeometricObject2D, Shape2D, ShapeSet2D<T>
- Direct Known Subclasses:
- PolyCubicBezierCurve2D, PolyOrientedCurve2D
public class PolyCurve2D<T extends ContinuousCurve2D> extends CurveArray2D<T> implements ContinuousCurve2D
A PolyCurve2D is a set of piecewise smooth curve arcs, such that the end of a curve is the beginning of the next curve, and such that they do not intersect nor self-intersect.
-
-
Constructor Summary
Constructors Constructor and Description PolyCurve2D()Empty constructor.PolyCurve2D(java.util.Collection<? extends T> curves)Creates a new PolyCurve2D from the specified collection of curves.PolyCurve2D(java.util.Collection<? extends T> curves, boolean closed)Creates a new PolyCurve2D from the specified collection of curves.PolyCurve2D(int n)Constructor that reserves space for the specified number of inner curves.PolyCurve2D(PolyCurve2D<? extends T> polyCurve)PolyCurve2D(T... curves)Creates a new PolyCurve2D from the specified list of curves.PolyCurve2D(T[] curves, boolean closed)Creates a new closed PolyCurve2D from the specified list of curves.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description java.awt.geom.GeneralPathappendPath(java.awt.geom.GeneralPath path)Append the path of the curve to the given path.Polyline2DasPolyline(int n)Converts this PolyCurve2D into a polyline with the given number of edges.CurveSet2D<? extends ContinuousCurve2D>clip(Box2D box)Clip the PolyCurve2D by a box.java.util.Collection<? extends PolyCurve2D<?>>continuousCurves()Returns a collection of PolyCurve2D that contains only this instance.static <T extends ContinuousCurve2D>
PolyCurve2D<T>create(java.util.Collection<T> curves, boolean closed)Static factory for creating a new PolyCurve2D from a collection of curves and a flag indicating if the curve is closed or not.static <T extends ContinuousCurve2D>
PolyCurve2D<T>create(T... curves)Static factory for creating a new PolyCurve2D from an array of curves.static <T extends ContinuousCurve2D>
PolyCurve2D<T>create(T[] curves, boolean closed)Static factory for creating a new PolyCurve2D from an array of curves and a flag indicating if the curve is closed or not.static <T extends ContinuousCurve2D>
PolyCurve2D<T>createClosed(T... curves)Static factory for creating a new closed PolyCurve2D from an array of curves.doublecurvature(double t)Computes the curvature at the given position.voiddraw(java.awt.Graphics2D g2)Draws the curve on the given Graphics2D object.booleanequals(java.lang.Object obj)Returns true if obj is a CurveArray2D with the same number of curves, and such that each curve belongs to both objects.java.awt.geom.GeneralPathgetGeneralPath()booleanisClosed()Returns true if the PolyCurve2D is closed.Vector2DleftTangent(double t)Computes the left tangent at the given position.PolyCurve2D<? extends ContinuousCurve2D>reverse()Returns the reverse curve of this PolyCurve2D.Vector2DrightTangent(double t)Computes the right tangent at the given position.voidsetClosed(boolean b)Toggle the 'closed' flag of this polycurve.java.util.Collection<? extends SmoothCurve2D>smoothPieces()Returns a collection containing only instances of SmoothCurve2D.PolyCurve2D<? extends ContinuousCurve2D>subCurve(double t0, double t1)Returns an instance of PolyCurve2D.PolyCurve2D<? extends ContinuousCurve2D>transform(AffineTransform2D trans)Transforms each smooth piece in this PolyCurve2D and returns a new instance of PolyCurve2D.-
Methods inherited from class math.geom2d.curve.CurveArray2D
add, add, almostEquals, asAwtShape, boundingBox, childCurve, clear, clone, contains, contains, contains, create, curveIndex, curves, distance, distance, firstCurve, firstPoint, get, getT0, getT1, globalPosition, indexOf, intersections, isBounded, isEmpty, isSingular, iterator, lastCurve, lastPoint, localPosition, point, position, project, remove, remove, singularPoints, size, t0, t1, vertices
-
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface math.geom2d.curve.Curve2D
asAwtShape, clone, firstPoint, getT0, getT1, intersections, isSingular, lastPoint, point, position, project, singularPoints, t0, t1, vertices
-
Methods inherited from interface math.geom2d.Shape2D
boundingBox, contains, contains, distance, distance, isBounded, isEmpty
-
Methods inherited from interface math.geom2d.GeometricObject2D
almostEquals
-
-
-
-
Constructor Detail
-
PolyCurve2D
public PolyCurve2D()
Empty constructor.
-
PolyCurve2D
public PolyCurve2D(int n)
Constructor that reserves space for the specified number of inner curves.
-
PolyCurve2D
public PolyCurve2D(T... curves)
Creates a new PolyCurve2D from the specified list of curves.- Parameters:
curves- the curves that constitutes this PolyCurve2D
-
PolyCurve2D
public PolyCurve2D(T[] curves, boolean closed)
Creates a new closed PolyCurve2D from the specified list of curves.- Parameters:
curves- the curves that constitutes this PolyCurve2D
-
PolyCurve2D
public PolyCurve2D(java.util.Collection<? extends T> curves)
Creates a new PolyCurve2D from the specified collection of curves.- Parameters:
curves- the curves that constitutes this PolyCurve2D
-
PolyCurve2D
public PolyCurve2D(java.util.Collection<? extends T> curves, boolean closed)
Creates a new PolyCurve2D from the specified collection of curves.- Parameters:
curves- the curves that constitutes this PolyCurve2D
-
PolyCurve2D
public PolyCurve2D(PolyCurve2D<? extends T> polyCurve)
-
-
Method Detail
-
create
public static <T extends ContinuousCurve2D> PolyCurve2D<T> create(T... curves)
Static factory for creating a new PolyCurve2D from an array of curves.- Since:
- 0.8.1
-
createClosed
public static <T extends ContinuousCurve2D> PolyCurve2D<T> createClosed(T... curves)
Static factory for creating a new closed PolyCurve2D from an array of curves.- Since:
- 0.10.0
-
create
public static <T extends ContinuousCurve2D> PolyCurve2D<T> create(java.util.Collection<T> curves, boolean closed)
Static factory for creating a new PolyCurve2D from a collection of curves and a flag indicating if the curve is closed or not.- Since:
- 0.9.0
-
create
public static <T extends ContinuousCurve2D> PolyCurve2D<T> create(T[] curves, boolean closed)
Static factory for creating a new PolyCurve2D from an array of curves and a flag indicating if the curve is closed or not.- Since:
- 0.9.0
-
setClosed
public void setClosed(boolean b)
Toggle the 'closed' flag of this polycurve.
-
leftTangent
public Vector2D leftTangent(double t)
Description copied from interface:ContinuousCurve2DComputes the left tangent at the given position. If the curve is smooth at positiont, 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 positiontcorresponds to a singular point, the tangent of the smooth portion beforetis computed.- Specified by:
leftTangentin interfaceContinuousCurve2D- 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:ContinuousCurve2DComputes the right tangent at the given position. If the curve is smooth at positiont, 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 positiontcorresponds to a singular point, the tangent of the smooth portion aftertis computed.- Specified by:
rightTangentin interfaceContinuousCurve2D- 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:ContinuousCurve2DComputes the curvature at the given position. The curvature is finite for positionstthat correspond to smooth parts, and is infinite for singular points.- Specified by:
curvaturein interfaceContinuousCurve2D- Parameters:
t- the position on the curve- Returns:
- the curvature of the curve for position t
-
isClosed
public boolean isClosed()
Returns true if the PolyCurve2D is closed.- Specified by:
isClosedin interfaceContinuousCurve2D
-
asPolyline
public Polyline2D asPolyline(int n)
Converts this PolyCurve2D into a polyline with the given number of edges.- Specified by:
asPolylinein interfaceContinuousCurve2D- Parameters:
n- the number of edges of the result polyline- Returns:
- a polyline with
nline segments. - See Also:
Polyline2D
-
smoothPieces
public java.util.Collection<? extends SmoothCurve2D> smoothPieces()
Returns a collection containing only instances of SmoothCurve2D.- Specified by:
smoothPiecesin interfaceContinuousCurve2D- Returns:
- a collection of SmoothCurve2D
-
continuousCurves
public java.util.Collection<? extends PolyCurve2D<?>> continuousCurves()
Returns a collection of PolyCurve2D that contains only this instance.- Specified by:
continuousCurvesin interfaceCurve2D- Overrides:
continuousCurvesin classCurveArray2D<T extends ContinuousCurve2D>- Returns:
- a collection of continuous curves.
-
reverse
public PolyCurve2D<? extends ContinuousCurve2D> reverse()
Returns the reverse curve of this PolyCurve2D.- Specified by:
reversein interfaceContinuousCurve2D- Specified by:
reversein interfaceCurve2D- Overrides:
reversein classCurveArray2D<T extends ContinuousCurve2D>
-
subCurve
public PolyCurve2D<? extends ContinuousCurve2D> subCurve(double t0, double t1)
Returns an instance of PolyCurve2D. If t0>t1 and curve is not closed, return a PolyCurve2D without curves inside.- Specified by:
subCurvein interfaceContinuousCurve2D- Specified by:
subCurvein interfaceCurve2D- Overrides:
subCurvein classCurveArray2D<T extends ContinuousCurve2D>- Parameters:
t0- position of the start of the sub-curvet1- position of the end of the sub-curve- Returns:
- the portion of original curve comprised between t0 and t1.
-
clip
public CurveSet2D<? extends ContinuousCurve2D> clip(Box2D box)
Clip the PolyCurve2D by a box. The result is an instance of CurveSet2D, which contains only instances of ContinuousCurve2D. If the PolyCurve2D is not clipped, the result is an instance of CurveSet2D which contains 0 curves. - Specified by:
clipin interfaceContinuousCurve2D- Specified by:
clipin interfaceCurve2D- Specified by:
clipin interfaceShape2D- Overrides:
clipin classCurveArray2D<T extends ContinuousCurve2D>- Parameters:
box- the clipping box- Returns:
- the clipped shape
-
transform
public PolyCurve2D<? extends ContinuousCurve2D> transform(AffineTransform2D trans)
Transforms each smooth piece in this PolyCurve2D and returns a new instance of PolyCurve2D.- Specified by:
transformin interfaceContinuousCurve2D- Specified by:
transformin interfaceCurve2D- Specified by:
transformin interfaceCurveSet2D<T extends ContinuousCurve2D>- Specified by:
transformin interfaceShape2D- Overrides:
transformin classCurveArray2D<T extends ContinuousCurve2D>- 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:ContinuousCurve2DAppend the path of the curve to the given path.- Specified by:
appendPathin interfaceContinuousCurve2D- Parameters:
path- a path to modify- Returns:
- the modified path
-
getGeneralPath
public java.awt.geom.GeneralPath getGeneralPath()
- Overrides:
getGeneralPathin classCurveArray2D<T extends ContinuousCurve2D>
-
draw
public void draw(java.awt.Graphics2D g2)
Description copied from interface:Curve2DDraws the curve on the given Graphics2D object.- Specified by:
drawin interfaceCurve2D- Specified by:
drawin interfaceShape2D- Overrides:
drawin classCurveArray2D<T extends ContinuousCurve2D>- Parameters:
g2- the graphics to draw the curve in
-
equals
public boolean equals(java.lang.Object obj)
Description copied from class:CurveArray2DReturns true if obj is a CurveArray2D with the same number of curves, and such that each curve belongs to both objects.- Overrides:
equalsin classCurveArray2D<T extends ContinuousCurve2D>
-
-
DMelt 3.0 © DataMelt by jWork.ORG