Bezier 0.4.0
Fast and lightweight class for using the Bezier curves of any order in C++
Loading...
Searching...
No Matches
Curve Class Reference

A Bezier curve class. More...

#include <bezier.h>

Public Member Functions

 Curve (Eigen::MatrixX2d points)
 Create the Bezier curve.
 
 Curve (const PointVector &points)
 Create the Bezier curve.
 
 Curve (const Curve &curve)
 
 Curve (Curve &&curve) noexcept
 
Curveoperator= (const Curve &curve)
 
Curveoperator= (Curve &&curve) noexcept
 
unsigned order () const
 Get order of the curve (Nth order curve is described with N+1 points)
 
PointVector controlPoints () const
 Get a vector of control points.
 
Point controlPoint (unsigned idx) const
 Get the control point at index idx.
 
std::pair< Point, PointendPoints () const
 Get first and last control points.
 
PointVector polyline () const
 Get a polyline representation of the curve as a vector of points on curve.
 
PointVector polyline (double flatness) const
 Get a polyline representation of the curve as a vector of points on curve.
 
ParamVector polylineParams () const
 Get curve parameters corresponding to polyline points.
 
ParamVector polylineParams (double flatness) const
 Get curve parameters corresponding to polyline points.
 
double length () const
 Compute exact arc length using Chebyshev polynomials.
 
double length (double t) const
 Compute exact arc length using Chebyshev polynomials.
 
double length (double t1, double t2) const
 Compute exact arc length using Chebyshev polynomials.
 
double step (double t, double ds) const
 Compute parameter t which is ds distance from given t.
 
void reverse ()
 Reverse order of control points.
 
void setControlPoint (unsigned idx, const Point &point)
 Set the new coordinates to a control point.
 
void raiseOrder ()
 Raise the curve order by 1.
 
void lowerOrder ()
 Lower the curve order by 1.
 
Point valueAt (double t) const
 Get the point on curve for a given t.
 
Eigen::MatrixX2d valueAt (const ParamVector &t_vector) const
 Get the point vector on curve for given parameters.
 
double curvatureAt (double t) const
 Get curvature of the curve for a given t.
 
double curvatureDerivativeAt (double t) const
 Get curvature derivative of the curve for a given t.
 
Vector tangentAt (double t) const
 Get the unit tangent of the curve for a given t.
 
Vector normalAt (double t) const
 Get the unit normal of the curve for a given t.
 
const Curvederivative () const
 Get the derivative of a curve.
 
const Curvederivative (unsigned n) const
 Get the nth derivative of a curve.
 
Vector derivativeAt (double t) const
 Get value of a derivative for a given t.
 
Vector derivativeAt (unsigned n, double t) const
 Get value of an nth derivative for a given t.
 
ParamVector roots () const
 Get roots of the curve on both axes.
 
ParamVector extrema () const
 Get all extrema of the curve.
 
BoundingBox boundingBox () const
 Get the bounding box of curve.
 
std::vector< CurvesplitCurve (const ParamVector &t_vector) const
 Split the curve into subcurves at multiple parameters.
 
std::pair< Curve, CurvesplitCurve (double t=0.5) const
 Split the curve into two subcurves.
 
PointVector intersections (const Curve &curve) const
 Get the points of intersection with another curve.
 
double projectPoint (const Point &point) const
 Get the parameter t where curve is closest to given point.
 
double distance (const Point &point) const
 Get distance of the point to the curve.
 
void applyContinuity (const Curve &curve, const std::vector< double > &beta_coeffs)
 Apply geometric continuity based on another curve.
 

Static Public Member Functions

static Curve offsetCurve (const Curve &curve, double offset, unsigned order=0)
 Fit a Bezier approximation of the curve offset by a given distance.
 
static Curve joinCurves (const Curve &curve1, const Curve &curve2, unsigned order=0)
 Fit a single Bezier curve through two curves joined end to end.
 
static Curve fromPolyline (const PointVector &polyline, unsigned order=0)
 Fit a Bezier curve to an ordered polyline.
 

Detailed Description

A Bezier curve class.

A class for storing and using any-order Bezier curve. It uses private and static caching for storing often accessed data. Private caching is used for data concerning individual curve, while static caching is used for common data (coefficient matrices)

Constructor & Destructor Documentation

◆ Curve() [1/2]

Curve ( Eigen::MatrixX2d  points)

Create the Bezier curve.

Parameters
pointsNx2 matrix where each row is one of N control points that define the curve
Warning
Requires at least one control point; undefined behavior otherwise (not enforced)

◆ Curve() [2/2]

Curve ( const PointVector points)

Create the Bezier curve.

Parameters
pointsA vector of control points that define the curve
Warning
Requires at least one control point; undefined behavior otherwise (not enforced)

Member Function Documentation

◆ applyContinuity()

void applyContinuity ( const Curve curve,
const std::vector< double > &  beta_coeffs 
)

Apply geometric continuity based on another curve.

Glues the start of this curve to the end of the given curve.

Parameters
curveCurve on which calculations are based
beta_coeffsBeta-constraints used to calculate continuity. Size defines continuity order.
Note
Raises the order of this curve if it has too few control points for the requested continuity
Warning
Resets cached data

◆ boundingBox()

BoundingBox boundingBox ( ) const

Get the bounding box of curve.

Returns
Bounding box

◆ controlPoint()

Point controlPoint ( unsigned  idx) const

Get the control point at index idx.

Parameters
idxIndex of chosen control point
Returns
The control point at index idx
Note
idx must be in range [0, order()]

◆ controlPoints()

PointVector controlPoints ( ) const

Get a vector of control points.

Returns
A vector of control points

◆ curvatureAt()

double curvatureAt ( double  t) const

Get curvature of the curve for a given t.

Parameters
tCurve parameter
Returns
Curvature of a curve for a given t

◆ curvatureDerivativeAt()

double curvatureDerivativeAt ( double  t) const

Get curvature derivative of the curve for a given t.

Parameters
tCurve parameter
Returns
Curvature derivative of a curve for a given t

◆ derivative() [1/2]

const Curve & derivative ( ) const

Get the derivative of a curve.

Returns
Derivative curve
Warning
The returned reference lives in this curve's cache; it is invalidated by any mutation, assignment or move of this curve.

◆ derivative() [2/2]

const Curve & derivative ( unsigned  n) const

Get the nth derivative of a curve.

Parameters
nDesired number of derivative
Returns
Derivative curve
Warning
The returned reference lives in this curve's cache; it is invalidated by any mutation, assignment or move of this curve.

◆ derivativeAt() [1/2]

Vector derivativeAt ( double  t) const

Get value of a derivative for a given t.

Parameters
tCurve parameter
Returns
Curve derivative at t

◆ derivativeAt() [2/2]

Vector derivativeAt ( unsigned  n,
double  t 
) const

Get value of an nth derivative for a given t.

Parameters
nDesired number of derivative
tCurve parameter
Returns
nth curve derivative at t

◆ distance()

double distance ( const Point point) const

Get distance of the point to the curve.

Parameters
pointPoint to project on curve
Returns
Distance to the curve

◆ endPoints()

std::pair< Point, Point > endPoints ( ) const

Get first and last control points.

Returns
A pair of end points

◆ extrema()

ParamVector extrema ( ) const

Get all extrema of the curve.

Returns
A vector of parameters where extrema are

◆ fromPolyline()

static Curve fromPolyline ( const PointVector polyline,
unsigned  order = 0 
)
static

Fit a Bezier curve to an ordered polyline.

Parameters
polylinePolyline vertices to approximate
orderOrder of the fitted curve; 0 selects it automatically
Returns
Fitted curve
Exceptions
std::logic_errorif the polyline has fewer than two points

◆ intersections()

PointVector intersections ( const Curve curve) const

Get the points of intersection with another curve.

Parameters
curveCurve to intersect with
Returns
A vector of points of intersection between curves
Note
Transversal crossings and endpoint/vertex contacts are reported; tangential (non-crossing) touches are not.

◆ joinCurves()

static Curve joinCurves ( const Curve curve1,
const Curve curve2,
unsigned  order = 0 
)
static

Fit a single Bezier curve through two curves joined end to end.

Parameters
curve1First curve
curve2Second curve
orderOrder of the resulting curve; 0 selects it automatically
Returns
Joined curve
Note
Curves need not be contiguous; a gap between them is bridged by the fit.

◆ length() [1/3]

double length ( ) const

Compute exact arc length using Chebyshev polynomials.

Returns
Arc length

◆ length() [2/3]

double length ( double  t) const

Compute exact arc length using Chebyshev polynomials.

Parameters
tCurve parameter to which length is computed
Returns
Arc length from start to parameter t
Exceptions
std::logic_errorif t is outside [0.0, 1.0]

◆ length() [3/3]

double length ( double  t1,
double  t2 
) const

Compute exact arc length using Chebyshev polynomials.

Parameters
t1Curve parameter from which length is computed
t2Curve parameter to which length is computed
Returns
Arc length between parameters t1 and t2
Exceptions
std::logic_errorif t1 or t2 is outside [0.0, 1.0]

◆ lowerOrder()

void lowerOrder ( )

Lower the curve order by 1.

If current shape cannot be described by lower order, it will be best approximation

Warning
Resets cached data
Exceptions
std::logic_errorif the curve is already 1st order

◆ normalAt()

Vector normalAt ( double  t) const

Get the unit normal of the curve for a given t.

Parameters
tCurve parameter
Returns
Unit normal of a curve for given t
Note
See tangentAt regarding behaviour at a cusp.

◆ offsetCurve()

static Curve offsetCurve ( const Curve curve,
double  offset,
unsigned  order = 0 
)
static

Fit a Bezier approximation of the curve offset by a given distance.

Parameters
curveSource curve
offsetOffset distance (positive to the left of the curve's direction, negative to the right)
orderOrder of the resulting curve; 0 selects it automatically
Returns
Offset curve

◆ order()

unsigned order ( ) const

Get order of the curve (Nth order curve is described with N+1 points)

Returns
Order of curve

◆ polyline() [1/2]

PointVector polyline ( ) const

Get a polyline representation of the curve as a vector of points on curve.

Returns
A vector of polyline vertices
Note
Default flatness parameter is calculated as 0.1% of bounding box diagonal

◆ polyline() [2/2]

PointVector polyline ( double  flatness) const

Get a polyline representation of the curve as a vector of points on curve.

Parameters
flatnessError tolerance of approximation
Returns
A vector of polyline vertices

◆ polylineParams() [1/2]

ParamVector polylineParams ( ) const

Get curve parameters corresponding to polyline points.

Returns
A vector of curve parameters for each polyline vertex
Note
Default flatness parameter is calculated as 0.1% of bounding box diagonal

◆ polylineParams() [2/2]

ParamVector polylineParams ( double  flatness) const

Get curve parameters corresponding to polyline points.

Parameters
flatnessError tolerance of approximation
Returns
A vector of curve parameters for each polyline vertex

◆ projectPoint()

double projectPoint ( const Point point) const

Get the parameter t where curve is closest to given point.

Parameters
pointPoint to project on curve
Returns
double t

◆ raiseOrder()

void raiseOrder ( )

Raise the curve order by 1.

Curve will always retain its shape

Warning
Resets cached data

◆ reverse()

void reverse ( )

Reverse order of control points.

Warning
Resets cached data

◆ roots()

ParamVector roots ( ) const

Get roots of the curve on both axes.

Returns
A vector of parameters where curve passes through axes

◆ setControlPoint()

void setControlPoint ( unsigned  idx,
const Point point 
)

Set the new coordinates to a control point.

Parameters
idxIndex of chosen control point
pointNew control point
Note
idx must be in range [0, order()]
Warning
Resets cached data

◆ splitCurve() [1/2]

std::vector< Curve > splitCurve ( const ParamVector t_vector) const

Split the curve into subcurves at multiple parameters.

Parameters
t_vectorVector of curve parameters at which to split the curve
Returns
A vector of subcurves

◆ splitCurve() [2/2]

std::pair< Curve, Curve > splitCurve ( double  t = 0.5) const

Split the curve into two subcurves.

Parameters
tCurve parameter at which to split the curve
Returns
Pair of two subcurves

◆ step()

double step ( double  t,
double  ds 
) const

Compute parameter t which is ds distance from given t.

Parameters
tCurve parameter
dsDistance to iterate
Returns
New parameter t
Note
Result saturates at t = 0.0 / t = 1.0 if ds walks off the curve
Exceptions
std::logic_errorif t is outside [0.0, 1.0]

◆ tangentAt()

Vector tangentAt ( double  t) const

Get the unit tangent of the curve for a given t.

Parameters
tCurve parameter
Returns
Unit tangent of a curve for a given t
Note
At a cusp (zero velocity) the direction is taken from the first non-vanishing derivative; it is the zero vector only if the curve is a point.

◆ valueAt() [1/2]

Eigen::MatrixX2d valueAt ( const ParamVector t_vector) const

Get the point vector on curve for given parameters.

Parameters
t_vectorCurve parameters
Returns
Matrix of points on a curve for given parameters

◆ valueAt() [2/2]

Point valueAt ( double  t) const

Get the point on curve for a given t.

Parameters
tCurve parameter
Returns
Point on a curve for a given t

The documentation for this class was generated from the following file: