Class 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-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
    BSD-style license. See OpenTrafficSim License.

    $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $, initial version Nov 14, 2015
    Author:
    Alexander Verbraeck, Peter Knoppers
    • Method Detail

      • cubic

        public static PolyLine3d cubic​(int numPoints,
                                       Point3d start,
                                       Point3d control1,
                                       Point3d control2,
                                       Point3d end)
                                throws DrawRuntimeException
        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 curve
        start - Point3d; the start point of the Bézier curve
        control1 - Point3d; the first control point
        control2 - Point3d; the second control point
        end - Point3d; 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:
        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 numPoints,
                                       OrientedPoint3d start,
                                       OrientedPoint3d 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.
        Parameters:
        numPoints - int; the number of points for the Bézier curve
        start - OrientedPoint3d; the directed start point of the Bézier curve
        end - OrientedPoint3d; 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:
        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 numPoints,
                                       OrientedPoint3d start,
                                       OrientedPoint3d end,
                                       double shape)
                                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.
        Parameters:
        numPoints - int; the number of points for the Bézier curve
        start - OrientedPoint3d; the directed start point of the Bézier curve
        end - OrientedPoint3d; the directed end point of the Bézier curve
        shape - 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:
        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 numPoints,
                                       OrientedPoint3d start,
                                       OrientedPoint3d end,
                                       double shape,
                                       boolean weighted)
                                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.
        Parameters:
        numPoints - int; the number of points for the Bézier curve
        start - OrientedPoint3d; the directed start point of the Bézier curve
        end - OrientedPoint3d; the directed end point of the Bézier curve
        shape - 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
        weighted - 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:
        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​(OrientedPoint3d start,
                                       OrientedPoint3d end)
        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 - OrientedPoint3d; the directed start point of the Bézier curve
        end - OrientedPoint3d; 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:
        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 numPoints,
                                        Point3d... points)
                                 throws DrawRuntimeException
        Construct a Bézier curve of degree n.
        Parameters:
        numPoints - int; the number of points for the Bézier curve to be constructed
        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​(Point3d... points)
                                 throws DrawRuntimeException
        Construct a Bézier curve of degree n.
        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