Package org.djutils.draw.line
Class Bezier
- java.lang.Object
-
- org.djutils.draw.line.Bezier
-
public final class Bezier extends 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-2021 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
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_BEZIER_SIZE
The default number of points to use to construct a Bézier curve.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static PolyLine2d
bezier(double epsilon, Point2d... points)
Approximate a Bézier curve of degree n with a specified precision.static PolyLine3d
bezier(double epsilon, Point3d... points)
Approximate a Bézier curve of degree n with a specified precision.static PolyLine2d
bezier(int size, Point2d... points)
Approximate a Bézier curve of degree n.static PolyLine3d
bezier(int size, Point3d... points)
Construct a Bézier curve of degree n.static PolyLine2d
bezier(Point2d... points)
Approximate a Bézier curve of degree n usingDEFAULT_BEZIER_SIZE
points.static PolyLine3d
bezier(Point3d... points)
Approximate a Bézier curve of degree n usingDEFAULT_BEZIER_SIZE
points.static PolyLine2d
cubic(double epsilon, Ray2d start, Ray2d end)
Approximate a cubic Bézier curve from start to end with two generated control points at half the distance between start and end with specified precision.static PolyLine2d
cubic(double epsilon, Ray2d start, Ray2d end, double shape)
Approximate a cubic Bézier curve from start to end with two generated control points at half the distance between start and end with specified precision.static PolyLine2d
cubic(double epsilon, Ray2d start, Ray2d end, double shape, boolean weighted)
Approximate a cubic Bézier curve from start to end with two generated control points at half the distance between start and end with specified precision.static PolyLine3d
cubic(double epsilon, Ray3d start, Ray3d end)
Approximate a cubic Bézier curve from start to end with two generated control points at half the distance between start and end with specified precision.static PolyLine3d
cubic(double epsilon, Ray3d start, Ray3d end, double shape)
Approximate a cubic Bézier curve from start to end with two generated control points at half the distance between start and end with specified precision.static PolyLine3d
cubic(double epsilon, Ray3d start, Ray3d end, double shape, boolean weighted)
Approximate a cubic Bézier curve from start to end with two generated control points at half the distance between start and end with specified precision.static PolyLine2d
cubic(double epsilon, Point2d start, Point2d control1, Point2d control2, Point2d end)
Approximate a cubic Bézier curve from start to end with two control points with a specified precision.static PolyLine3d
cubic(double epsilon, Point3d start, Point3d control1, Point3d control2, Point3d end)
Approximate a cubic Bézier curve from start to end with two control points with a specified precision.static PolyLine2d
cubic(int size, Ray2d start, Ray2d end)
Approximate a cubic Bézier curve from start to end with two generated control points at half the distance between start and end.static PolyLine2d
cubic(int size, Ray2d start, Ray2d end, double shape)
Approximate a cubic Bézier curve from start to end with two generated control points at half the distance between start and end.static PolyLine2d
cubic(int size, Ray2d start, Ray2d end, double shape, boolean weighted)
Approximate a cubic Bézier curve from start to end with two generated control points at half the distance between start and end.static PolyLine3d
cubic(int size, Ray3d start, Ray3d end)
Approximate a cubic Bézier curve from start to end with two generated control points at half the distance between start and end.static PolyLine3d
cubic(int size, Ray3d start, Ray3d end, double shape)
Approximate a cubic Bézier curve from start to end with two generated control points at half the distance between start and end.static PolyLine3d
cubic(int size, Ray3d start, Ray3d end, double shape, boolean weighted)
Approximate a cubic Bézier curve from start to end with two generated control points at half the distance between start and end.static PolyLine2d
cubic(int size, Point2d start, Point2d control1, Point2d control2, Point2d end)
Approximate a cubic Bézier curve from start to end with two control points.static PolyLine3d
cubic(int size, Point3d start, Point3d control1, Point3d control2, Point3d end)
Approximate a cubic Bézier curve from start to end with two control points.static PolyLine2d
cubic(Ray2d start, Ray2d end)
Approximate a cubic Bézier curve from start to end with two generated control points at half the distance between start and end.static PolyLine3d
cubic(Ray3d start, Ray3d end)
Construct a cubic Bézier curve from start to end with two generated control points at half the distance between start and end.
-
-
-
Field Detail
-
DEFAULT_BEZIER_SIZE
public static final int DEFAULT_BEZIER_SIZE
The default number of points to use to construct a Bézier curve.- See Also:
- Constant Field Values
-
-
Method Detail
-
cubic
public static PolyLine2d cubic(int size, Point2d start, Point2d control1, Point2d control2, Point2d end) throws DrawRuntimeException
Approximate a cubic Bézier curve from start to end with two control points.- Parameters:
size
- int; the number of points of 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:
- PolyLine2d; an approximation of a cubic Bézier curve between start and end, using the two provided control points
- Throws:
DrawRuntimeException
- in case the number of points is less than 2 or the Bézier curve could not be constructed
-
cubic
public static PolyLine2d cubic(double epsilon, Point2d start, Point2d control1, Point2d control2, Point2d end) throws DrawRuntimeException
Approximate a cubic Bézier curve from start to end with two control points with a specified precision.- Parameters:
epsilon
- double; the precision.start
- 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:
- PolyLine2d; an approximation of a cubic Bézier curve between start and end, using the two provided control points
- Throws:
DrawRuntimeException
- in case the number of points is less than 2, or the Bézier curve could not be constructed
-
cubic
public static PolyLine2d cubic(int size, Ray2d start, Ray2d end) throws DrawRuntimeException
Approximate a cubic Bézier curve from start to end with two generated control points at half the distance between start and end. TODO change start and end to Ray3d- Parameters:
size
- int; the number of points of the Bézier curvestart
- Ray2d; the start point and start direction of the Bézier curveend
- Ray2d; the end point and end direction of the Bézier curve- Returns:
- PolyLine2d; an approximation of a cubic Bézier curve between start and end, using the directions of those points at start and end
- Throws:
DrawRuntimeException
- in case the number of points is less than 2 or the Bézier curve could not be constructed
-
cubic
public static PolyLine2d cubic(double epsilon, Ray2d start, Ray2d end) throws DrawRuntimeException
Approximate a cubic Bézier curve from start to end with two generated control points at half the distance between start and end with specified precision.- Parameters:
epsilon
- double; the precision.start
- Ray2d; the start point and start direction of the Bézier curveend
- Ray2d; the end point and end direction of the Bézier curve- Returns:
- PolyLine2d; an approximation of a cubic Bézier curve between start and end, using the directions of those points at start and end
- Throws:
DrawRuntimeException
- in case the number of points is less than 2 or the Bézier curve could not be constructed
-
cubic
public static PolyLine2d cubic(int size, Ray2d start, Ray2d end, double shape) throws DrawRuntimeException
Approximate a cubic Bézier curve from start to end with two generated control points at half the distance between start and end.- Parameters:
size
- int; the number of points for the Bézier curvestart
- Ray2d; the start point and start direction of the Bézier curveend
- Ray2d; the end point and end direction 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 and finite- Returns:
- PolyLine2d; an approximation of a cubic Bézier curve between start and end, using the directions of those points at start and end
- Throws:
DrawRuntimeException
- in case the number of points is less than 2 or the Bézier curve could not be constructed
-
cubic
public static PolyLine2d cubic(double epsilon, Ray2d start, Ray2d end, double shape) throws DrawRuntimeException
Approximate a cubic Bézier curve from start to end with two generated control points at half the distance between start and end with specified precision.- Parameters:
epsilon
- double; the precision.start
- Ray2d; the start point and start direction of the Bézier curveend
- Ray2d; the end point and end direction 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 and finite- Returns:
- PolyLine2d; an approximation of a cubic Bézier curve between start and end, using the directions of those points at start and end
- Throws:
DrawRuntimeException
- in case the number of points is less than 2 or the Bézier curve could not be constructed
-
cubic
public static PolyLine2d cubic(int size, Ray2d start, Ray2d end, double shape, boolean weighted) throws NullPointerException, DrawRuntimeException
Approximate a cubic Bézier curve from start to end with two generated control points at half the distance between start and end.- Parameters:
size
- int; the number of points for the Bézier curvestart
- Ray2d; the start point and start direction of the Bézier curveend
- Ray2d; the end point and end direction 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, finite and not NaNweighted
- boolean; control point distance relates to distance to projected point on extended line from other end- Returns:
- PolyLine2d; an approximation of a cubic Bézier curve between start and end, with the two determined control points
- Throws:
NullPointerException
- when start or end is nullDrawRuntimeException
- in case size is less than 2, start is at the same location as end, shape is invalid, or the Bézier curve could not be constructed
-
cubic
public static PolyLine2d cubic(double epsilon, Ray2d start, Ray2d end, double shape, boolean weighted) throws NullPointerException, DrawRuntimeException
Approximate a cubic Bézier curve from start to end with two generated control points at half the distance between start and end with specified precision.- Parameters:
epsilon
- double; the precision.start
- Ray2d; the start point and start direction of the Bézier curveend
- Ray2d; the end point and end direction 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, finite and not NaNweighted
- boolean; control point distance relates to distance to projected point on extended line from other end- Returns:
- PolyLine2d; an approximation of a cubic Bézier curve between start and end, with the two determined control points
- Throws:
NullPointerException
- when start or end is nullDrawRuntimeException
- in case size is less than 2, start is at the same location as end, shape is invalid
-
cubic
public static PolyLine2d cubic(Ray2d start, Ray2d end) throws DrawRuntimeException
Approximate a cubic Bézier curve from start to end with two generated control points at half the distance between start and end. The size of the constructed curve isDEFAULT_BEZIER_SIZE
.- Parameters:
start
- Ray2d; the start point and start direction of the Bézier curveend
- Ray2d; the end point and end direction of the Bézier curve- Returns:
- PolyLine2d; an approximation of a cubic Bézier curve between start and end, following the directions of those points at start and end
- Throws:
DrawRuntimeException
- in case the number of points is less than 2 or the Bézier curve could not be constructed
-
bezier
public static PolyLine2d bezier(int size, Point2d... points) throws NullPointerException, DrawRuntimeException
Approximate a Bézier curve of degree n.- Parameters:
size
- 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:
- PolyLine2d; an approximation of a cubic Bézier curve between start and end, using the provided control points
- Throws:
NullPointerException
- when points contains a nullDrawRuntimeException
- in case the number of points is less than 2, size is less than 2, or the Bézier curve could not be constructed
-
bezier
public static PolyLine2d bezier(Point2d... points) throws NullPointerException, DrawRuntimeException
Approximate a Bézier curve of degree n usingDEFAULT_BEZIER_SIZE
points.- 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:
- PolyLine2d; an approximation of a cubic Bézier curve between start and end, using the provided control points
- Throws:
NullPointerException
- when points contains a null valueDrawRuntimeException
- in case the number of points is less than 2 or the Bézier curve could not be constructed
-
bezier
public static PolyLine2d bezier(double epsilon, Point2d... points) throws NullPointerException, DrawRuntimeException
Approximate a Bézier curve of degree n with a specified precision.- Parameters:
epsilon
- double; the precision.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:
- PolyLine2d; an approximation of a cubic Bézier curve between start and end, with the provided control points
- Throws:
NullPointerException
- when points contains a null valueDrawRuntimeException
- in case the number of points is less than 2 or the Bézier curve could not be constructed
-
cubic
public static PolyLine3d cubic(int size, Point3d start, Point3d control1, Point3d control2, Point3d end) throws DrawRuntimeException
Approximate a cubic Bézier curve from start to end with two control points.- Parameters:
size
- int; the number of points for the Bézier curvestart
- Point3d; the start point of the Bézier curvecontrol1
- Point3d; the first control pointcontrol2
- Point3d; the second control pointend
- Point3d; the end point of the Bézier curve- Returns:
- PolyLine3d; an approximation of a cubic Bézier curve between start and end, with the two provided control points
- Throws:
DrawRuntimeException
- in case the number of points is less than 2 or the Bézier curve could not be constructed
-
cubic
public static PolyLine3d cubic(double epsilon, Point3d start, Point3d control1, Point3d control2, Point3d end) throws DrawRuntimeException
Approximate a cubic Bézier curve from start to end with two control points with a specified precision.- Parameters:
epsilon
- double; the precision.start
- Point3d; the start point of the Bézier curvecontrol1
- Point3d; the first control pointcontrol2
- Point3d; the second control pointend
- Point3d; the end point of the Bézier curve- Returns:
- PolyLine3d; an approximation of a cubic Bézier curve between start and end, with the two provided control points
- Throws:
DrawRuntimeException
- in case the number of points is less than 2 or the Bézier curve could not be constructed
-
cubic
public static PolyLine3d cubic(int size, Ray3d start, Ray3d end) throws DrawRuntimeException
Approximate a cubic Bézier curve from start to end with two generated control points at half the distance between start and end.- Parameters:
size
- int; the number of points for the Bézier curvestart
- Ray3d; the start point and start direction of the Bézier curveend
- Ray3d; the end point and end direction of the Bézier curve- Returns:
- PolyLine2d; an approximation of a cubic Bézier curve between start and end, with the two provided control points
- Throws:
DrawRuntimeException
- in case the number of points is less than 2 or the Bézier curve could not be constructed
-
cubic
public static PolyLine3d cubic(double epsilon, Ray3d start, Ray3d end) throws DrawRuntimeException
Approximate a cubic Bézier curve from start to end with two generated control points at half the distance between start and end with specified precision.- Parameters:
epsilon
- double; the precision.start
- Ray3d; the start point and start direction of the Bézier curveend
- Ray3d; the end point and end direction of the Bézier curve- Returns:
- PolyLine2d; an approximation of a cubic Bézier curve between start and end, with the two provided control points
- Throws:
DrawRuntimeException
- in case the number of points is less than 2 or the Bézier curve could not be constructed
-
cubic
public static PolyLine3d cubic(int size, Ray3d start, Ray3d end, double shape) throws DrawRuntimeException
Approximate a cubic Bézier curve from start to end with two generated control points at half the distance between start and end.- Parameters:
size
- int; the number of points for the Bézier curvestart
- Ray3d; the start point and start direction of the Bézier curveend
- Ray3d; the end point and end direction 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 and finite- Returns:
- a cubic Bézier curve between start and end, with the two determined control points
- Throws:
DrawRuntimeException
- in case the number of points is less than 2 or the Bézier curve could not be constructed
-
cubic
public static PolyLine3d cubic(double epsilon, Ray3d start, Ray3d end, double shape) throws DrawRuntimeException
Approximate a cubic Bézier curve from start to end with two generated control points at half the distance between start and end with specified precision.- Parameters:
epsilon
- double; the precision.start
- Ray3d; the start point and start direction of the Bézier curveend
- Ray3d; the end point and end direction 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 and finite- Returns:
- a cubic Bézier curve between start and end, with the two determined control points
- Throws:
DrawRuntimeException
- in case the number of points is less than 2 or the Bézier curve could not be constructed
-
cubic
public static PolyLine3d cubic(int size, Ray3d start, Ray3d end, double shape, boolean weighted) throws NullPointerException, DrawRuntimeException
Approximate 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:
size
- int; the number of points for the Bézier curvestart
- Ray3d; the start point and start direction of the Bézier curveend
- Ray3d; the end point and end direction 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:
NullPointerException
- when start or end is nullDrawRuntimeException
- in case size is less than 2, start is at the same location as end, shape is invalid, or the Bézier curve could not be constructed
-
cubic
public static PolyLine3d cubic(double epsilon, Ray3d start, Ray3d end, double shape, boolean weighted) throws NullPointerException, DrawRuntimeException
Approximate a cubic Bézier curve from start to end with two generated control points at half the distance between start and end with specified precision.- Parameters:
epsilon
- double; the precision.start
- Ray3d; the start point and start direction of the Bézier curveend
- Ray3d; the end point and end direction 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, finite and not NaNweighted
- boolean; control point distance relates to distance to projected point on extended line from other end- Returns:
- PolyLine3d; an approximation of a cubic Bézier curve between start and end, with the two determined control points
- Throws:
NullPointerException
- when start or end is nullDrawRuntimeException
- in case size is less than 2, start is at the same location as end, shape is invalid, or the Bézier curve could not be constructed
-
cubic
public static PolyLine3d cubic(Ray3d start, Ray3d end) throws DrawRuntimeException
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. The size of the constructed curve isDEFAULT_BEZIER_SIZE
. TODO change start en end to Ray3d- Parameters:
start
- Ray3d; the start point and orientation of the Bézier curveend
- Ray3d; the end point and orientation of the Bézier curve- Returns:
- a cubic Bézier curve between start and end, with the two provided control points
- Throws:
DrawRuntimeException
- in case the number of points is less than 2 or the Bézier curve could not be constructed
-
bezier
public static PolyLine3d bezier(int size, Point3d... points) throws DrawRuntimeException
Construct a Bézier curve of degree n.- Parameters:
size
- int; the number of points for the Bézier curve to be constructedpoints
- Point3d...; 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:
DrawRuntimeException
- in case the number of points is less than 2 or the Bézier curve could not be constructed
-
bezier
public static PolyLine3d bezier(Point3d... points) throws DrawRuntimeException
Approximate a Bézier curve of degree n usingDEFAULT_BEZIER_SIZE
points.- Parameters:
points
- Point3d...; 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:
DrawRuntimeException
- in case the number of points is less than 2 or the Bézier curve could not be constructed
-
bezier
public static PolyLine3d bezier(double epsilon, Point3d... points) throws NullPointerException, DrawRuntimeException
Approximate a Bézier curve of degree n with a specified precision.- Parameters:
epsilon
- double; the precision.points
- Point3d...; 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:
- PolyLine3d; an approximation of a cubic Bézier curve between start and end, with the provided control points
- Throws:
NullPointerException
- when points contains a null valueDrawRuntimeException
- in case the number of points is less than 2 or the Bézier curve could not be constructed
-
-