ndcurves 2.3.0
create and manipulate spline and bezier curves.
Loading...
Searching...
No Matches
bezier_curve.h File Reference

class allowing to create a Bezier curve of dimension 1 <= n <= 3. More...

#include <iostream>
#include <stdexcept>
#include <vector>
#include "MathDefs.h"
#include "bernstein.h"
#include "cross_implementation.h"
#include "curve_abc.h"
#include "curve_constraint.h"
#include "piecewise_curve.h"
Include dependency graph for bezier_curve.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ndcurves::bezier_curve< Time, Numeric, Safe, Point >

Namespaces

namespace  ndcurves

Typedefs

typedef Point point_t
typedef Eigen::Matrix< Numeric, Eigen::Dynamic, 1 > vector_x_t
typedef Eigen::Ref< const vector_x_tvector_x_ref_t
typedef Time time_t
typedef Numeric num_t
typedef curve_constraints< point_tcurve_constraints_t
typedef std::vector< point_t, Eigen::aligned_allocator< point_t > > t_point_t
typedef t_point_t::const_iterator cit_point_t
typedef bezier_curve< Time, Numeric, Safe, Point > bezier_curve_t
typedef std::shared_ptr< bezier_curve_tbezier_curve_ptr_t
typedef piecewise_curve< Time, Numeric, Safe, point_t, point_t, bezier_curve_tpiecewise_curve_t
typedef curve_abc< Time, Numeric, Safe, point_tcurve_abc_t
typedef curve_abc_t::curve_ptr_t curve_ptr_t

Functions

template<typename Time = double, typename Numeric = Time, bool Safe = false, typename Point = Eigen::Matrix<Numeric, Eigen::Dynamic, 1>>
ndcurves::bezier_curve curve_abc ndcurves::waypoints () const
 bezier_curve ()
 Empty constructor. Curve obtained this way can not perform other class functions.
template<typename In>
 bezier_curve (In PointsBegin, In PointsEnd, const time_t T_min=0., const time_t T_max=1., const time_t mult_T=1.)
 Constructor. Given the first and last point of a control points set, create the bezier curve.
template<typename In>
 bezier_curve (In PointsBegin, In PointsEnd, const curve_constraints_t &constraints, const time_t T_min=0., const time_t T_max=1., const time_t mult_T=1.)
 Constructor with constraints. This constructor will add 4 points (2 after the first one, 2 before the last one) to ensure that velocity and acceleration constraints are respected.
 bezier_curve (const bezier_curve &other)
virtual ~bezier_curve ()
 Destructor.
virtual point_t operator() (const time_t t) const
 Evaluation of the bezier curve at time t.
bool isApprox (const bezier_curve_t &other, const Numeric prec=Eigen::NumTraits< Numeric >::dummy_precision()) const
 isApprox check if other and *this are approximately equals. Only two curves of the same class can be approximately equals, for comparison between different type of curves see isEquivalent
virtual bool isApprox (const curve_abc_t *other, const Numeric prec=Eigen::NumTraits< Numeric >::dummy_precision()) const
virtual bool operator== (const bezier_curve_t &other) const
virtual bool operator!= (const bezier_curve_t &other) const
bezier_curve_t compute_derivate (const std::size_t order) const
 Compute the derived curve at order N. Computes the derivative order N, $\frac{d^Nx(t)}{dt^N}$ of bezier curve of parametric equation x(t).
bezier_curve_tcompute_derivate_ptr (const std::size_t order) const
 Compute the derived curve at order N.
bezier_curve_t compute_primitive (const std::size_t order, const point_t &init) const
 Compute the primitive of the curve at order N. Computes the primitive at order N of bezier curve of parametric equation $x(t)$.
At order $N=1$, the primitve $X(t)$ of $x(t)$ is such as $\frac{dX(t)}{dt} = x(t)$.
bezier_curve_t compute_primitive (const std::size_t order) const
bezier_curve_tcompute_primitive_ptr (const std::size_t order, const point_t &init) const
bezier_curve_t elevate (const std::size_t order) const
 Computes a Bezier curve of order degrees higher than the current curve, but strictly equivalent. Order elevation is required for addition / substraction and other comparison operations.
void elevate_self (const std::size_t order)
 Elevate the Bezier curve of order degrees higher than the current curve, but strictly equivalent. Order elevation is required for addition / substraction and other comparison operations.
virtual point_t derivate (const time_t t, const std::size_t order) const
 Evaluate the derivative order N of curve at time t. If derivative is to be evaluated several times, it is rather recommended to compute derived curve using compute_derivate.
point_t evalBernstein (const Numeric t) const
 Evaluate all Bernstein polynomes for a certain degree. A bezier curve with N control points is represented by : $x(t) =
\sum_{i=0}^{N} B_i^N(t) P_i$ with $ B_i^N(t) = \binom{N}{i}t^i
(1-t)^{N-i} $.
Warning: the horner scheme is about 100 times faster than this method.
This method will probably be removed in the future as the computation of bernstein polynomial is very costly.
const point_t ndcurves::waypointAtIndex (const std::size_t index) const
point_t ndcurves::evalDeCasteljau (const Numeric t) const
 Evaluate the curve value at time t using deCasteljau algorithm. The algorithm will compute the $N-1$ centroids of parameters ${t,1-t}$ of consecutive $N$ control points of bezier curve, and perform it iteratively until getting one point in the list which will be the evaluation of bezier curve at time $t$.
t_point_t ndcurves::deCasteljauReduction (const Numeric t) const
t_point_t ndcurves::deCasteljauReduction (const t_point_t &pts, const Numeric u) const
 Compute de Casteljau's reduction of the given list of points at time t. For the list $pts$ of N points, compute a new list of points of size N-1 :
$<br>( pts[0]*(1-t)+pts[1], pts[1]*(1-t)+pts[2], ...,
pts[0]*(N-2)+pts[N-1] )$
with t the time when to evaluate bezier curve.
\ The new list contains centroid of parameters ${t,1-t}$ of consecutive points in the list.
std::pair< bezier_curve_t, bezier_curve_tndcurves::split (const Numeric t) const
 Split the bezier curve in 2 at time t.
piecewise_curve_t ndcurves::split (const vector_x_t &times) const
 Split the bezier curve in several curves, all accessible within a piecewise_curve_t.
bezier_curve_t ndcurves::extract (const Numeric t1, const Numeric t2)
 Extract a bezier curve defined between $[t_1,t_2]$ from the actual bezier curve defined between $[T_{min},T_{max}]$ with $T_{min} \leq t_1
       \leq t_2 \leq T_{max}$.
bezier_curve_t ndcurves::cross (const bezier_curve_t &g) const
 Compute the cross product of the current bezier curve by another bezier curve. The cross product p1Xp2 of 2 bezier curves p1 and p2 is defined such that forall t, p1Xp2(t) = p1(t) X p2(t), with X designing the cross product. This method of course only makes sense for dimension 3 curves. It assumes that a method point_t cross(const point_t&, const point_t&) has been defined.
bezier_curve_t ndcurves::cross (const bezier_curve_t::point_t &point) const
 Compute the cross product of the current bezier b by a point point. The cross product pXpoint of is defined such that forall t, bXpoint(t) = b(t) X point, with X designing the cross product. This method of course only makes sense for dimension 3 polynomials.
bezier_curve_tndcurves::operator+= (const bezier_curve_t &other)
bezier_curve_tndcurves::operator-= (const bezier_curve_t &other)
bezier_curve_tndcurves::operator+= (const bezier_curve_t::point_t &point)
bezier_curve_tndcurves::operator-= (const bezier_curve_t::point_t &point)
bezier_curve_tndcurves::operator/= (const double d)
bezier_curve_tndcurves::operator*= (const double d)
virtual std::size_t ndcurves::dim () const
 Get dimension of curve.
virtual time_t ndcurves::min () const
 Get the minimum time for which the curve is defined.
virtual time_t ndcurves::max () const
 Get the maximum time for which the curve is defined.
virtual std::size_t ndcurves::degree () const
 Get the degree of the curve.
template<class Archive>
void ndcurves::serialize (Archive &ar, const unsigned int version)
template<typename T, typename N, bool S, typename P>
bezier_curve< T, N, S, P > operator+ (const bezier_curve< T, N, S, P > &p1, const bezier_curve< T, N, S, P > &p2)
template<typename T, typename N, bool S, typename P>
bezier_curve< T, N, S, P > operator- (const bezier_curve< T, N, S, P > &p1)
template<typename T, typename N, bool S, typename P>
bezier_curve< T, N, S, P > operator- (const bezier_curve< T, N, S, P > &p1, const bezier_curve< T, N, S, P > &p2)
template<typename T, typename N, bool S, typename P>
bezier_curve< T, N, S, P > operator- (const bezier_curve< T, N, S, P > &p1, const typename bezier_curve< T, N, S, P >::point_t &point)
template<typename T, typename N, bool S, typename P>
bezier_curve< T, N, S, P > operator- (const typename bezier_curve< T, N, S, P >::point_t &point, const bezier_curve< T, N, S, P > &p1)
template<typename T, typename N, bool S, typename P>
bezier_curve< T, N, S, P > operator+ (const bezier_curve< T, N, S, P > &p1, const typename bezier_curve< T, N, S, P >::point_t &point)
template<typename T, typename N, bool S, typename P>
bezier_curve< T, N, S, P > operator+ (const typename bezier_curve< T, N, S, P >::point_t &point, const bezier_curve< T, N, S, P > &p1)
template<typename T, typename N, bool S, typename P>
bezier_curve< T, N, S, P > operator/ (const bezier_curve< T, N, S, P > &p1, const double k)
template<typename T, typename N, bool S, typename P>
bezier_curve< T, N, S, P > operator* (const bezier_curve< T, N, S, P > &p1, const double k)
template<typename T, typename N, bool S, typename P>
bezier_curve< T, N, S, P > operator* (const double k, const bezier_curve< T, N, S, P > &p1)

Variables

std::size_t ndcurves::dim_
 Dim of curve.
time_t ndcurves::T_min_
time_t ndcurves::T_max_
time_t ndcurves::mult_T_
std::size_t ndcurves::size_
std::size_t ndcurves::degree_
std::vector< Bern< Numeric > > ndcurves::bernstein_
t_point_t ndcurves::control_points_

Detailed Description

class allowing to create a Bezier curve of dimension 1 <= n <= 3.

Author
Steve T.
Version
0.1
Date
06/17/2013

Typedef Documentation

◆ bezier_curve_ptr_t

typedef std::shared_ptr<bezier_curve_t> bezier_curve_ptr_t

◆ bezier_curve_t

typedef bezier_curve<Time, Numeric, Safe, Point> bezier_curve_t

◆ cit_point_t

typedef t_point_t::const_iterator cit_point_t

◆ curve_abc_t

typedef curve_abc<Time, Numeric, Safe, point_t> curve_abc_t

◆ curve_constraints_t

typedef curve_constraints<point_t> curve_constraints_t

◆ curve_ptr_t

typedef curve_abc_t::curve_ptr_t curve_ptr_t

◆ num_t

typedef Numeric num_t

◆ piecewise_curve_t

typedef piecewise_curve<Time, Numeric, Safe, point_t, point_t, bezier_curve_t> piecewise_curve_t

◆ point_t

typedef Point point_t

◆ t_point_t

typedef std::vector<point_t, Eigen::aligned_allocator<point_t> > t_point_t

◆ time_t

typedef Time time_t

◆ vector_x_ref_t

typedef Eigen::Ref<const vector_x_t> vector_x_ref_t

◆ vector_x_t

typedef Eigen::Matrix<Numeric, Eigen::Dynamic, 1> vector_x_t

Function Documentation

◆ bezier_curve() [1/4]

waypoints::bezier_curve ( )

Empty constructor. Curve obtained this way can not perform other class functions.

◆ bezier_curve() [2/4]

waypoints::bezier_curve ( const bezier_curve & other)

◆ bezier_curve() [3/4]

template<typename In>
waypoints::bezier_curve ( In PointsBegin,
In PointsEnd,
const curve_constraints_t & constraints,
const time_t T_min = 0.,
const time_t T_max = 1.,
const time_t mult_T = 1. )

Constructor with constraints. This constructor will add 4 points (2 after the first one, 2 before the last one) to ensure that velocity and acceleration constraints are respected.

Parameters
PointsBegin: an iterator pointing to the first element of a control point container.
PointsEnd: an iterator pointing to the last element of a control point container.
constraints: constraints applying on start / end velocities and acceleration.
T_min: lower bound of time, curve will be defined for time in [T_min, T_max].
T_max: upper bound of time, curve will be defined for time in [T_min, T_max].
mult_T: ... (default value is 1.0).

◆ bezier_curve() [4/4]

template<typename In>
waypoints::bezier_curve ( In PointsBegin,
In PointsEnd,
const time_t T_min = 0.,
const time_t T_max = 1.,
const time_t mult_T = 1. )

Constructor. Given the first and last point of a control points set, create the bezier curve.

Parameters
PointsBegin: an iterator pointing to the first element of a control point container.
PointsEnd: an iterator pointing to the last element of a control point container.
T_min: lower bound of time, curve will be defined for time in [T_min, T_max].
T_max: upper bound of time, curve will be defined for time in [T_min, T_max].
mult_T: ... (default value is 1.0).

◆ compute_derivate()

bezier_curve_t waypoints::compute_derivate ( const std::size_t order) const

Compute the derived curve at order N. Computes the derivative order N, $\frac{d^Nx(t)}{dt^N}$ of bezier curve of parametric equation x(t).

Parameters
order: order of derivative.
Returns
$\frac{d^Nx(t)}{dt^N}$ derivative order N of the curve.

◆ compute_derivate_ptr()

bezier_curve_t * waypoints::compute_derivate_ptr ( const std::size_t order) const

Compute the derived curve at order N.

Parameters
order: order of derivative.
Returns
A pointer to $\frac{d^Nx(t)}{dt^N}$ derivative order N of the curve.

◆ compute_primitive() [1/2]

bezier_curve_t waypoints::compute_primitive ( const std::size_t order) const

◆ compute_primitive() [2/2]

bezier_curve_t waypoints::compute_primitive ( const std::size_t order,
const point_t & init ) const

Compute the primitive of the curve at order N. Computes the primitive at order N of bezier curve of parametric equation $x(t)$.
At order $N=1$, the primitve $X(t)$ of $x(t)$ is such as $\frac{dX(t)}{dt} = x(t)$.

Parameters
order: order of the primitive.
init: constant valuefor the first point of the primitive (can tipycally be zero)
Returns
primitive at order N of x(t).

◆ compute_primitive_ptr()

bezier_curve_t * waypoints::compute_primitive_ptr ( const std::size_t order,
const point_t & init ) const

◆ derivate()

virtual point_t waypoints::derivate ( const time_t t,
const std::size_t order ) const
virtual

Evaluate the derivative order N of curve at time t. If derivative is to be evaluated several times, it is rather recommended to compute derived curve using compute_derivate.

Parameters
order: order of derivative.
t: time when to evaluate the curve.
Returns
$\frac{d^Nx(t)}{dt^N}$ point corresponding on derived curve of order N at time t.

◆ elevate()

bezier_curve_t waypoints::elevate ( const std::size_t order) const

Computes a Bezier curve of order degrees higher than the current curve, but strictly equivalent. Order elevation is required for addition / substraction and other comparison operations.

Parameters
order: number of order the curve must be updated
Returns
An equivalent Bezier, with one more degree.

◆ elevate_self()

void waypoints::elevate_self ( const std::size_t order)

Elevate the Bezier curve of order degrees higher than the current curve, but strictly equivalent. Order elevation is required for addition / substraction and other comparison operations.

Parameters
order: number of order the curve must be updated

◆ evalBernstein()

point_t waypoints::evalBernstein ( const Numeric t) const

Evaluate all Bernstein polynomes for a certain degree. A bezier curve with N control points is represented by : $x(t) =
\sum_{i=0}^{N} B_i^N(t) P_i$ with $ B_i^N(t) = \binom{N}{i}t^i
(1-t)^{N-i} $.
Warning: the horner scheme is about 100 times faster than this method.
This method will probably be removed in the future as the computation of bernstein polynomial is very costly.

Parameters
t: time when to evaluate the curve.
Returns
$x(t)$ point corresponding on curve at time t.

◆ isApprox() [1/2]

bool waypoints::isApprox ( const bezier_curve_t & other,
const Numeric prec = Eigen::NumTraits<Numeric>::dummy_precision() ) const

isApprox check if other and *this are approximately equals. Only two curves of the same class can be approximately equals, for comparison between different type of curves see isEquivalent

Parameters
otherthe other curve to check
precthe precision threshold, default Eigen::NumTraits<Numeric>::dummy_precision()
Returns
true if the two curves are approximately equals

◆ isApprox() [2/2]

virtual bool waypoints::isApprox ( const curve_abc_t * other,
const Numeric prec = Eigen::NumTraits<Numeric>::dummy_precision() ) const
virtual

◆ operator!=()

virtual bool waypoints::operator!= ( const bezier_curve_t & other) const
virtual

◆ operator()()

virtual point_t waypoints::operator() ( const time_t t) const
virtual

Evaluation of the bezier curve at time t.

Parameters
t: time when to evaluate the curve.
Returns
$x(t)$ point corresponding on curve at time t.

◆ operator*() [1/2]

template<typename T, typename N, bool S, typename P>
bezier_curve< T, N, S, P > operator* ( const bezier_curve< T, N, S, P > & p1,
const double k )

◆ operator*() [2/2]

template<typename T, typename N, bool S, typename P>
bezier_curve< T, N, S, P > operator* ( const double k,
const bezier_curve< T, N, S, P > & p1 )

◆ operator+() [1/3]

template<typename T, typename N, bool S, typename P>
bezier_curve< T, N, S, P > operator+ ( const bezier_curve< T, N, S, P > & p1,
const bezier_curve< T, N, S, P > & p2 )

◆ operator+() [2/3]

template<typename T, typename N, bool S, typename P>
bezier_curve< T, N, S, P > operator+ ( const bezier_curve< T, N, S, P > & p1,
const typename bezier_curve< T, N, S, P >::point_t & point )

◆ operator+() [3/3]

template<typename T, typename N, bool S, typename P>
bezier_curve< T, N, S, P > operator+ ( const typename bezier_curve< T, N, S, P >::point_t & point,
const bezier_curve< T, N, S, P > & p1 )

◆ operator-() [1/4]

template<typename T, typename N, bool S, typename P>
bezier_curve< T, N, S, P > operator- ( const bezier_curve< T, N, S, P > & p1)

◆ operator-() [2/4]

template<typename T, typename N, bool S, typename P>
bezier_curve< T, N, S, P > operator- ( const bezier_curve< T, N, S, P > & p1,
const bezier_curve< T, N, S, P > & p2 )

◆ operator-() [3/4]

template<typename T, typename N, bool S, typename P>
bezier_curve< T, N, S, P > operator- ( const bezier_curve< T, N, S, P > & p1,
const typename bezier_curve< T, N, S, P >::point_t & point )

◆ operator-() [4/4]

template<typename T, typename N, bool S, typename P>
bezier_curve< T, N, S, P > operator- ( const typename bezier_curve< T, N, S, P >::point_t & point,
const bezier_curve< T, N, S, P > & p1 )

◆ operator/()

template<typename T, typename N, bool S, typename P>
bezier_curve< T, N, S, P > operator/ ( const bezier_curve< T, N, S, P > & p1,
const double k )

◆ operator==()

virtual bool waypoints::operator== ( const bezier_curve_t & other) const
virtual

◆ ~bezier_curve()

virtual waypoints::~bezier_curve ( )
virtual

Destructor.