Class Bezier2d

java.lang.Object
org.djutils.draw.curve.Bezier2d
All Implemented Interfaces:
Curve<DirectedPoint2d,Double,Point2d,Flattener2d,PolyLine2d>, Curve2d, Flattener.FlattableCurve<Point2d,Double>
Direct Known Subclasses:
BezierCubic2d

public class Bezier2d extends Object implements Curve2d
Continuous definition of a Bézier curve in 2d. This class is simply a helper class for (and a super of) BezierCubic2d, which uses this class to determine curvature, offset lines, etc.

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:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final double[]
    The x-coordinates of the points of this Bézier.
    protected final double[]
    The y-coordinates of the points of this Bézier.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Bezier2d(double[] x, double[] y)
    Create a Bézier curve of any order.
    Bezier2d(Point2d... points)
    Create a Bézier curve of any order.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    curvature(double t)
    Returns the curvature at the given t value.
    Returns the derivative for a Bézier, which is a Bézier of 1 order lower.
    boolean
     
    double
    Return the length of this Curve.
    getPoint(double t)
    Returns the point at the given fraction of this Curve.
    double
    getX(int i)
    Retrieve the x-coordinate of the i'th point of this Bézier curve.
    double
    getY(int i)
    Retrieve the y-coordinate of the i'th point of this Bézier curve.
    int
     
    int
    Return the number of points (or x-y pairs) that this Bézier curve is based on.
    Flatten a Curve into a PolyLine.
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.djutils.draw.curve.Curve

    getKnots

    Methods inherited from interface org.djutils.draw.curve.Curve2d

    getDirection, getEndDirection, getEndPoint, getStartDirection, getStartPoint
  • Field Details

    • x

      protected final double[] x
      The x-coordinates of the points of this Bézier.
    • y

      protected final double[] y
      The y-coordinates of the points of this Bézier.
  • Constructor Details

    • Bezier2d

      public Bezier2d(Point2d... points)
      Create a Bézier curve of any order.
      Parameters:
      points - Point2d... shape points that define the Bézier curve
      Throws:
      NullPointerException - when points is null, or contains a null value
      IllegalArgumentException - when the length of points is less than 2
    • Bezier2d

      public Bezier2d(double[] x, double[] y)
      Create a Bézier curve of any order.
      Parameters:
      x - the x-coordinates of the points that define the Bézier curve
      y - the y-coordinates of the points that define the Bézier curve
      Throws:
      NullPointerException - when x, or y is null
      IllegalArgumentException - when the length of the x array is not equal to the length of the y array, or less than 2
  • Method Details

    • derivative

      public Bezier2d derivative()
      Returns the derivative for a Bézier, which is a Bézier of 1 order lower.
      Returns:
      derivative Bézier
      Throws:
      IllegalStateException - when the order of this Bezier2d is 1
    • size

      public int size()
      Return the number of points (or x-y pairs) that this Bézier curve is based on.
      Returns:
      the number of points (or x-y pairs) that this Bézier curve is based on
    • getX

      public double getX(int i)
      Retrieve the x-coordinate of the i'th point of this Bézier curve.
      Parameters:
      i - the index
      Returns:
      the x-coordinate of the i'th point of this Bézier curve
      Throws:
      IndexOutOfBoundsException - when i < 0, or i ≥ size()
    • getY

      public double getY(int i)
      Retrieve the y-coordinate of the i'th point of this Bézier curve.
      Parameters:
      i - the index
      Returns:
      the y-coordinate of the i'th point of this Bézier curve
      Throws:
      IndexOutOfBoundsException - when i < 0, or i ≥ size()
    • getPoint

      public Point2d getPoint(double t)
      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:
      t - the fraction
      Returns:
      the point at the given fraction
    • 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
    • curvature

      public double curvature(double t)
      Returns the curvature at the given t value.
      Parameters:
      t - t value, moving from 0 to 1 along the Bézier.
      Returns:
      double curvature at the given t value.
    • 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
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

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