Package org.djutils.draw.curve
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
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondouble
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
hashCode()
int
size()
Return the number of points (or x-y pairs) that this Bézier curve is based on.toPolyLine
(Flattener2d flattener) Flatten a Curve into a PolyLine.toString()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.djutils.draw.curve.Curve2d
getDirection, getEndDirection, getEndPoint, getStartDirection, getStartPoint
-
Field Details
-
x
protected final double[] xThe x-coordinates of the points of this Bézier. -
y
protected final double[] yThe y-coordinates of the points of this Bézier.
-
-
Constructor Details
-
Bezier2d
Create a Bézier curve of any order.- Parameters:
points
- Point2d... shape points that define the Bézier curve- Throws:
NullPointerException
- whenpoints
isnull
, or contains anull
valueIllegalArgumentException
- when the length ofpoints
is less than2
-
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 curvey
- the y-coordinates of the points that define the Bézier curve- Throws:
NullPointerException
- whenx
, ory
isnull
IllegalArgumentException
- when the length of thex
array is not equal to the length of they
array, or less than2
-
-
Method Details
-
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 ofthis Bezier2d
is1
-
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
- wheni < 0
, ori ≥ 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
- wheni < 0
, ori ≥ size()
-
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> - 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 interfaceCurve<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
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> - Parameters:
flattener
- the flattener- Returns:
- approximation of this
Curve
as aPolyLine
-
toString
-
hashCode
public int hashCode() -
equals
-