9 #ifndef _CLASS_BEZIERCURVE
10 #define _CLASS_BEZIERCURVE
18 #include "curve_abc.h"
19 #include "curve_constraint.h"
27 template <
typename Time = double,
typename Numeric =
Time, Eigen::Index Dim = 3,
28 bool Safe =
false,
typename Point = Eigen::Matrix<Numeric, Dim, 1> >
29 struct bezier_curve :
public curve_abc<Time, Numeric, Dim, Safe, Point> {
34 typedef std::vector<point_t, Eigen::aligned_allocator<point_t> >
t_point_t;
43 template <
typename In>
48 size_(std::distance(PointsBegin, PointsEnd)),
53 if (Safe && (size_ < 1 || minBound >= maxBound))
54 throw std::out_of_range(
55 "can't create bezier min bound is higher than max bound");
56 for (; it != PointsEnd; ++it) pts_.push_back(*it);
67 template <
typename In>
73 size_(std::distance(PointsBegin, PointsEnd) + 4),
76 if (Safe && (size_ < 1 || minBound >= maxBound))
77 throw std::out_of_range(
78 "can't create bezier min bound is higher than max bound");
80 add_constraints<In>(PointsBegin, PointsEnd, constraints);
81 for (
cit_point_t cit = updatedList.begin(); cit != updatedList.end(); ++cit)
102 if (Safe & !(0 <= nT && nT <= 1)) {
103 throw std::out_of_range(
104 "can't evaluate bezier curve, out of range");
111 return pts_[0] * dt + nT * pts_[1];
114 return pts_[0] * dt * dt + 2 * pts_[1] * nT * dt + pts_[2] * nT * nT;
117 return pts_[0] * dt * dt * dt + 3 * pts_[1] * nT * dt * dt +
118 3 * pts_[2] * nT * nT * dt + pts_[3] * nT * nT * nT;
130 if (order == 0)
return *
this;
132 for (
typename t_point_t::const_iterator pit = pts_.begin();
133 pit != pts_.end() - 1; ++pit)
134 derived_wp.push_back(
degree_ * (*(pit + 1) - (*pit)));
135 if (derived_wp.empty()) derived_wp.push_back(point_t::Zero());
145 if (order == 0)
return *
this;
148 point_t current_sum = point_t::Zero();
151 n_wp.push_back(current_sum);
152 for (
typename t_point_t::const_iterator pit = pts_.begin();
153 pit != pts_.end(); ++pit) {
155 n_wp.push_back(current_sum / new_degree);
177 typename t_point_t::const_iterator pts_it = pts_.begin();
178 for (
typename std::vector<
Bern<Numeric> >::const_iterator cit =
181 res += cit->operator()(u) * (*pts_it);
190 typename t_point_t::const_iterator pts_it = pts_.begin();
197 for (
int i = 1; i <
degree_; i++, ++pts_it) {
199 bc = bc * (
degree_ - i + 1) / i;
200 tmp = (tmp + tn * bc * (*pts_it)) * u;
202 return (tmp + tn * t * (*pts_it));
208 template <
typename In>
209 t_point_t add_constraints(In PointsBegin, In PointsEnd,
212 point_t P0, P1, P2, P_n_2, P_n_1, PN;
214 PN = *(PointsEnd - 1);
215 P1 = P0 + constraints.init_vel /
degree_;
216 P_n_1 = PN - constraints.end_vel /
degree_;
217 P2 = constraints.init_acc / (
degree_ * (
degree_ - 1)) + 2 * P1 - P0;
218 P_n_2 = constraints.end_acc / (
degree_ * (
degree_ - 1)) + 2 * P_n_1 - PN;
224 for (In it = PointsBegin + 1; it != PointsEnd - 1; ++it) res.push_back(*it);
226 res.push_back(P_n_2);
227 res.push_back(P_n_1);
double Time
Definition: effector_spline.h:27
Eigen::Matrix< Numeric, 3, 1 > Point
Definition: effector_spline.h:28
double Numeric
Definition: effector_spline.h:26
Definition: bernstein.h:20
std::vector< Bern< Numeric > > makeBernstein(const unsigned int n)
Computes all Bernstein polynomes for a certain degree.
Definition: bernstein.h:62
Definition: bernstein.h:42
Definition: bezier_curve.h:29
const time_t minBound_
Definition: bezier_curve.h:241
bezier_curve(In PointsBegin, In PointsEnd, const time_t minBound=0, const time_t maxBound=1)
Constructor.
Definition: bezier_curve.h:44
~bezier_curve()
Destructor.
Definition: bezier_curve.h:86
bezier_curve_t compute_derivate(const std::size_t order) const
Computes the derivative curve at order N.
Definition: bezier_curve.h:129
t_point_t::const_iterator cit_point_t
Definition: bezier_curve.h:35
const t_point_t & waypoints() const
Definition: bezier_curve.h:205
point_t evalBernstein(const Numeric u) const
Evaluates all Bernstein polynomes for a certain degree.
Definition: bezier_curve.h:175
Time time_t
Definition: bezier_curve.h:31
const std::size_t degree_
Definition: bezier_curve.h:243
Numeric num_t
Definition: bezier_curve.h:32
point_t evalHorner(const Numeric t) const
Evaluates all Bernstein polynomes for a certain degree using horner's scheme.
Definition: bezier_curve.h:189
virtual point_t operator()(const time_t t) const
Evaluation of the cubic spline at time t.
Definition: bezier_curve.h:100
std::vector< point_t, Eigen::aligned_allocator< point_t > > t_point_t
Definition: bezier_curve.h:34
curve_constraints< point_t > curve_constraints_t
Definition: bezier_curve.h:33
bezier_curve(In PointsBegin, In PointsEnd, const curve_constraints_t &constraints, const time_t minBound=0, const time_t maxBound=1)
Constructor This constructor will add 4 points (2 after the first one, 2 before the last one) to ensu...
Definition: bezier_curve.h:68
virtual time_t max() const
Definition: bezier_curve.h:237
const time_t maxBound_
Definition: bezier_curve.h:241
virtual time_t min() const
Definition: bezier_curve.h:236
bezier_curve_t compute_primitive(const std::size_t order) const
Computes the primitive of the curve at order N.
Definition: bezier_curve.h:144
Point point_t
Definition: bezier_curve.h:30
const std::size_t size_
Definition: bezier_curve.h:242
virtual point_t derivate(const time_t t, const std::size_t order) const
Evaluates the derivative at order N of the curve. If the derivative is to be evaluated several times,...
Definition: bezier_curve.h:167
bezier_curve< Time, Numeric, Dim, Safe, Point > bezier_curve_t
Definition: bezier_curve.h:36
const std::vector< Bern< Numeric > > bernstein_
Definition: bezier_curve.h:244