Package org.opentrafficsim.core.geometry
Class Bezier
- java.lang.Object
-
- org.opentrafficsim.core.geometry.Bezier
-
public final class Bezier extends java.lang.Object
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.Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
$LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $, initial version Nov 14, 2015
BSD-style license. See OpenTrafficSim License.- Author:
- Alexander Verbraeck, Peter Knoppers
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static OTSLine3D
bezier(int numPoints, OTSPoint3D... points)
Construct a Bézier curve of degree n.static OTSLine3D
bezier(OTSPoint3D... points)
Construct a Bézier curve of degree n.static OTSLine3D
cubic(int numPoints, DirectedPoint start, DirectedPoint 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 OTSLine3D
cubic(int numPoints, DirectedPoint start, DirectedPoint 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 OTSLine3D
cubic(int numPoints, DirectedPoint start, DirectedPoint 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 OTSLine3D
cubic(int numPoints, OTSPoint3D start, OTSPoint3D control1, OTSPoint3D control2, OTSPoint3D end)
Construct a cubic Bézier curve from start to end with two control points.static OTSLine3D
cubic(DirectedPoint start, DirectedPoint end)
Construct a cubic Bézier curve from start to end with two generated control points at half the distance between start and end.
-
-
-
Method Detail
-
cubic
public static OTSLine3D cubic(int numPoints, OTSPoint3D start, OTSPoint3D control1, OTSPoint3D control2, OTSPoint3D 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
- OTSPoint3D; the start point of the Bézier curvecontrol1
- OTSPoint3D; the first control pointcontrol2
- OTSPoint3D; the second control pointend
- OTSPoint3D; 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 OTSLine3D cubic(int numPoints, DirectedPoint start, DirectedPoint 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
- DirectedPoint; the directed start point of the Bézier curveend
- DirectedPoint; 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 OTSLine3D cubic(int numPoints, DirectedPoint start, DirectedPoint 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
- DirectedPoint; the directed start point of the Bézier curveend
- DirectedPoint; 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 OTSLine3D cubic(int numPoints, DirectedPoint start, DirectedPoint 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
- DirectedPoint; the directed start point of the Bézier curveend
- DirectedPoint; 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 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
-
cubic
public static OTSLine3D cubic(DirectedPoint start, DirectedPoint 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
- DirectedPoint; the directed start point of the Bézier curveend
- DirectedPoint; 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 OTSLine3D bezier(int numPoints, OTSPoint3D... 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
- OTSPoint3D...; 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 OTSLine3D bezier(OTSPoint3D... points) throws OTSGeometryException
Construct a Bézier curve of degree n.- Parameters:
points
- OTSPoint3D...; 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
-
-