Class Clothoid2d

java.lang.Object
org.djutils.draw.curve.Clothoid2d
All Implemented Interfaces:
Curve<DirectedPoint2d,Double,Point2d,Flattener2d,PolyLine2d>, Curve2d, Flattener.FlattableCurve<Point2d,Double>, OffsetCurve2d

public class Clothoid2d extends Object implements Curve2d, OffsetCurve2d
Continuous definition of a clothoid in 2d. The following definitions are available:
  • A clothoid between two DirectedPoint2ds.
  • A clothoid originating from a DirectedPoint2d with start curvature, end curvature, and length specified.
  • A clothoid originating from a DirectedPoint2d with start curvature, end curvature, and A-value specified.
This class is based on:
  • Dale Connor and Lilia Krivodonova (2014) "Interpolation of two-dimensional curves with Euler spirals", Journal of Computational and Applied Mathematics, Volume 261, 1 May 2014, pp. 320-332.
  • D.J. Waltona and D.S. Meek (2009) "G1 interpolation with a single Cornu spiral segment", Journal of Computational and Applied Mathematics, Volume 223, Issue 1, 1 January 2009, pp. 86-96.

Copyright (c) 2023-2025 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.

Author:
Alexander Verbraeck, Peter Knoppers, Wouter Schakel
See Also:
  • Constructor Details

    • Clothoid2d

      public Clothoid2d(DirectedPoint2d startPoint, DirectedPoint2d endPoint)
      Create clothoid between two directed points. This constructor is based on the procedure in:
      Dale Connor and Lilia Krivodonova (2014) "Interpolation of two-dimensional curves with Euler spirals", Journal of Computational and Applied Mathematics, Volume 261, 1 May 2014, pp. 320-332.
      Which applies the theory proven in:
      D.J. Waltona and D.S. Meek (2009) "G1 interpolation with a single Cornu spiral segment", Journal of Computational and Applied Mathematics, Volume 223, Issue 1, 1 January 2009, pp. 86-96.
      This procedure guarantees that the resulting line has the minimal angle rotation that is required to connect the points. If the points approximate a straight line or circle, with a tolerance of up 1/10th of a degree, those respective lines are created. The numerical approximation of the underlying Fresnel integral is different from the paper. See Clothoid.fresnel().
      Parameters:
      startPoint - start point
      endPoint - end point
      Throws:
      NullPointerException - when startPoint, or endPoint is null
      See Also:
    • Clothoid2d

      public Clothoid2d(DirectedPoint2d startPoint, double a, double startCurvature, double endCurvature)
      Create clothoid from one point based on curvature and A-value.
      Parameters:
      startPoint - start point
      a - A-value
      startCurvature - start curvature
      endCurvature - end curvature
      Throws:
      NullPointerException - when startPoint is null
      IllegalArgumentException - when a ≤ 0.0
  • Method Details

    • withLength

      public static Clothoid2d withLength(DirectedPoint2d startPoint, double length, double startCurvature, double endCurvature)
      Create clothoid from one point based on curvature and length. This method calculates the A-value as sqrt(L/|k2-k1|), where L is the length of the resulting clothoid, and k2 and k1 are the end and start curvature.
      Parameters:
      startPoint - start point.
      length - Length of the resulting clothoid.
      startCurvature - start curvature.
      endCurvature - end curvature
      Returns:
      clothoid based on curvature and length.
      Throws:
      NullPointerException - when startPoint is null
      IllegalArgumentException - when length ≤ 0.0
    • getStartPoint

      public DirectedPoint2d getStartPoint()
      Description copied from interface: Curve
      Start point of this Curve.
      Specified by:
      getStartPoint in interface Curve<DirectedPoint2d,Double,Point2d,Flattener2d,PolyLine2d>
      Specified by:
      getStartPoint in interface Curve2d
      Returns:
      start point of this Curve
    • getEndPoint

      public DirectedPoint2d getEndPoint()
      Description copied from interface: Curve
      End point of this Curve.
      Specified by:
      getEndPoint in interface Curve<DirectedPoint2d,Double,Point2d,Flattener2d,PolyLine2d>
      Specified by:
      getEndPoint in interface Curve2d
      Returns:
      end point of this Curve
    • getStartCurvature

      public double getStartCurvature()
      Start curvature of this Clothoid.
      Returns:
      start curvature of this Clothoid
    • getEndCurvature

      public double getEndCurvature()
      End curvature of this Clothoid.
      Returns:
      end curvature of this Clothoid
    • getStartRadius

      public double getStartRadius()
      Start radius of this Clothoid.
      Returns:
      start radius of this Clothoid
    • getEndRadius

      public double getEndRadius()
      End radius of this Clothoid.
      Returns:
      end radius of this Clothoid
    • getA

      public double getA()
      Return A, the clothoid scaling parameter.
      Returns:
      a, the clothoid scaling parameter.
    • getPoint

      public Point2d getPoint(double fraction)
      Description copied from interface: Curve
      Returns the point at the given fraction of this Curve. The fraction may represent any parameter, such as t in a Bézier curve, s in a Clothoid, or simply the fraction of length.
      Specified by:
      getPoint in interface Curve<DirectedPoint2d,Double,Point2d,Flattener2d,PolyLine2d>
      Specified by:
      getPoint in interface Flattener.FlattableCurve<Point2d,Double>
      Parameters:
      fraction - the fraction
      Returns:
      the point at the given fraction
    • getPoint

      public Point2d getPoint(double fraction, ContinuousPiecewiseLinearFunction of)
      Description copied from interface: OffsetCurve2d
      Returns the point at the given fraction. The fraction may represent any parameter, such as t in a Bézier curve, s in a Clothoid, or simply the fraction of length.
      Specified by:
      getPoint in interface OffsetCurve2d
      Parameters:
      fraction - the fraction
      of - provides fraction-dependent lateral offset to the point
      Returns:
      the point at the given fraction
    • getDirection

      public Double getDirection(double fraction)
      Description copied from interface: Curve
      Returns the direction at the given fraction. The fraction may represent any parameter, such as t in a Bézier curve, s in a Clothoid, or simply the fraction of length. The default implementation performs a numerical approach by looking at the direction between the points at fraction, and a point 1e-6 away.
      Specified by:
      getDirection in interface Curve<DirectedPoint2d,Double,Point2d,Flattener2d,PolyLine2d>
      Specified by:
      getDirection in interface Curve2d
      Specified by:
      getDirection in interface Flattener.FlattableCurve<Point2d,Double>
      Parameters:
      fraction - the fraction
      Returns:
      the direction at the given fraction
    • toPolyLine

      public PolyLine2d toPolyLine(Flattener2d flattener)
      Description copied from interface: Curve
      Flatten a Curve into a PolyLine. Implementations should use the flattener when relevant and possible.
      Specified by:
      toPolyLine in interface Curve<DirectedPoint2d,Double,Point2d,Flattener2d,PolyLine2d>
      Parameters:
      flattener - the flattener
      Returns:
      approximation of this Curve as a PolyLine
    • toPolyLine

      public PolyLine2d toPolyLine(OffsetFlattener2d flattener, ContinuousPiecewiseLinearFunction offsets)
      Description copied from interface: OffsetCurve2d
      Flatten a Curve2d while offsetting with the provided continuous offset into a PolyLine2d. Implementations should use the flattener when relevant and possible.
      Specified by:
      toPolyLine in interface OffsetCurve2d
      Parameters:
      flattener - OffsetFlattener
      offsets - offset data
      Returns:
      approximation of this curve2d with offset as a PolyLine2d
    • getLength

      public double getLength()
      Description copied from interface: Curve
      Return the length of this Curve.
      Specified by:
      getLength in interface Curve<DirectedPoint2d,Double,Point2d,Flattener2d,PolyLine2d>
      Returns:
      length of this Curve
    • getAppliedShape

      public String getAppliedShape()
      Returns whether the shape was applied as a Clothoid, an Arc, or as a Straight, depending on start and end position and direction.
      Returns:
      "Clothoid", "Arc" or "Straight"
    • toString

      public String toString()
      Overrides:
      toString in class Object