1 #ifndef _CLASS_CURVE_CONVERSION
2 #define _CLASS_CURVE_CONVERSION
17 template <
typename Polynomial>
20 typedef typename Polynomial::t_point_t t_point_t;
21 typedef typename Polynomial::num_t num_t;
22 t_point_t coefficients;
23 coefficients.push_back(curve(curve.min()));
25 for (std::size_t i = 1; i <= curve.degree(); ++i) {
27 coefficients.push_back(curve.derivate(curve.min(), i) / fact);
30 return Polynomial(coefficients, curve.min(), curve.max());
37 template <
typename Bezier>
39 if (curve.degree() > 3)
40 throw std::invalid_argument(
41 "bezier_from_curve is only implemented for curves of degree <= 3.");
42 typedef typename Bezier::point_t point_t;
43 typedef typename Bezier::t_point_t t_point_t;
44 typedef typename Bezier::num_t num_t;
45 num_t T_min = curve.min();
46 num_t T_max = curve.max();
47 num_t T = T_max - T_min;
49 point_t p0 = curve(T_min);
50 point_t p1 = curve(T_max);
51 point_t m0 = curve.derivate(T_min, 1);
52 point_t m1 = curve.derivate(T_max, 1);
59 point_t b_p1 = T * m0 / 3 + b_p0;
60 point_t b_p2 = -T * m1 / 3 + b_p3;
61 t_point_t control_points;
62 control_points.push_back(b_p0);
63 control_points.push_back(b_p1);
64 control_points.push_back(b_p2);
65 control_points.push_back(b_p3);
66 return Bezier(control_points.begin(), control_points.end(), curve.min(),
74 template <
typename Hermite>
76 if (curve.degree() > 3)
77 throw std::invalid_argument(
78 "hermite_from_curve is only implemented for curves of degree <= 3.");
79 typedef typename Hermite::pair_point_tangent_t pair_point_tangent_t;
80 typedef typename Hermite::t_pair_point_tangent_t t_pair_point_tangent_t;
81 typedef typename Hermite::point_t point_t;
82 typedef typename Hermite::num_t num_t;
83 num_t T_min = curve.min();
84 num_t T_max = curve.max();
86 point_t p0 = curve(T_min);
87 point_t p1 = curve(T_max);
88 point_t m0 = curve.derivate(T_min, 1);
89 point_t m1 = curve.derivate(T_max, 1);
91 pair_point_tangent_t pair0(p0, m0);
92 pair_point_tangent_t pair1(p1, m1);
93 t_pair_point_tangent_t control_points;
94 control_points.push_back(pair0);
95 control_points.push_back(pair1);
96 std::vector<double> time_control_points;
97 time_control_points.push_back(T_min);
98 time_control_points.push_back(T_max);
99 return Hermite(control_points.begin(), control_points.end(),
100 time_control_points);
interface for a Curve of arbitrary dimension.
struct to define constraints on start / end velocities and acceleration on a curve
Definition: bernstein.h:20
curve_abc< double, double, true, pointX_t, pointX_t > curve_abc_t
Definition: fwd.h:85
Hermite hermite_from_curve(const typename Hermite::curve_abc_t &curve)
Converts a polynomial of order 3 or less/cubic bezier curve to a cubic hermite spline.
Definition: curve_conversion.h:75
Bezier bezier_from_curve(const typename Bezier::curve_abc_t &curve)
Converts a cubic hermite spline or polynomial of order 3 or less to a cubic bezier curve.
Definition: curve_conversion.h:38
Polynomial polynomial_from_curve(const typename Polynomial::curve_abc_t &curve)
Converts a cubic hermite spline or a bezier curve to a polynomial.
Definition: curve_conversion.h:18