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 fromstart
toend
with two generated control points.BezierCubic2d
(Ray2d start, Ray2d end, double shape) Construct a BezierCubic2d fromstart
toend
with 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 TypeMethodDescriptiondouble
getDirection
(double fraction, ContinuousPiecewiseLinearFunction of) Returns the direction at the given fraction.double
End curvature of this BezierCubic2d.double
Return 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.double
Start curvature of this BezierCubic2d.double
getT
(double position) Returns the t value at the provided length along the Bézier curve.org.djutils.draw.curve.BezierCubic2d.SplitBeziers
split
(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, size
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.djutils.draw.curve.Curvature
getEndRadius, getStartRadius
Methods 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
, orend
isnull
-
BezierCubic2d
Create a cubic Bézier curve.- Parameters:
points
- array containing fourPoint2d
objects- Throws:
NullPointerException
- whenpoints
isnull
, or contains anull
valueIllegalArgumentException
- when length ofpoints
is not equal to4
-
BezierCubic2d
Construct a BezierCubic2d fromstart
toend
with two generated control points. This constructor creates two control points. The first of these is offset fromstart
in the direction of thestart
and at a distance fromstart
equal to half the distance fromstart
toend
. 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
, orend
isnull
IllegalArgumentException
- whenstart
andend
are at the same location
-
BezierCubic2d
Construct a BezierCubic2d fromstart
toend
with two generated control points. The control points are in placed along the direction of thestart
, resp.end
points at a distance that depends on theshape
parameter.- 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
, orend
isnull
IllegalArgumentException
- whenstart
andend
are at the same location,shape ≤ 0
,shape
isNaN
, 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
, orend
isnull
IllegalArgumentException
- whenstart
andend
are at the same location,shape ≤ 0
,shape
isNaN
, or infinite
-
-
Method Details
-
getPoint
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 interfaceCurve<DirectedPoint2d,
Double, Point2d, Flattener2d, PolyLine2d> - Specified by:
getPoint
in interfaceFlattener.FlattableCurve<Point2d,
Double> - Overrides:
getPoint
in classBezier2d
- 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 interfaceCurvature
- Returns:
- start curvature of this BezierCubic2d
-
getEndCurvature
public double getEndCurvature()End curvature of this BezierCubic2d. TODO looks very wrong- Specified by:
getEndCurvature
in 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:
getT
in 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:Curve
Flatten a Curve into a PolyLine. Implementations should use the flattener when relevant and possible.- Specified by:
toPolyLine
in interfaceCurve<DirectedPoint2d,
Double, Point2d, Flattener2d, PolyLine2d> - Overrides:
toPolyLine
in classBezier2d
- Parameters:
flattener
- the flattener- Returns:
- approximation of this
Curve
as aPolyLine
-
getPoint
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 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: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 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: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 interfaceOffsetCurve2d
- Parameters:
flattener
- OffsetFlattenerof
- offset data- Returns:
- approximation of this
curve2d
with offset as aPolyLine2d
-
getLength
public double getLength()Description copied from interface:Curve
Return the length of this Curve.- Specified by:
getLength
in interfaceCurve<DirectedPoint2d,
Double, Point2d, Flattener2d, PolyLine2d> - Overrides:
getLength
in classBezier2d
- Returns:
- length of this Curve
-
toString
-