1 #ifndef _CLASS_CURVE_CONVERSION 2 #define _CLASS_CURVE_CONVERSION 19 template <
typename Polynomial>
21 typedef typename Polynomial::t_point_t t_point_t;
22 typedef typename Polynomial::num_t num_t;
23 t_point_t coefficients;
24 coefficients.push_back(curve(curve.min()));
26 for (std::size_t i = 1; i <= curve.degree(); ++i) {
28 coefficients.push_back(curve.derivate(curve.min(), i) / fact);
31 return Polynomial(coefficients, curve.min(), curve.max());
37 template <
typename Bezier>
39 if(curve.degree() > 3)
40 throw std::invalid_argument(
"bezier_from_curve is only implemented for curves of degree <= 3.");
41 typedef typename Bezier::point_t point_t;
42 typedef typename Bezier::t_point_t t_point_t;
43 typedef typename Bezier::num_t num_t;
44 num_t T_min = curve.min();
45 num_t T_max = curve.max();
46 num_t T = T_max - T_min;
48 point_t p0 = curve(T_min);
49 point_t p1 = curve(T_max);
50 point_t m0 = curve.derivate(T_min, 1);
51 point_t m1 = curve.derivate(T_max, 1);
58 point_t b_p1 = T * m0 / 3 + b_p0;
59 point_t b_p2 = -T * m1 / 3 + b_p3;
60 t_point_t control_points;
61 control_points.push_back(b_p0);
62 control_points.push_back(b_p1);
63 control_points.push_back(b_p2);
64 control_points.push_back(b_p3);
65 return Bezier(control_points.begin(), control_points.end(), curve.min(), curve.max());
71 template <
typename Hermite>
73 if(curve.degree() > 3)
74 throw std::invalid_argument(
"hermite_from_curve is only implemented for curves of degree <= 3.");
75 typedef typename Hermite::pair_point_tangent_t pair_point_tangent_t;
76 typedef typename Hermite::t_pair_point_tangent_t t_pair_point_tangent_t;
77 typedef typename Hermite::point_t point_t;
78 typedef typename Hermite::num_t num_t;
79 num_t T_min = curve.min();
80 num_t T_max = curve.max();
82 point_t p0 = curve(T_min);
83 point_t p1 = curve(T_max);
84 point_t m0 = curve.derivate(T_min, 1);
85 point_t m1 = curve.derivate(T_max, 1);
87 pair_point_tangent_t pair0(p0, m0);
88 pair_point_tangent_t pair1(p1, m1);
89 t_pair_point_tangent_t control_points;
90 control_points.push_back(pair0);
91 control_points.push_back(pair1);
92 std::vector<double> time_control_points;
93 time_control_points.push_back(T_min);
94 time_control_points.push_back(T_max);
95 return Hermite(control_points.begin(), control_points.end(), time_control_points);
98 #endif //_CLASS_CURVE_CONVERSION 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:72
Definition: bernstein.h:20
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:20
interface for a Curve of arbitrary dimension.
curve_abc< double, double, true, pointX_t, pointX_t > curve_abc_t
Definition: fwd.h:73
struct to define constraints on start / end velocities and acceleration on a curve ...
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