31 A <<
power(v1.t, 3), v1.t * v1.t, v1.t, 1, 3 * v1.t * v1.t, 2 * v1.t, 1, 0,
32 power(v2.t, 3), v2.t * v2.t, v2.t, 1, 3 * v2.t * v2.t, 2 * v2.t, 1, 0;
34 b << v1.p, v1.v, v2.p, v2.v;
38 if (fabs(a(0)) < 1e-5) a(0) = 0;
39 if (fabs(a(1)) < 1e-5) a(1) = 0;
40 if (fabs(a(2)) < 1e-5) a(2) = 0;
41 if (fabs(a(3)) < 1e-5) a(3) = 0;
46 dT = getT(tf) - getT(ti);
52 vt.p = a(0) *
power(tau, 3) + a(1) * tau * tau + a(2) * tau + a(3);
53 vt.v = 3 * a(0) * tau * tau + 2 * a(1) * tau + a(2);
58 return a(0) / 4 *
power(t, 4) + a(1) / 3 *
power(t, 3) + a(2) / 2 * t * t +
77 Lambda(
const std::vector<VirtualPoint> &vs) {
78 for (
int i = 0; i < (int)vs.size() - 1; i++) {
84 bool exist()
const {
return !segs.empty(); }
86 std::vector<VirtualPoint> sample(
int N) {
88 std::vector<VirtualPoint> vs;
89 if (segs.empty())
return vs;
93 for (
decimal_t t = ti; t <= tf; t += dt) {
94 for (
const auto &seg : segs) {
95 if (t >= seg.ti && t < seg.tf) {
96 vs.push_back(seg.evaluate(t));
111 for (
decimal_t t = ti; t <= tf; t += dt) ts.push_back(
Vec3f(t, getT(t), 0));
118 for (
const auto &seg : segs) {
119 if (tau >= seg.ti && tau < seg.tf) {
120 vt = seg.evaluate(tau);
128 if (segs.empty())
return tau;
130 for (
const auto &seg : segs) {
131 if (tau >= seg.ti && tau <= seg.tf) {
132 T += seg.getT(tau) - seg.getT(seg.ti);
141 if (!exist())
return t;
143 for (
const auto &seg : segs) {
144 if (t >= T && t <= T + seg.dT) {
151 std::vector<decimal_t> ts =
solve(a, b, c, d, e);
152 for (
const auto &it : ts) {
153 if (it >= seg.ti && it <= seg.tf)
return it;
159 printf(
"error: cannot find tau, t = %f\n", t);
165 for (
const auto &seg : segs) t += seg.dT;
170 std::vector<LambdaSeg> segs;
piecewise polynomial for scaling trajectory
Definition: lambda.h:73
Vec4f a
a3, a2, a1, a0
Definition: lambda.h:62
decimal_t power(decimal_t t, int n)
Return .
Definition: math.h:197
std::vector< decimal_t > solve(decimal_t a, decimal_t b, decimal_t c, decimal_t d, decimal_t e)
General solver for .
Definition: math.h:117
Vecf< 3 > Vec3f
Eigen 1D float vector of size 3.
Definition: data_type.h:80
Matf< 4, 4 > Mat4f
4x4 Matrix in float
Definition: data_type.h:102
double decimal_t
Rename the float type used in lib.
Definition: data_type.h:49
Defines all data types used in this lib.
Used for scaling, ignored for most case.
Definition: lambda.h:16
Vecf< 4 > Vec4f
Eigen 1D float vector of size 4.
Definition: data_type.h:84
polynomial between two virtual points
Definition: lambda.h:25
vec_E< Vec3f > vec_Vec3f
Vector of type Vec3f.
Definition: data_type.h:93