Pedro 3 has been released!
Pedro Pathing LogoPedro Pathing

Bezier Curves

Bézier curves are parametric curves defined by a set of control points. They are used to create smooth curved paths between positions.

The first and last control points define the start and end of the curve, while the points between them determine the shape of the curve.

Control Points

When using Paths.curve(), the first and last Poses are the start and end of the curve. Any Poses between them are control points.

PoseFactory p = PoseFactory.degrees();

Pose start = p.of(0, 0, 0);
Pose control = p.of(20, 30, 0);
Pose end = p.of(40, 0, 0);

Path curve = Paths.curve(start, control, end);

The curve is pulled toward control, but it does not have to pass directly through it.

Multiple control points can also be used:

Pose control1 = p.of(20, 30, 0);
Pose control2 = p.of(40, 30, 0);

Path curve = Paths.curve(
    start,
    control1,
    control2,
    end
);

Curves Through Points

Paths.through() generates a Bézier curve that passes through the provided Poses.

PoseFactory p = PoseFactory.degrees();

Pose start = p.of(0, 0, 0);
Pose middle = p.of(20, 30, 0);
Pose end = p.of(40, 0, 0);

Path curve = Paths.through(start, middle, end);

This is different from using the same points with Paths.curve():

Path curve = Paths.curve(start, middle, end);

With Paths.curve(), middle is a control point and the curve is not required to pass through it. With Paths.through(), the generated curve passes through middle.

Tip

Use Paths.curve() when you want to define the shape of the curve using control points. Use Paths.through() when you want the curve to pass through specific positions.

Parameterization

Bézier curves are parameterized using a t-value from 0 to 1.

  • t = 0 represents the start of the curve.
  • t = 1 represents the end of the curve.
  • Values between 0 and 1 represent points along the curve.

When working directly with a BezierCurve, get(double t) returns the point on the curve at the given t-value:

BezierCurve curve = new BezierCurve(start, control, end);

Vector2D point = curve.get(0.5);

Bézier curves are not parameterized by distance. This means that a t-value of 0.5 does not necessarily represent a point that is 50% of the total distance along the curve.

A conversion between t-value and path completion is available using the following methods:

  • getPathCompletion(double t): Returns the path completion at a given t-value.
  • getT(double pathCompletion): Returns the t-value for a given path completion.
double completion = curve.getPathCompletion(0.5);

double t = curve.getT(completion);

Path completion is based on the distance traveled along the curve, while the t-value represents the curve's parameterization.

Last updated on