Package org.djutils.draw.curve
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
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:
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionBezierCubic2d(Ray2d start, Ray2d end) Construct a BezierCubic2d fromstarttoendwith two generated control points.BezierCubic2d(Ray2d start, Ray2d end, double shape) Construct a BezierCubic2d fromstarttoendwith two generated control points.BezierCubic2d(Ray2d start, Ray2d end, double shape, boolean weighted) Construct a BezierCubic2d from start to end with two generated control points.BezierCubic2d(Point2d[] points) Create a cubic Bézier curve.BezierCubic2d(Point2d start, Point2d control1, Point2d control2, Point2d end) Create a cubic Bézier curve. -
Method Summary
Modifier and TypeMethodDescriptiondoublegetDirection(double fraction, ContinuousPiecewiseLinearFunction of) Returns the direction at the given fraction.doubleEnd curvature of this BezierCubic2d.doubleReturn the length of this Curve.getPoint(double t) Returns the point at the given fraction of this Curve.getPoint(double fraction, ContinuousPiecewiseLinearFunction of) Returns the point at the given fraction.doubleStart curvature of this BezierCubic2d.doublegetT(double position) Returns the t value at the provided length along the Bézier curve.org.djutils.draw.curve.BezierCubic2d.SplitBezierssplit(double t) Splits the Bézier in two Bézier curves of the same order.toPolyLine(Flattener2d flattener) Flatten a Curve into a PolyLine.toPolyLine(OffsetFlattener2d flattener, ContinuousPiecewiseLinearFunction of) Flatten a Curve2d while offsetting with the provided continuous offset into a PolyLine2d.toString()Methods inherited from class org.djutils.draw.curve.Bezier2d
curvature, derivative, equals, getX, getY, hashCode, sizeMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.djutils.draw.curve.Curvature
getEndRadius, getStartRadiusMethods inherited from interface org.djutils.draw.curve.Curve2d
getDirection, getEndDirection, getEndPoint, getStartDirection, getStartPoint
-
Constructor Details
-
BezierCubic2d
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- whenstart,control1,control2, orendisnull
-
BezierCubic2d
Create a cubic Bézier curve.- Parameters:
points- array containing fourPoint2dobjects- Throws:
NullPointerException- whenpointsisnull, or contains anullvalueIllegalArgumentException- when length ofpointsis not equal to4
-
BezierCubic2d
Construct a BezierCubic2d fromstarttoendwith two generated control points. This constructor creates two control points. The first of these is offset fromstartin the direction of thestartand at a distance fromstartequal to half the distance fromstarttoend. The second is placed in a similar relation toend.- Parameters:
start- the start point and start direction of the Bézier curveend- the end point and end direction of the Bézier curve- Throws:
NullPointerException- whenstart, orendisnullIllegalArgumentException- whenstartandendare at the same location
-
BezierCubic2d
Construct a BezierCubic2d fromstarttoendwith two generated control points. The control points are in placed along the direction of thestart, resp.endpoints at a distance that depends on theshapeparameter.- Parameters:
start- the start point and start direction of the Bézier curveend- the end point and end direction of the Bézier curveshape- 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- whenstart, orendisnullIllegalArgumentException- whenstartandendare at the same location,shape ≤ 0,shapeisNaN, or infinite
-
BezierCubic2d
Construct a BezierCubic2d from start to end with two generated control points.- Parameters:
start- the start point and start direction of the Bézier curveend- the end point and end direction of the Bézier curveshape- the shape; higher values put the generated control points further away from end and result in a pointier Bézier curveweighted- whether weights will be applied- Throws:
NullPointerException- whenstart, orendisnullIllegalArgumentException- whenstartandendare at the same location,shape ≤ 0,shapeisNaN, or infinite
-
-
Method Details
-
getPoint
Description copied from interface:CurveReturns 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:
getPointin interfaceCurve<DirectedPoint2d,Double, Point2d, Flattener2d, PolyLine2d> - Specified by:
getPointin interfaceFlattener.FlattableCurve<Point2d,Double> - Overrides:
getPointin classBezier2d- Parameters:
t- the fraction- Returns:
- the point at the given
fraction
-
getStartCurvature
public double getStartCurvature()Start curvature of this BezierCubic2d.- Specified by:
getStartCurvaturein interfaceCurvature- Returns:
- start curvature of this BezierCubic2d
-
getEndCurvature
public double getEndCurvature()End curvature of this BezierCubic2d.- Specified by:
getEndCurvaturein interfaceCurvature- 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:
getTin interfaceOffsetCurve2d- 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- whent < 0.0, ort > 1.0
-
toPolyLine
Description copied from interface:CurveFlatten a Curve into a PolyLine. Implementations should use the flattener when relevant and possible.- Specified by:
toPolyLinein interfaceCurve<DirectedPoint2d,Double, Point2d, Flattener2d, PolyLine2d> - Overrides:
toPolyLinein classBezier2d- Parameters:
flattener- the flattener- Returns:
- approximation of this
Curveas aPolyLine
-
getPoint
Description copied from interface:OffsetCurve2dReturns 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:
getPointin interfaceOffsetCurve2d- Parameters:
fraction- the fractionof- provides fraction-dependent lateral offset to the point- Returns:
- the point at the given
fraction
-
getDirection
Description copied from interface:OffsetCurve2dReturns 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:
getDirectionin interfaceOffsetCurve2d- Parameters:
fraction- the fractionof- provides fraction-dependent lateral offset to the curve- Returns:
- the direction at the given
fraction
-
toPolyLine
Description copied from interface:OffsetCurve2dFlatten a Curve2d while offsetting with the provided continuous offset into a PolyLine2d. Implementations should use the flattener when relevant and possible.- Specified by:
toPolyLinein interfaceOffsetCurve2d- Parameters:
flattener- OffsetFlattenerof- offset data- Returns:
- approximation of this
curve2dwith offset as aPolyLine2d
-
getLength
public double getLength()Description copied from interface:CurveReturn the length of this Curve.- Specified by:
getLengthin interfaceCurve<DirectedPoint2d,Double, Point2d, Flattener2d, PolyLine2d> - Overrides:
getLengthin classBezier2d- Returns:
- length of this Curve
-
toString
-