Class Paths2D

java.lang.Object
org.bzdev.geom.Paths2D

public class Paths2D extends Object
Utility class to create various 2D paths. This class consists of static methods.

The methods named createArc will generate either a circular arc or a combination of a circular arc and a straight-line segment, depending on the arguments. Straight-line segments may appear in a path generated by a createArc method when the arguments delimit the path by providing starting and ending points and the curve's tangents at these points. All of these methods are provided in pairs, with one of the pair containing a final argument whose name is maxDelta. The smaller maxDelta is, the better the approximation to a circular arc will be. The default value of maxDelta is π/9 radians (20 degrees) and the maximum is 2π/3 (120 degrees) for reasons specific to the implementation.

With the default value of maxDelta and a unit circle, the mean of the distance of points on an arc from the arc's center is 1.7×10-8, the standard deviation is 1.2×10-8, and the worst case deviation from 1 is 3.27×-8. The mean value of the curvature differs from the expected value of 1 by -1.288×10-8 and the standard deviation is 1.7×-5. By contrast, for a unit circle created using the class java.awt.geom.Ellipse2D.Double, the mean of the distance of points on an arc from the arc's center is 0.00015, the standard deviation is 0.0001, and the worst case deviation from 1 is 0.00027. The mean value of the curvature for this Ellipse2D case differs from the expected value of 1 by -0.0001 with a standard deviation of 0.0067. For general use in computer graphics, the Ellipse2D class is more than adequate for creating a circle. On the other hand, for some 3D-printing applications, the deviation from the ideal value may be too high. In a physics (classical mechanics) application, the acceleration normal to the path for an object moving along the path is proportional to the curvature, and using the Ellipse2D class would generate an error of just under 1 percent.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
    The default maxdelta value (π/9 radians = 20 degrees).
    static final double
    The constant 2π/3.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Path2D
    createArc(double x1, double y1, double[] tangent, int offset, double x2, double y2)
    Create a circular arc given a starting point, a tangent vector, and a final point.
    static Path2D
    createArc(double x1, double y1, double[] tangent, int offset, double x2, double y2, double maxDelta)
    Create a circular arc given a starting point, a tangent vector, a final point, and an angular limit.
    static Path2D
    createArc(double x1, double y1, double[] tangent1, int offset1, double x2, double y2, double[] tangent2, int offset2)
    Create a path consisting of a circular arc, extended by a straight line segment if needed, with an array representation for tangent vectors.
    static Path2D
    createArc(double x1, double y1, double[] tangent1, int offset1, double x2, double y2, double[] tangent2, int offset2, double maxDelta)
    Create a path consisting of a circular arc, extended by a straight line segment if needed, with an array representation for tangent vectors, and with a maximum angular extend for each segment of the circular arc.
    static Path2D
    createArc(double xc, double yc, double x1, double y1, double theta)
    Create a circular arc given an angular extent
    static Path2D
    createArc(double xc, double yc, double x1, double y1, double theta, double maxDelta)
    Create a circular arc given an angular extent and a limit on the angular extent of cubic Bézier curve segments.
    static Path2D
    createArc(double x1, double y1, double t1x, double t1y, double x2, double y2, double t2x, double t2y)
    Create a path consisting of a circular arc, extended by a straight line segment if needed.
    static Path2D
    createArc(double x1, double y1, double t1x, double t1y, double x2, double y2, double t2x, double t2y, double maxDelta)
    Create a path consisting of a circular arc, extended by a straight line segment if needed, with a bound on the angular extent of each arc segment of the circular arc.
    static Path2D
    createArc(Path2D spath, double radius, boolean counterClockwise, double theta)
    Create an arc specifying a radius, a path whose final point and final tangent match the start of the arc, and the angular extent of the arc.
    static Path2D
    createArc(Path2D spath, double radius, boolean counterClockwise, double theta, double maxDelta)
    Create an arc specifying a radius, a path whose final point and final tangent match the start of the arc, and the angular extent of the arc.
    static Path2D
    createArc(Path2D path, double x, double y)
    Create a circular arc given a starting path and the X and Y coordinates of a final point.
    static Path2D
    createArc(Path2D path, double x, double y, double maxDelta)
    Create a circular arc given a starting path, the X and Y coordinates of a final point, and an angular limit.
    static Path2D
    createArc(Path2D path1, Path2D path2)
    Create a path consisting of a circular arc, extended by a straight line segment if needed, connecting the end of path1 with the start of path2.
    static Path2D
    createArc(Path2D path1, Path2D path2, double maxDelta)
    Create a path consisting of a circular arc, extended by a straight line segment if needed, connecting the end of path1 with the start of path2, and specifying the maximum angular extent of each segment of the circular arc.
    static Path2D
    createArc(Path2D path, Point2D point)
    Create a circular arc given a starting path and a final point.
    static Path2D
    createArc(Path2D path, Point2D point, double theta)
    Create a circular arc given a starting path, a final point, and an angular limit.
    static Path2D
    offsetBy(Path2D path, double dist1, double dist2, boolean close)
    Offset a path in two directions.
    static Path2D
    offsetBy(Path2D path, double dist1, double dist2, boolean close, double maxDelta)
    Offset a path in two directions, specifying a maximum angle between segments for an arc.
    static Path2D
    offsetBy(Path2D path, double dist1, double dist2, double dist3, boolean ccw)
    Offset a path by interpolating the paths provided by offsetBy(Path2D,double,double,boolean) or offsetBy(Path2D,double,double,boolean,double).
    static Path2D
    offsetBy(Path2D path, double dist1, double dist2, double dist3, boolean ccw, double maxDelta)
    Offset a path by interpolating the paths provided by offsetBy(Path2D,double,double,boolean) or offsetBy(Path2D,double,double,boolean,double), specifying a maximum angle between segments for an arc.
    static Path2D
    Remove straight line segments whose length is 0 to single-precision accuracy.
    static Path2D
    Reverse a path.
    static Path2D
    Apply an affine transformation to a path.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • TWO_THIRDS_PI

      public static final double TWO_THIRDS_PI
      The constant 2π/3.
      See Also:
    • DEFAULT_MAX_DELTA

      public static final double DEFAULT_MAX_DELTA
      The default maxdelta value (π/9 radians = 20 degrees).
      See Also:
  • Method Details

    • createArc

      public static Path2D createArc(double xc, double yc, double x1, double y1, double theta) throws IllegalArgumentException
      Create a circular arc given an angular extent
      Parameters:
      xc - the X coordinate of the center of the arc's circle
      yc - the Y coordinate of the center of the arc's circle
      x1 - the X coordinate of a point on the arc
      y1 - the Y coordinate of a point on the arc
      theta - the angular extent of the arc in radians, where positive values represent a rotation from the positive X axis towards the positive Y axis
      Returns:
      the path for the arc
      Throws:
      IllegalArgumentException - an arc cannot be created given the parameters
    • createArc

      public static Path2D createArc(double xc, double yc, double x1, double y1, double theta, double maxDelta) throws IllegalArgumentException
      Create a circular arc given an angular extent and a limit on the angular extent of cubic Bézier curve segments.
      Parameters:
      xc - the X coordinate of the center of the arc's circle
      yc - the Y coordinate of the center of the arc's circle
      x1 - the X coordinate of a point on the arc
      y1 - the Y coordinate of a point on the arc
      theta - the angular extent of the arc in radians, where positive values represent a rotation from the positive X axis towards the positive Y axis
      maxDelta - the maximum angular extent for each cubic Bézier segment making up the arc, with values in the range (0.0, 2π/3]
      Returns:
      the path for the arc
      Throws:
      IllegalArgumentException - an arc cannot be created given the parameters
    • createArc

      public static Path2D createArc(Path2D spath, double radius, boolean counterClockwise, double theta) throws IllegalArgumentException, NullPointerException
      Create an arc specifying a radius, a path whose final point and final tangent match the start of the arc, and the angular extent of the arc.
      Parameters:
      spath - the path before the start of the arc
      radius - the radius of the arc
      counterClockwise - true if the arc turns in the same angular direction as a rotation from the positive X axis to the positive Y axis; false if the arc turns in the same angular direction as a rotation from the positive X axis to the negative Y axis
      theta - the angular extent of the arc (if negative, the arc will form a cusp with the specified path)
      Returns:
      the arc
      Throws:
      IllegalArgumentException - an arc cannot be created given the parameters
      NullPointerException - the path argument was null
    • createArc

      public static Path2D createArc(Path2D spath, double radius, boolean counterClockwise, double theta, double maxDelta) throws IllegalArgumentException, NullPointerException
      Create an arc specifying a radius, a path whose final point and final tangent match the start of the arc, and the angular extent of the arc.
      Parameters:
      spath - the path before the start of the arc
      radius - the radius of the arc
      counterClockwise - true if the arc turns in the same angular direction as a rotation from the positive X axis to the positive Y axis; false if the arc turns in the same angular direction as a rotation from the positive X axis to the negative Y axis
      theta - the angular extent of the arc (if negative, the arc will form a cusp with the specified path)
      maxDelta - the maximum angular extent for each cubic Bézier segment making up the arc, with values in the range (0.0, 2π/3]
      Returns:
      the arc
      Throws:
      IllegalArgumentException - an arc cannot be created given the parameters
      NullPointerException - the path argument was null
    • createArc

      public static Path2D createArc(Path2D path, Point2D point) throws IllegalArgumentException, NullPointerException
      Create a circular arc given a starting path and a final point. The arc starts parallel to the tangent vector and in the tangent vector's direction.
      Parameters:
      path - a path whose current point is the initial point of the arc and whose last tangent vector is the initial tangent vector for the arc
      point - the final point for the arc
      Returns:
      the path for the arc
      Throws:
      IllegalArgumentException - an arc cannot be created given the parameters
      NullPointerException - the path argument was null
    • createArc

      public static Path2D createArc(Path2D path, Point2D point, double theta) throws IllegalArgumentException, NullPointerException
      Create a circular arc given a starting path, a final point, and an angular limit. The arc starts parallel to the tangent vector and in the tangent vector's direction.
      Parameters:
      path - a path whose current point is the initial point of the arc and whose last tangent vector is the initial tangent vector for the arc
      point - the final point for the arc
      theta - the angular limit in radians for each Bézier curve segment making up the arc, measured from the center of the circle the arc follows.
      Returns:
      the path for the arc
      Throws:
      IllegalArgumentException - an arc cannot be created given the parameters
      NullPointerException - the path argument was null
    • createArc

      public static Path2D createArc(Path2D path, double x, double y) throws IllegalArgumentException, NullPointerException
      Create a circular arc given a starting path and the X and Y coordinates of a final point. The arc starts parallel to the tangent vector and in the tangent vector's direction.
      Parameters:
      path - a path whose current point is the initial point of the arc and whose last tangent vector is the initial tangent vector for the arc
      x - X coordinate for the final point for the circular arc
      y - the Y coordinate for final point for the circular arc
      Returns:
      the path for the arc
      Throws:
      IllegalArgumentException - an arc cannot be created given the parameters
      NullPointerException - the path argument was null
    • createArc

      public static Path2D createArc(Path2D path, double x, double y, double maxDelta) throws IllegalArgumentException, NullPointerException
      Create a circular arc given a starting path, the X and Y coordinates of a final point, and an angular limit. The arc starts parallel to the tangent vector and in the tangent vector's direction.
      Parameters:
      path - a path whose current point is the initial point of the arc and whose last tangent vector is the initial tangent vector for the arc
      x - X coordinate for the final point for the circular arc
      y - the Y coordinate for final point for the circular arc
      maxDelta - the angular limit in radians for each Bézier curve segment making up the arc, measured from the center of the circle the arc follows, with values in the range (0.0, 2π/3]
      Returns:
      the path for the arc
      Throws:
      IllegalArgumentException - the path does not have a tangent at the path's end
      NullPointerException - the path argument was null
    • createArc

      public static Path2D createArc(double x1, double y1, double[] tangent, int offset, double x2, double y2) throws IllegalArgumentException, NullPointerException
      Create a circular arc given a starting point, a tangent vector, and a final point. The arc starts parallel to the tangent vector and in the tangent vector's direction.
      Parameters:
      x1 - X coordinate for the starting point for the circular arc
      y1 - the Y coordinate for starting point for the circular arc
      tangent - an array containing the tangent vector
      offset - an offset into the tangent array such that tangent[offset] contains the X coordinate for the tangent vector and tangent[offset+1] contains the Y coordinate for the tangent vector
      x2 - X coordinate for the final point for the circular arc
      y2 - the Y coordinate for final point for the circular arc
      Returns:
      the path for the arc
      Throws:
      IllegalArgumentException - an arc cannot be created given the parameters
      NullPointerException - an array argument was null
    • createArc

      public static Path2D createArc(double x1, double y1, double[] tangent, int offset, double x2, double y2, double maxDelta)
      Create a circular arc given a starting point, a tangent vector, a final point, and an angular limit. The arc starts parallel to the tangent vector and in the tangent vector's direction.
      Parameters:
      x1 - X coordinate for the starting point for the circular arc
      y1 - the Y coordinate for starting point for the circular arc
      tangent - an array containing the tangent vector
      offset - an offset into the tangent array such that tangent[offset] contains the X coordinate for the tangent vector and tangent[offset+1] contains the Y coordinate for the tangent vector
      x2 - X coordinate for the final point for the circular arc
      y2 - the Y coordinate for final point for the circular arc
      maxDelta - the angular limit in radians for each Bézier curve segment making up the arc, measured from the center of the circle the arc follows, with values in the range (0.0, 2π/3]
      Returns:
      the path for the arc
      Throws:
      IllegalArgumentException - an arc cannot be created given the parameters
      NullPointerException - an array argument was null
    • createArc

      public static Path2D createArc(Path2D path1, Path2D path2) throws IllegalArgumentException, NullPointerException
      Create a path consisting of a circular arc, extended by a straight line segment if needed, connecting the end of path1 with the start of path2.

      The initial and final points, and their tangent vectors, must satisfy one the following constraints for an arc to exist:

      • the initial and final points may be identical, in which case the arc will exist but will have a length of zero as it will consist of a single point.
      • If the tangent vectors are parallel, the corresponding line segments must be collinear, and a vector connecting the initial point to the final point must be parallel to the initial point's tangent vector.
      • If the tangent vectors are antiparallel, the corresponding line segments must not be collinear.
      • Otherwise the tangent lines passing through the initial and final points are not parallel and will meet at a vertex v. In this case, the following must be true:
        • for the directed line segments parallel to the tangent vectors at the initial and final points, one segment must point towards the vertex and the other must point away from the vertex.
        • the points on the (extended) arc may include the directed lines starting at v and passing through the initial or final points, and the points between these two directed lines on the side where the angle between them is smallest.
        • the curvature at any point along the extended arc may be any value in either the range [0, ∞) or the range (-∞, 0] but not both.
      Parameters:
      path1 - the preceding path
      path2 - the following path
      Returns:
      the path for the extended arc
      Throws:
      IllegalArgumentException - an arc cannot be created given the parameters
      NullPointerException - path1 or path2 was null
    • createArc

      public static Path2D createArc(Path2D path1, Path2D path2, double maxDelta) throws IllegalArgumentException, NullPointerException
      Create a path consisting of a circular arc, extended by a straight line segment if needed, connecting the end of path1 with the start of path2, and specifying the maximum angular extent of each segment of the circular arc.

      The initial and final points, and their tangent vectors, must satisfy one the following constraints for an arc to exist:

      • the initial and final points may be identical, in which case the arc will exist but will have a length of zero as it will consist of a single point.
      • If the tangent vectors are parallel, the corresponding line segments must be collinear, and a vector connecting the initial point to the final point must be parallel to the initial point's tangent vector.
      • If the tangent vectors are antiparallel, the corresponding line segments must not be collinear.
      • Otherwise the tangent lines passing through the initial and final points are not parallel and will meet at a vertex v. In this case, the following must be true:
        • for the directed line segments parallel to the tangent vectors at the initial and final points, one segment must point towards the vertex and the other must point away from the vertex.
        • the points on the (extended) arc may include the directed lines starting at v and passing through the initial or final points, and the points between these two directed lines on the side where the angle between them is smallest.
        • the curvature at any point along the extended arc may be any value in either the range [0, ∞) or the range (-∞, 0] but not both.
      Parameters:
      path1 - the preceding path
      path2 - the following path
      maxDelta - the angular limit in radians for each Bézier curve segment in the arc, measured from the center of the circle the arc follows, with values in the range (0.0, 2π/3]
      Returns:
      the path for the extended arc
      Throws:
      IllegalArgumentException - an arc cannot be created given the parameters
      NullPointerException - path1 or path2 was null
    • createArc

      public static Path2D createArc(double x1, double y1, double[] tangent1, int offset1, double x2, double y2, double[] tangent2, int offset2) throws IllegalArgumentException, NullPointerException
      Create a path consisting of a circular arc, extended by a straight line segment if needed, with an array representation for tangent vectors. Both tangent vector's point in the direction of an increasing path parameter with the initial point having a path parameter of 0.0.

      The initial and final points, and their tangent vectors, must satisfy one the following constraints for an arc to exist:

      • the initial and final points may be identical, in which case the arc will exist but will have a length of zero as it will consist of a single point.
      • If the tangent vectors are parallel, the corresponding line segments must be collinear, and a vector connecting the initial point to the final point must be parallel to the initial point's tangent vector.
      • If the tangent vectors are antiparallel, the corresponding line segments must not be collinear.
      • Otherwise the tangent lines passing through the initial and final points are not parallel and will meet at a vertex v. In this case, the following must be true:
        • for the directed line segments parallel to the tangent vectors at the initial and final points, one segment must point towards the vertex and the other must point away from the vertex.
        • the points on the (extended) arc may include the directed lines starting at v and passing through the initial or final points, and the points between these two directed lines on the side where the angle between them is smallest.
        • the curvature at any point along the extended arc may be any value in either the range [0, ∞) or the range (-∞, 0] but not both.
      If the arc does not exist, an exception will be thrown.
      Parameters:
      x1 - the X coordinate of the extended arc's initial point
      y1 - the Y coordinate of the extended arc's initial point
      tangent1 - an array containing the initial point's tangent vector
      offset1 - an offset into tangent1 such that tangent1[offset1] contains the X component of the tangent vector and tangent1[offset1+1] contains the X component of the initial point's tangent vector
      x2 - the X coordinate of the extended arc's final point
      y2 - the Y coordinate of the extended arc's final point
      tangent2 - an array containing the final point's tangent vector
      offset2 - an offset into tangent1 such that tangent2[offset2] contains the X component of the tangent vector and tangent2[offset2+1] contains the Y component of the final point's tangent vector
      Returns:
      the path for the extended arc
      Throws:
      IllegalArgumentException - an arc cannot be created given the parameters
      NullPointerException - an array argument was null
    • createArc

      public static Path2D createArc(double x1, double y1, double[] tangent1, int offset1, double x2, double y2, double[] tangent2, int offset2, double maxDelta) throws IllegalArgumentException, NullPointerException
      Create a path consisting of a circular arc, extended by a straight line segment if needed, with an array representation for tangent vectors, and with a maximum angular extend for each segment of the circular arc. Both tangent vector's point in the direction of an increasing path parameter with the initial point having a path parameter of 0.0.

      The initial and final points, and their tangent vectors, must satisfy one the following constraints for an arc to exist:

      • the initial and final points may be identical, in which case the arc will exist but will have a length of zero as it will consist of a single point.
      • If the tangent vectors are parallel, the corresponding line segments must be collinear, and a vector connecting the initial point to the final point must be parallel to the initial point's tangent vector.
      • If the tangent vectors are antiparallel, the corresponding line segments must not be collinear.
      • Otherwise the tangent lines passing through the initial and final points are not parallel and will meet at a vertex v. In this case, the following must be true:
        • for the directed line segments parallel to the tangent vectors at the initial and final points, one segment must point towards the vertex and the other must point away from the vertex.
        • the points on the (extended) arc may include the directed lines starting at v and passing through the initial or final points, and the points between these two directed lines on the side where the angle between them is smallest.
        • the curvature at any point along the extended arc may be any value in either the range [0, ∞) or the range (-∞, 0] but not both.
      If the arc does not exist, an exception will be thrown.
      Parameters:
      x1 - the X coordinate of the extended arc's initial point
      y1 - the Y coordinate of the extended arc's initial point
      tangent1 - an array containing the initial point's tangent vector
      offset1 - an offset into tangent1 such that tangent1[offset1] contains the X component of the tangent vector and tangent1[offset1+1] contains the X component of the initial point's tangent vector
      x2 - the X coordinate of the extended arc's final point
      y2 - the Y coordinate of the extended arc's final point
      tangent2 - an array containing the final point's tangent vector
      offset2 - an offset into tangent1 such that tangent2[offset2] contains the X component of the tangent vector and tangent2[offset2+1] contains the Y component of the final point's tangent vector
      maxDelta - the angular limit in radians for each Bézier curve segment in the arc, measured from the center of the circle the arc follows, with values in the range (0.0, 2π/3]
      Returns:
      the path for the extended arc
      Throws:
      IllegalArgumentException - an arc cannot be created given the parameters
      NullPointerException - an array argument was null
    • createArc

      public static Path2D createArc(double x1, double y1, double t1x, double t1y, double x2, double y2, double t2x, double t2y) throws IllegalArgumentException
      Create a path consisting of a circular arc, extended by a straight line segment if needed. Both tangent vector's point in the direction of an increasing path parameter with the initial point having a path parameter of 0.0.

      The initial and final points, and their tangent vectors, must satisfy one the following constraints for an arc to exist:

      • the initial and final points may be identical, in which case the arc will exist but will have a length of zero as it will consist of a single point.
      • If the tangent vectors are parallel, the corresponding line segments must be collinear, and a vector connecting the initial point to the final point must be parallel to the initial point's tangent vector.
      • If the tangent vectors are antiparallel, the corresponding line segments must not be collinear.
      • Otherwise the tangent lines passing through the initial and final points are not parallel and will meet at a vertex v. In this case, the following must be true:
        • for the directed line segments parallel to the tangent vectors at the initial and final points, one segment must point towards the vertex and the other must point away from the vertex.
        • the points on the (extended) arc may include the directed lines starting at v and passing through the initial or final points, and the points between these two directed lines on the side where the angle between them is smallest.
        • the curvature at any point along the extended arc may be any value in either the range [0, ∞) or the range (-∞, 0] but not both.
      If the arc does not exist, an exception will be thrown.
      Parameters:
      x1 - the X coordinate of the extended arc's initial point
      y1 - the Y coordinate of the extended arc's initial point
      t1x - the X coordinate of the initial point's tangent vector
      t1y - the Y coordinate of the initial point's tangent vector
      x2 - the X coordinate of the extended arc's final point
      y2 - the Y coordinate of the extended arc's final point
      t2x - the X coordinate of the final point's tangent vector
      t2y - the Y coordinate of the final point's tangent vector
      Returns:
      the path for the extended arc
      Throws:
      IllegalArgumentException - an arc cannot be created given the parameters
    • createArc

      public static Path2D createArc(double x1, double y1, double t1x, double t1y, double x2, double y2, double t2x, double t2y, double maxDelta) throws IllegalArgumentException
      Create a path consisting of a circular arc, extended by a straight line segment if needed, with a bound on the angular extent of each arc segment of the circular arc. Both tangent vector's point in the direction of an increasing path parameter with the initial point having a path parameter of 0.0.

      The initial and final points, and their tangent vectors, must satisfy one the following constraints for an arc to exist:

      • the initial and final points may be identical, in which case the arc will exist but will have a length of zero as it will consist of a single point.
      • If the tangent vectors are parallel, the corresponding line segments must be collinear, and a vector connecting the initial point to the final point must be parallel to the initial point's tangent vector.
      • If the tangent vectors are antiparallel, the corresponding line segments must not be collinear.
      • Otherwise the tangent lines passing through the initial and final points are not parallel and will meet at a vertex v. In this case, the following must be true:
        • for the directed line segments parallel to the tangent vectors at the initial and final points, one segment must point towards the vertex and the other must point away from the vertex.
        • the points on the (extended) arc may include the directed lines starting at v and passing through the initial or final points, and the points between these two directed lines on the side where the angle between them is smallest.
        • the curvature at any point along the extended arc may be any value in either the range [0, ∞) or the range (-∞, 0] but not both.
      If the arc does not exist, an exception will be thrown.
      Parameters:
      x1 - the X coordinate of the extended arc's initial point
      y1 - the Y coordinate of the extended arc's initial point
      t1x - the X coordinate of the initial point's tangent vector
      t1y - the Y coordinate of the initial point's tangent vector
      x2 - the X coordinate of the extended arc's final point
      y2 - the Y coordinate of the extended arc's final point
      t2x - the X coordinate of the final point's tangent vector
      t2y - the Y coordinate of the final point's tangent vector
      maxDelta - the angular limit in radians for each Bézier curve segment in the arc, measured from the center of the circle the arc follows, with values in the range (0.0, 2π/3]
      Returns:
      the path for the extended arc
      Throws:
      IllegalArgumentException - an arc cannot be created given the parameters
    • transformPath

      public static Path2D transformPath(Path2D path, AffineTransform at)
      Apply an affine transformation to a path.
      Parameters:
      path - the path to transform
      at - the affine transform to apply to a path; null for the identity transformation
      Returns:
      the transformed path
    • reverse

      public static Path2D reverse(Path2D path) throws IllegalArgumentException
      Reverse a path. For a path to be reversible, each PathIterator.SEG_CLOSE segment that does not end a path must be followed by a PathIterator.SEG_MOVETO segment.

      Reversing a path can be useful when a series of closed paths will be appended to represent a shape and the winding rule PathIterator.WIND_NON_ZERO is used to determine the inside and outside boundaries of the shape.

      Parameters:
      path - the path to reverse
      Returns:
      the reversed path
      Throws:
      IllegalArgumentException - the path cannot be reversed
    • offsetBy

      public static Path2D offsetBy(Path2D path, double dist1, double dist2, boolean close)
      Offset a path in two directions. Offsetting a path refers to the creation of a parallel path such that the distance along the normal to one path to the corresponding point on the other pass is constant. This relationship is bidirectional. Two parallel paths will be created such that one is offset from the other, and an argument determines if these paths are connected to each other at their ends to form a closed path. Both will be offset from the original path at most points with vertices at which the path is not smooth being the main exception. These paths will be on opposite sides of the original path. The object returned will be a single path. If not explicitly closed, this path will contain two disjoint subpaths. If two separate paths are desired, the method PathSplitter.split(Path2D) can be used to provide each subpath as a separate path.

      When the original path is not a closed path and a closed path is requested, the path created will be a closed path oriented counterclockwise: traversing one around this path will result in its tangent rotating a total of 360 degrees counterclockwise. When the original path is not closed and the value of 'close' is false, the second segment of the resulting path will be offset in the direction of the normal vector (the direction of a vector rotated 90 degrees counterclockwise from the tangent), and the first segment will be on the opposite side of the original curve. When the original path is closed, two paths will be created. The outer of these two paths will have a counterclockwise orientation and the inner will have a clockwise orientation.

      An offset for a Bezier path cannot in general be represented by a Bezier path, although it can be approximated by a Bezier path. The algorithm used works best when each segment of the original path has roughly constant curvature, such as when a path consists of straight-line segments and segments created with the createArc methods defined in this class.

      The arguments dist1 and dist2 must both be non-negative. If the original path is closed, the offsetted paths will also be closed. Otherwise the resulting curve will be closed if the close argument has the value true. The path will be explicitly closed in this case by connecting the two paths at their endpoints. When the close argument has the value false and the original path is not closed, the returned path will have two separate components. If dist1 or dist2 is zero, the corresponding path will be identical to the original path.

      Note: of the two subpaths, the clockwise one is always the first so that when 'close' is true, the orientation of the path will be determined by the right-hand rule.

      Parameters:
      path - the original path
      dist1 - the distance from the path in the counterclockwise direction
      dist2 - the distance from the path in the clockwise direction
      close - true if the path returned must be a closed path; false otherwise (a value of true will result in the path specified by dist2 being reversed regardless of whether the original path is closed)
      Returns:
      the new path.
      Throws:
      IllegalArgumentException - dist1 or dist2 was negative or the path was null
    • offsetBy

      public static Path2D offsetBy(Path2D path, double dist1, double dist2, boolean close, double maxDelta)
      Offset a path in two directions, specifying a maximum angle between segments for an arc. Offsetting a path refers to the creation of a parallel path such that the distance along the normal to one path to the corresponding point on the other pass is constant. This relationship is bidirectional. Two parallel paths will be created such that one is offset from the other, and an argument determines if these paths are connected to each other at their ends to form a closed path. Both will be offset from the original path at most points with vertices at which the path is not smooth being the main exception. These paths will be on opposite sides of the original path. The object returned will be a single path. If not explicitly closed, this path will contain two disjoint subpaths. If two separate paths are desired, the method PathSplitter.split(Path2D) can be used to provide each subpath as a separate path.

      When the original path is not a closed path and a closed path is requested, the path created will be a closed path oriented counterclockwise: traversing one around this path will result in its tangent rotating a total of 360 degrees counterclockwise. When the original path is not closed and the value of 'close' is false, the second segment of the resulting path will be offset in the direction of the normal vector (the direction of a vector rotated 90 degrees counterclockwise from the tangent), and the second segment will be on the opposite side of the original curve. When the original path is closed, two paths will be created. The outer of these two paths will have a counterclockwise orientation and the inner will have a clockwise orientation.

      An offset for a Bezier path cannot in general be represented by a Bezier path, although it can be approximated by a Bezier path. The algorithm used works best when each segment of the original path has roughly constant curvature, such as when a path consists of straight-line segments and segments created with the createArc methods defined in this class.

      The arguments dist1 and dist2 must both be non-negative. If the original path is closed, the offsetted paths will also be closed. Otherwise the resulting curve will be closed if the close argument has the value true. The path will be explicitly closed in this case by connecting the two paths at their endpoints. When the close argument has the value false and the original path is not closed, the returned path will have two separate components. If dist1 or dist2 is zero, the corresponding path will be identical to the original path.

      Note: of the two subpaths, the clockwise one is always the first so that when 'close' is true, the orientation of the path will be determined by the right-hand rule.

      Parameters:
      path - the original path
      dist1 - the distance from the path in the counterclockwise direction
      dist2 - the distance from the path in the clockwise direction
      close - true if the path returned must be a closed path; false otherwise (a value of true will result in the path specified by dist2 being reversed regardless of whether the original path is closed)
      maxDelta - the maximum angle in radians for each segment of an arc, with values in the range (0.0, 2π/3]
      Returns:
      the new path.
      Throws:
      IllegalArgumentException - dist1 or dist2 was negative or the path was null
    • offsetBy

      public static Path2D offsetBy(Path2D path, double dist1, double dist2, double dist3, boolean ccw)
      Offset a path by interpolating the paths provided by offsetBy(Path2D,double,double,boolean) or offsetBy(Path2D,double,double,boolean,double). Offsetting a path refers to the creation of a parallel path such that the distance along the normal to one path to the corresponding point on the other pass is constant. An offset for a Bezier path cannot in general be represented by a Bezier path, although it can be approximated by a Bezier path. The method offsetBy(Path2D,double,double,boolean) creates an approximation to two offset Bezier paths, each one on the opposite side of the original (or base) path than the other. This method uses these two paths and interpolates them to create a single path between the two.

      The arguments dist1 and dist2 must both be non-negative. If the original path is closed the offsetted paths will also be closed. Otherwise the resulting curve will be closed if the close argument has the value true. The path will be explicitly closed in this case by connecting the two paths at their endpoints. When the close argument has the value false and the original path is not closed, the returned path will have two separate components.

      The argument dist3 provides the nominal distance from the original or base path to the curve. The curve created will be a smooth curve regardless of whether or not the base curve is smooth, Kinks in the base curve will be smoothed out with circular arcs. The center of these circular arcs will be a point on the curves associated with the parameters dist1 and dist2, only one of which will not be smooth at some value of the path parameter.

      Parameters:
      path - the path to offset.
      dist1 - the distance from the path in the counterclockwise direction
      dist2 - the distance from the path in the clockwise direction
      dist3 - the distance from the path (when ccw is true, dist3∈[0, dist1]; otherwise dist2∈[0,dist2])
      ccw - true if dist3 is measured in the counterclockwise direction; false if it is measured in the clockwise direction.
      Returns:
      the new path.
      Throws:
      IllegalArgumentException - dist1 or dist2 was negative or the path was null
    • offsetBy

      public static Path2D offsetBy(Path2D path, double dist1, double dist2, double dist3, boolean ccw, double maxDelta)
      Offset a path by interpolating the paths provided by offsetBy(Path2D,double,double,boolean) or offsetBy(Path2D,double,double,boolean,double), specifying a maximum angle between segments for an arc. Offsetting a path refers to the creation of a parallel path such that the distance along the normal to one path to the corresponding point on the other pass is constant. An offset for a Bezier path cannot in general be represented by a Bezier path, although it can be approximated by a Bezier path. The method offsetBy(Path2D,double,double,boolean) creates an approximation to two offset Bezier paths, each one on the opposite side of the original (or base) path than the other. This method uses these two paths and interpolates them to create a single path between the two.

      The arguments dist1 and dist2 must both be non-negative. If the original path is closed the offsetted paths will also be closed. Otherwise the resulting curve will be closed if the close argument has the value true. The path will be explicitly closed in this case by connecting the two paths at their endpoints. When the close argument has the value false and the original path is not closed, the returned path will have two separate components.

      The argument dist3 provides the nominal distance from the original or base path to the curve. The curve created will be a smooth curve regardless of whether or not the base curve is smooth, Kinks in the base curve will be smoothed out with circular arcs. The center of these circular arcs will be a point on the curves associated with the parameters dist1 and dist2, only one of which will not be smooth at some value of the path parameter.

      Parameters:
      path - the path to offset.
      dist1 - the distance from the path in the counterclockwise direction
      dist2 - the distance from the path in the clockwise direction
      dist3 - the distance from the path (when ccw is true, dist3∈[0, dist1]; otherwise dist2∈[0,dist2])
      ccw - true if dist3 is measured in the counterclockwise direction; false if it is measured in the clockwise direction.
      maxDelta - the maximum angle in radians for each segment of an arc, with values in the range (0.0, 2π/3]
      Returns:
      the new path.
      Throws:
      IllegalArgumentException - dist1 or dist2 was negative or the path was null
    • pruneShortLineSegments

      public static Path2D pruneShortLineSegments(Path2D path)
      Remove straight line segments whose length is 0 to single-precision accuracy.

      This method is provided to eliminate extremely short line segments that might be added inadvertently such as when one path is appended to the other and where the end of the first path and the start of the next path differ by a very small amount due to round-off errors. The BezierGrid class in particular will fail to produce a boundary if adjacent grid points are identical to within single-precision accuracy, and a Path2D is an argument for the constructor BezierGrid(Path2D,Point3DMapper,int,boolean). While such short segments can be eliminated as a path is generated, it may be easier to fix it up afterwards.

      Parameters:
      path - the initial path
      Returns:
      the modified path if changed; otherwise the initial path