Skip to contents

Evaluates a Bezier curve of any degree with de Casteljau's algorithm. Unlike spline_path, the control points are **not** points on the curve: only the first and the last one are, and the rest pull the curve like a magnet. This is the function to use when the input really is a control polygon (a font outline, a vector graphics path, a designed shape); use spline_path when your points are positions the curve should pass through.

Usage

bezier_path(control_points, samples = 64L)

Arguments

control_points

Nx3 numeric matrix of control points (at least 2).

samples

Number of points to emit along the curve (default 64, at least 2). Both endpoints are included in the result.

Value

An Nx3 numeric matrix of path points, or an empty (0-row) matrix if there are fewer than two control points.

Examples

# A quadratic Bezier arc, drawn as a tube:
arc <- bezier_path(matrix(c(0, 0, 0, 1, 1, 0, 2, 0, 0), ncol = 3, byrow = TRUE))
nrow(arc)
#> [1] 64