Bezier
Fast and lightweight class for using the Bezier curves of any order in C++
Curve Class Reference

A Bezier curve class. More...

#include <bezier.h>

Public Member Functions

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

Protected Member Functions

void resetCache ()
 Reset all privately cached data.
 

Protected Attributes

Eigen::MatrixX2d control_points_
 N x 2 matrix where each row corresponds to control Point. More...
 

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

◆ Curve() [2/2]

Curve ( const PointVector points)

Create the Bezier curve.

Parameters
pointsA vector of control points that define the curve

Member Function Documentation

◆ applyContinuity()

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

applyContinuity Apply geometric continuity based on the another curve.

Parameters
locked_curveCurve on which calculation are based.
beta_coeffsBeta-constraints used to calculate continuity. Size defines continuity order.

◆ boundingBox()

BoundingBox boundingBox ( ) const

Get the bounding box of curve.

Returns
Bounding box (if use_roots is false, returns the bounding box of control points)

◆ controlPoint()

Point controlPoint ( unsigned  idx) const

Get the control point at index idx.

Parameters
idxIndex of chosen control point
Returns
A vector of control points

◆ 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

◆ 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
double n cannot be zero

◆ 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

◆ elevateOrder()

void elevateOrder ( )

Raise the curve order by 1.

Curve will always retain its shape

Warning
Resets cached data

◆ endPoints()

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

Get first and last control points.

Returns
A pair of end points

◆ extrema()

std::vector<double> extrema ( ) const

Get all extrema of the curve.

Returns
A vector of parameters where extrema are

◆ intersections()

PointVector intersections ( const Curve curve) const

Get the points of intersection with another curve.

Parameters
curveCurve to intersect with
Returns
A vector af points of intersection between curves

◆ iterateByLength()

double iterateByLength ( double  t,
double  s 
) const

Compute parameter t which is S distance from given t.

Parameters
tCurve parameter
sDistance to iterate
Returns
New parameter t

◆ 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

◆ 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 paramaters t1 and t2

◆ lowerOrder()

void lowerOrder ( )

Lower the curve order by 1.

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

Warning
CAN THROW: Cannot be called for curves of 1st order
Resets cached data

◆ manipulateCurvature()

void manipulateCurvature ( double  t,
const Point point 
)

Manipulate the curve so that it passes through wanted point for given 't'.

Parameters
tCurve parameter
pointPoint where curve should pass for a given t
Warning
CAN THROW: Only works for quadratic and cubic curves
Resets cached data

◆ normalAt()

Vector normalAt ( double  t,
bool  normalize = true 
) const

Get the normal of the curve for a given t.

Parameters
tCurve parameter
normalizeIf the resulting normal should be normalized
Returns
Normal of a curve for given t

◆ order()

unsigned order ( ) const

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

Returns
Order of curve

◆ polyline()

PointVector polyline ( double  flatness = 0.5) 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

◆ 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

◆ roots()

std::vector<double> 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

◆ splitCurve()

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

Split the curve into two subcurves.

Parameters
zdouble t at which to split the curve
Returns
Pair of two subcurves

◆ tangentAt()

Vector tangentAt ( double  t,
bool  normalize = true 
) const

Get the tangent of the curve for a given t.

Parameters
tCurve parameter
normalizeIf the resulting tangent should be normalized
Returns
Tangent of a curve for a given t

◆ valueAt() [1/2]

Eigen::MatrixX2d valueAt ( const std::vector< double > &  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

Field Documentation

◆ control_points_

Eigen::MatrixX2d control_points_
protected

N x 2 matrix where each row corresponds to control Point.

Warning
Any changes made to control_points_ require a call to resetCache() funtion!

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