Class BezierCubic2d

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

public class BezierCubic2d extends Bezier2d implements Curve2d, OffsetCurve2d, Curvature
Continuous definition of a cubic Bézier curves in 2d. This extends from the more general Bezier as certain methods are applied to calculate e.g. the roots, that are specific to cubic Bézier curves. With such information this class can also specify information to be a Curve.

Copyright (c) 2023-2025 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://djutils.org. The DJUTILS project is distributed under a three-clause BSD-style license, which can be found at https://djutils.org/docs/license.html.

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

    • BezierCubic2d

      public BezierCubic2d(Point2d start, Point2d control1, Point2d control2, Point2d end)
      Create a cubic Bézier curve.
      Parameters:
      start - start point.
      control1 - first intermediate shape point.
      control2 - second intermediate shape point.
      end - end point.
      Throws:
      NullPointerException - when start, control1, control2, or end is null
    • BezierCubic2d

      public BezierCubic2d(Point2d[] points)
      Create a cubic Bézier curve.
      Parameters:
      points - array containing four Point2d objects
      Throws:
      NullPointerException - when points is null, or contains a null value
      IllegalArgumentException - when length of points is not equal to 4
    • BezierCubic2d

      public BezierCubic2d(Ray2d start, Ray2d end)
      Construct a BezierCubic2d from start to end with two generated control points. This constructor creates two control points. The first of these is offset from start in the direction of the start and at a distance from start equal to half the distance from start to end. The second is placed in a similar relation to end.
      Parameters:
      start - the start point and start direction of the Bézier curve
      end - the end point and end direction of the Bézier curve
      Throws:
      NullPointerException - when start, or end is null
      IllegalArgumentException - when start and end are at the same location
    • BezierCubic2d

      public BezierCubic2d(Ray2d start, Ray2d end, double shape)
      Construct a BezierCubic2d from start to end with two generated control points. The control points are in placed along the direction of the start, resp. end points at a distance that depends on the shape parameter.
      Parameters:
      start - the start point and start direction of the Bézier curve
      end - the end point and end direction of the Bézier curve
      shape - 1 = control points at half the distance between start and end, > 1 results in a pointier shape, < 1 results in a flatter shape, value should be above 0 and finite
      Throws:
      NullPointerException - when start, or end is null
      IllegalArgumentException - when start and end are at the same location, shape ≤ 0, shape is NaN, or infinite
    • BezierCubic2d

      public BezierCubic2d(Ray2d start, Ray2d end, double shape, boolean weighted)
      Construct a BezierCubic2d from start to end with two generated control points.
      Parameters:
      start - the start point and start direction of the Bézier curve
      end - the end point and end direction of the Bézier curve
      shape - the shape; higher values put the generated control points further away from end and result in a pointier Bézier curve
      weighted - whether weights will be applied
      Throws:
      NullPointerException - when start, or end is null
      IllegalArgumentException - when start and end are at the same location, shape ≤ 0, shape is NaN, or infinite
  • Method Details

    • 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>
      Overrides:
      getPoint in class Bezier2d
      Parameters:
      t - the fraction
      Returns:
      the point at the given fraction
    • getStartCurvature

      public double getStartCurvature()
      Start curvature of this BezierCubic2d. TODO looks very wrong
      Specified by:
      getStartCurvature in interface Curvature
      Returns:
      start curvature of this BezierCubic2d
    • getEndCurvature

      public double getEndCurvature()
      End curvature of this BezierCubic2d. TODO looks very wrong
      Specified by:
      getEndCurvature in interface Curvature
      Returns:
      end curvature of this BezierCubic2d
    • getT

      public double getT(double position)
      Returns the t value at the provided length along the Bézier curve. This method uses an iterative approach with a precision of 1e-6.
      Specified by:
      getT in interface OffsetCurve2d
      Parameters:
      position - position along the Bézier curve.
      Returns:
      t value at the provided length along the Bézier curve.
    • split

      public org.djutils.draw.curve.BezierCubic2d.SplitBeziers split(double t)
      Splits the Bézier in two Bézier curves of the same order.
      Parameters:
      t - t value along the Bézier curve to apply the split
      Returns:
      the Bézier curve before t, and the Bézier curve after t
      Throws:
      IllegalArgumentException - when t < 0.0, or t > 1.0
    • 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>
      Overrides:
      toPolyLine in class Bezier2d
      Parameters:
      flattener - the flattener
      Returns:
      approximation of this Curve as a PolyLine
    • 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, ContinuousPiecewiseLinearFunction of)
      Description copied from interface: OffsetCurve2d
      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 OffsetCurve2d
      Parameters:
      fraction - the fraction
      of - provides fraction-dependent lateral offset to the curve
      Returns:
      the direction at the given fraction
    • toPolyLine

      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
      of - 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>
      Overrides:
      getLength in class Bezier2d
      Returns:
      length of this Curve
    • toString

      public String toString()
      Overrides:
      toString in class Bezier2d