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 TypeMethodDescriptiondoublecurvature(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.booleandoubleReturn the length of this Curve.getPoint(double t) Returns the point at the given fraction of this Curve.doublegetX(int i) Retrieve the x-coordinate of the i'th point of this Bézier curve.doublegetY(int i) Retrieve the y-coordinate of the i'th point of this Bézier curve.inthashCode()intsize()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, waitMethods 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- whenpointsisnull, or contains anullvalueIllegalArgumentException- when the length ofpointsis 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, oryisnullIllegalArgumentException- when the length of thexarray is not equal to the length of theyarray, 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 Bezier2dis1
-
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: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> - Parameters:
t- the fraction- Returns:
- the point at the given
fraction
-
getLength
public double getLength()Description copied from interface:CurveReturn the length of this Curve.- Specified by:
getLengthin 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:CurveFlatten a Curve into a PolyLine. Implementations should use the flattener when relevant and possible.- Specified by:
toPolyLinein interfaceCurve<DirectedPoint2d,Double, Point2d, Flattener2d, PolyLine2d> - Parameters:
flattener- the flattener- Returns:
- approximation of this
Curveas aPolyLine
-
toString
-
hashCode
public int hashCode() -
equals
-