Package org.opentrafficsim.core.geometry
Class Bezier
java.lang.Object
org.opentrafficsim.core.geometry.Bezier
Generation of Bézier curves.
The class implements the cubic(...) method to generate a cubic Bézier curve using the following formula: B(t) = (1 - t)3P0 + 3t(1 - t)2 P1 + 3t2 (1 - t) P2 + t3 P3 where P0 and P3 are the end points, and P1 and P2 the control points.
For a smooth movement, one of the standard implementations if the cubic(...) function offered is the case where P1 is positioned halfway between P0 and P3 starting from P0 in the direction of P3, and P2 is positioned halfway between P3 and P0 starting from P3 in the direction of P0.
Finally, an n-point generalization of the Bézier curve is implemented with the bezier(...) function.
The class implements the cubic(...) method to generate a cubic Bézier curve using the following formula: B(t) = (1 - t)3P0 + 3t(1 - t)2 P1 + 3t2 (1 - t) P2 + t3 P3 where P0 and P3 are the end points, and P1 and P2 the control points.
For a smooth movement, one of the standard implementations if the cubic(...) function offered is the case where P1 is positioned halfway between P0 and P3 starting from P0 in the direction of P3, and P2 is positioned halfway between P3 and P0 starting from P3 in the direction of P0.
Finally, an n-point generalization of the Bézier curve is implemented with the bezier(...) function.
Copyright (c) 2013-2024 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
-
Method Summary
Modifier and TypeMethodDescriptionstatic OtsLine2d
bezier
(int numPoints, org.djutils.draw.point.Point2d... points) Construct a Bézier curve of degree n.static OtsLine2d
bezier
(org.djutils.draw.point.Point2d... points) Construct a Bézier curve of degree n.(package private) static double
Bn
(double t, double... p) Calculate the Bézier point of degree n, with B(t) = Sum(i = 0..n) [C(n, i) * (1 - t)n-i ti Pi], where C(n, k) is the binomial coefficient defined by n!static OtsLine2d
cubic
(int numPoints, org.djutils.draw.point.OrientedPoint2d start, org.djutils.draw.point.OrientedPoint2d end) Construct a cubic Bézier curve from start to end with two generated control points at half the distance between start and end.static OtsLine2d
cubic
(int numPoints, org.djutils.draw.point.OrientedPoint2d start, org.djutils.draw.point.OrientedPoint2d end, double shape) Construct a cubic Bézier curve from start to end with two generated control points at half the distance between start and end.static OtsLine2d
cubic
(int numPoints, org.djutils.draw.point.OrientedPoint2d start, org.djutils.draw.point.OrientedPoint2d end, double shape, boolean weighted) Construct a cubic Bézier curve from start to end with two generated control points at half the distance between start and end.static OtsLine2d
cubic
(int numPoints, org.djutils.draw.point.Point2d start, org.djutils.draw.point.Point2d control1, org.djutils.draw.point.Point2d control2, org.djutils.draw.point.Point2d end) Construct a cubic Bézier curve from start to end with two control points.static OtsLine2d
cubic
(org.djutils.draw.point.OrientedPoint2d start, org.djutils.draw.point.OrientedPoint2d end) Construct a cubic Bézier curve from start to end with two generated control points at half the distance between start and end.static org.djutils.draw.point.Point2d[]
cubicControlPoints
(org.djutils.draw.point.OrientedPoint2d start, org.djutils.draw.point.OrientedPoint2d end, double shape, boolean weighted) Construct control points for a cubic Bézier curve from start to end with two generated control points at half the distance between start and end.
-
Method Details
-
cubic
public static OtsLine2d cubic(int numPoints, org.djutils.draw.point.Point2d start, org.djutils.draw.point.Point2d control1, org.djutils.draw.point.Point2d control2, org.djutils.draw.point.Point2d end) throws OtsGeometryException Construct a cubic Bézier curve from start to end with two control points.- Parameters:
numPoints
- int; the number of points for the Bézier curvestart
- Point2d; the start point of the Bézier curvecontrol1
- Point2d; the first control pointcontrol2
- Point2d; the second control pointend
- Point2d; the end point of the Bézier curve- Returns:
- a cubic Bézier curve between start and end, with the two provided control points
- Throws:
OtsGeometryException
- in case the number of points is less than 2 or the Bézier curve could not be constructed
-
cubic
public static OtsLine2d cubic(int numPoints, org.djutils.draw.point.OrientedPoint2d start, org.djutils.draw.point.OrientedPoint2d end) throws OtsGeometryException Construct a cubic Bézier curve from start to end with two generated control points at half the distance between start and end. The z-value is interpolated in a linear way.- Parameters:
numPoints
- int; the number of points for the Bézier curvestart
- OrientedPoint2d; the directed start point of the Bézier curveend
- OrientedPoint2d; the directed end point of the Bézier curve- Returns:
- a cubic Bézier curve between start and end, with the two provided control points
- Throws:
OtsGeometryException
- in case the number of points is less than 2 or the Bézier curve could not be constructed
-
cubic
public static OtsLine2d cubic(int numPoints, org.djutils.draw.point.OrientedPoint2d start, org.djutils.draw.point.OrientedPoint2d end, double shape) throws OtsGeometryException Construct a cubic Bézier curve from start to end with two generated control points at half the distance between start and end. The z-value is interpolated in a linear way.- Parameters:
numPoints
- int; the number of points for the Bézier curvestart
- OrientedPoint2d; the directed start point of the Bézier curveend
- OrientedPoint2d; the directed end point of the Bézier curveshape
- shape factor; 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- Returns:
- a cubic Bézier curve between start and end, with the two determined control points
- Throws:
OtsGeometryException
- in case the number of points is less than 2 or the Bézier curve could not be constructed
-
cubic
public static OtsLine2d cubic(int numPoints, org.djutils.draw.point.OrientedPoint2d start, org.djutils.draw.point.OrientedPoint2d end, double shape, boolean weighted) throws OtsGeometryException Construct a cubic Bézier curve from start to end with two generated control points at half the distance between start and end. The z-value is interpolated in a linear way.- Parameters:
numPoints
- int; the number of points for the Bézier curvestart
- OrientedPoint2d; the directed start point of the Bézier curveend
- OrientedPoint2d; the directed end point of the Bézier curveshape
- double; shape factor; 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 0weighted
- boolean; control point distance relates to distance to projected point on extended line from other end- Returns:
- a cubic Bézier curve between start and end, with the two determined control points
- Throws:
OtsGeometryException
- in case the number of points is less than 2 or the Bézier curve could not be constructed
-
cubicControlPoints
public static org.djutils.draw.point.Point2d[] cubicControlPoints(org.djutils.draw.point.OrientedPoint2d start, org.djutils.draw.point.OrientedPoint2d end, double shape, boolean weighted) Construct control points for a cubic Bézier curve from start to end with two generated control points at half the distance between start and end.- Parameters:
start
- OrientedPoint2d; the directed start point of the Bézier curveend
- OrientedPoint2d; the directed end point of the Bézier curveshape
- double; shape factor; 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 0weighted
- boolean; control point distance relates to distance to projected point on extended line from other end- Returns:
- a cubic Bézier curve between start and end, with the two determined control points
-
cubic
public static OtsLine2d cubic(org.djutils.draw.point.OrientedPoint2d start, org.djutils.draw.point.OrientedPoint2d end) throws OtsGeometryException Construct a cubic Bézier curve from start to end with two generated control points at half the distance between start and end. The z-value is interpolated in a linear way.- Parameters:
start
- OrientedPoint2d; the directed start point of the Bézier curveend
- OrientedPoint2d; the directed end point of the Bézier curve- Returns:
- a cubic Bézier curve between start and end, with the two provided control points
- Throws:
OtsGeometryException
- in case the number of points is less than 2 or the Bézier curve could not be constructed
-
bezier
public static OtsLine2d bezier(int numPoints, org.djutils.draw.point.Point2d... points) throws OtsGeometryException Construct a Bézier curve of degree n.- Parameters:
numPoints
- int; the number of points for the Bézier curve to be constructedpoints
- Point2d...; the points of the curve, where the first and last are begin and end point, and the intermediate ones are control points. There should be at least two points.- Returns:
- the Bézier value B(t) of degree n, where n is the number of points in the array
- Throws:
OtsGeometryException
- in case the number of points is less than 2 or the Bézier curve could not be constructed
-
bezier
public static OtsLine2d bezier(org.djutils.draw.point.Point2d... points) throws OtsGeometryException Construct a Bézier curve of degree n.- Parameters:
points
- Point2d...; the points of the curve, where the first and last are begin and end point, and the intermediate ones are control points. There should be at least two points.- Returns:
- the Bézier value B(t) of degree n, where n is the number of points in the array
- Throws:
OtsGeometryException
- in case the number of points is less than 2 or the Bézier curve could not be constructed
-
Bn
static double Bn(double t, double... p) Calculate the Bézier point of degree n, with B(t) = Sum(i = 0..n) [C(n, i) * (1 - t)n-i ti Pi], where C(n, k) is the binomial coefficient defined by n! / ( k! (n-k)! ), ! being the factorial operator.- Parameters:
t
- double; the fractionp
- double...; the points of the curve, where the first and last are begin and end point, and the intermediate ones are control points- Returns:
- the Bézier value B(t) of degree n, where n is the number of points in the array
-