38 #ifndef FCL_CCD_SPLINEMOTION_INL_H 39 #define FCL_CCD_SPLINEMOTION_INL_H 41 #include "fcl/math/motion/spline_motion.h" 48 class SplineMotion<double>;
53 const Vector3<S>& Td0,
const Vector3<S>& Td1,
const Vector3<S>& Td2,
const Vector3<S>& Td3,
54 const Vector3<S>& Rd0,
const Vector3<S>& Rd1,
const Vector3<S>& Rd2,
const Vector3<S>& Rd3)
67 Rd0Rd0 = Rd[0].dot(Rd[0]);
68 Rd0Rd1 = Rd[0].dot(Rd[1]);
69 Rd0Rd2 = Rd[0].dot(Rd[2]);
70 Rd0Rd3 = Rd[0].dot(Rd[3]);
71 Rd1Rd1 = Rd[1].dot(Rd[1]);
72 Rd1Rd2 = Rd[1].dot(Rd[2]);
73 Rd1Rd3 = Rd[1].dot(Rd[3]);
74 Rd2Rd2 = Rd[2].dot(Rd[2]);
75 Rd2Rd3 = Rd[2].dot(Rd[3]);
76 Rd3Rd3 = Rd[3].dot(Rd[3]);
78 TA = Td[1] * 3 - Td[2] * 3 + Td[3] - Td[0];
79 TB = (Td[0] - Td[1] * 2 + Td[2]) * 3;
80 TC = (Td[2] - Td[0]) * 3;
82 RA = Rd[1] * 3 - Rd[2] * 3 + Rd[3] - Rd[0];
83 RB = (Rd[0] - Rd[1] * 2 + Rd[2]) * 3;
84 RC = (Rd[2] - Rd[0]) * 3;
92 const Matrix3<S>& R1,
const Vector3<S>& T1,
93 const Matrix3<S>& R2,
const Vector3<S>& T2)
100 template <
typename S>
102 const Transform3<S>& tf1,
const Transform3<S>& tf2)
109 template <
typename S>
114 Vector3<S> cur_T = Td[0] * getWeight0(dt) + Td[1] * getWeight1(dt) + Td[2] * getWeight2(dt) + Td[3] * getWeight3(dt);
115 Vector3<S> cur_w = Rd[0] * getWeight0(dt) + Rd[1] * getWeight1(dt) + Rd[2] * getWeight2(dt) + Rd[3] * getWeight3(dt);
116 S cur_angle = cur_w.norm();
119 tf.linear() = AngleAxis<S>(cur_angle, cur_w).toRotationMatrix();
120 tf.translation() = cur_T;
128 template <
typename S>
131 return mb_visitor.visit(*
this);
135 template <
typename S>
138 return mb_visitor.visit(*
this);
142 template <
typename S>
149 template <
typename S>
154 c[0] = (Td[0] + Td[1] * 4 + Td[2] + Td[3]) * (1/6.0);
155 c[1] = (-Td[0] + Td[2]) * (1/2.0);
156 c[2] = (Td[0] - Td[1] * 2 + Td[2]) * (1/2.0);
157 c[3] = (-Td[0] + Td[1] * 3 - Td[2] * 3 + Td[3]) * (1/6.0);
158 tv.setTimeInterval(this->getTimeInterval());
159 for(std::size_t i = 0; i < 3; ++i)
161 for(std::size_t j = 0; j < 4; ++j)
163 tv[i].coeff(j) = c[j][i];
168 Matrix3<S> I = Matrix3<S>::Identity();
171 Vector3<S> Rt0 = (Rd[0] + Rd[1] * 23 + Rd[2] * 23 + Rd[3]) * (1 / 48.0);
172 S Rt0_len = Rt0.norm();
173 S inv_Rt0_len = 1.0 / Rt0_len;
174 S inv_Rt0_len_3 = inv_Rt0_len * inv_Rt0_len * inv_Rt0_len;
175 S inv_Rt0_len_5 = inv_Rt0_len_3 * inv_Rt0_len * inv_Rt0_len;
177 S costheta0 = cos(theta0);
178 S sintheta0 = sin(theta0);
180 Vector3<S> Wt0 = Rt0 * inv_Rt0_len;
183 Matrix3<S> hatWt0_sqr = hatWt0 * hatWt0;
184 Matrix3<S> Mt0 = I + hatWt0 * sintheta0 + hatWt0_sqr * (1 - costheta0);
188 Vector3<S> dRt0 = (-Rd[0] - Rd[1] * 5 + Rd[2] * 5 + Rd[3]) * (1 / 8.0);
189 S Rt0_dot_dRt0 = Rt0.dot(dRt0);
190 S dtheta0 = Rt0_dot_dRt0 * inv_Rt0_len;
191 Vector3<S> dWt0 = dRt0 * inv_Rt0_len - Rt0 * (Rt0_dot_dRt0 * inv_Rt0_len_3);
194 Matrix3<S> dMt0 = hatdWt0 * sintheta0 + hatWt0 * (costheta0 * dtheta0) + hatWt0_sqr * (sintheta0 * dtheta0) + (hatWt0 * hatdWt0 + hatdWt0 * hatWt0) * (1 - costheta0);
197 Vector3<S> ddRt0 = (Rd[0] - Rd[1] - Rd[2] + Rd[3]) * 0.5;
198 S Rt0_dot_ddRt0 = Rt0.dot(ddRt0);
199 S dRt0_dot_dRt0 = dRt0.squaredNorm();
200 S ddtheta0 = (Rt0_dot_ddRt0 + dRt0_dot_dRt0) * inv_Rt0_len - Rt0_dot_dRt0 * Rt0_dot_dRt0 * inv_Rt0_len_3;
201 Vector3<S> ddWt0 = ddRt0 * inv_Rt0_len - (dRt0 * (2 * Rt0_dot_dRt0) + Rt0 * (Rt0_dot_ddRt0 + dRt0_dot_dRt0)) * inv_Rt0_len_3 + (Rt0 * (3 * Rt0_dot_dRt0 * Rt0_dot_dRt0)) * inv_Rt0_len_5;
203 hat(hatddWt0, ddWt0);
205 hatddWt0 * sintheta0 +
206 hatWt0 * (costheta0 * dtheta0 - sintheta0 * dtheta0 * dtheta0 + costheta0 * ddtheta0) +
207 hatdWt0 * (costheta0 * dtheta0) +
208 (hatWt0 * hatdWt0 + hatdWt0 * hatWt0) * (sintheta0 * dtheta0 * 2) +
209 hatdWt0 * hatdWt0 * (2 * (1 - costheta0)) +
210 hatWt0 * hatWt0 * (costheta0 * dtheta0 * dtheta0 + sintheta0 * ddtheta0) +
211 (hatWt0 * hatddWt0 + hatddWt0 + hatWt0) * (1 - costheta0);
213 tm.setTimeInterval(this->getTimeInterval());
214 for(std::size_t i = 0; i < 3; ++i)
216 for(std::size_t j = 0; j < 3; ++j)
218 tm(i, j).coeff(0) = Mt0(i, j) - dMt0(i, j) * 0.5 + ddMt0(i, j) * 0.25 * 0.5;
219 tm(i, j).coeff(1) = dMt0(i, j) - ddMt0(i, j) * 0.5;
220 tm(i, j).coeff(2) = ddMt0(i, j) * 0.5;
221 tm(i, j).coeff(3) = 0;
223 tm(i, j).remainder() =
Interval<S>(-1/48.0, 1/48.0);
229 template <
typename S>
236 template <
typename S>
243 std::vector<S> T_potential;
244 T_potential.push_back(
tf_t);
245 T_potential.push_back(1);
246 if(Tb * Tb - 3 * Ta * Tc >= 0)
252 S tmp = -Tc / (2 * Tb);
253 if(tmp < 1 && tmp >
tf_t)
254 T_potential.push_back(tmp);
259 S tmp_delta = sqrt(Tb * Tb - 3 * Ta * Tc);
260 S tmp1 = (-Tb + tmp_delta) / (3 * Ta);
261 S tmp2 = (-Tb - tmp_delta) / (3 * Ta);
262 if(tmp1 < 1 && tmp1 >
tf_t)
263 T_potential.push_back(tmp1);
264 if(tmp2 < 1 && tmp2 > tf_t)
265 T_potential.push_back(tmp2);
269 S T_bound = Ta * T_potential[0] * T_potential[0] * T_potential[0] + Tb * T_potential[0] * T_potential[0] + Tc * T_potential[0];
270 for(
unsigned int i = 1; i < T_potential.size(); ++i)
272 S T_bound_tmp = Ta * T_potential[i] * T_potential[i] * T_potential[i] + Tb * T_potential[i] * T_potential[i] + Tc * T_potential[i];
273 if(T_bound_tmp > T_bound) T_bound = T_bound_tmp;
279 T_bound -= cur_delta;
286 template <
typename S>
290 int a00[5] = {1,-4,6,-4,1};
291 int a01[5] = {-3,10,-11,4,0};
292 int a02[5] = {3,-8,6,0,-1};
293 int a03[5] = {-1,2,-1,0,0};
294 int a11[5] = {9,-24,16,0,0};
295 int a12[5] = {-9,18,-5,-4,0};
296 int a13[5] = {3,-4,0,0,0};
297 int a22[5] = {9,-12,-2,4,1};
298 int a23[5] = {-3,2,1,0,0};
299 int a33[5] = {1,0,0,0,0};
303 for(
int i = 0; i < 5; ++i)
305 a[i] = Rd0Rd0 * a00[i] + Rd0Rd1 * a01[i] + Rd0Rd2 * a02[i] + Rd0Rd3 * a03[i]
306 + Rd0Rd1 * a01[i] + Rd1Rd1 * a11[i] + Rd1Rd2 * a12[i] + Rd1Rd3 * a13[i]
307 + Rd0Rd2 * a02[i] + Rd1Rd2 * a12[i] + Rd2Rd2 * a22[i] + Rd2Rd3 * a23[i]
308 + Rd0Rd3 * a03[i] + Rd1Rd3 * a13[i] + Rd2Rd3 * a23[i] + Rd3Rd3 * a33[i];
313 int da00[4] = {4,-12,12,-4};
314 int da01[4] = {-12,30,-22,4};
315 int da02[4] = {12,-24,12,0};
316 int da03[4] = {-4,6,-2,0};
317 int da11[4] = {36,-72,32,0};
318 int da12[4] = {-36,54,-10,-4};
319 int da13[4] = {12,-12,0,0};
320 int da22[4] = {36,-36,-4,4};
321 int da23[4] = {-12,6,2,0};
322 int da33[4] = {4,0,0,0};
325 for(
int i = 0; i < 4; ++i)
327 da[i] = Rd0Rd0 * da00[i] + Rd0Rd1 * da01[i] + Rd0Rd2 * da02[i] + Rd0Rd3 * da03[i]
328 + Rd0Rd1 * da01[i] + Rd1Rd1 * da11[i] + Rd1Rd2 * da12[i] + Rd1Rd3 * da13[i]
329 + Rd0Rd2 * da02[i] + Rd1Rd2 * da12[i] + Rd2Rd2 * da22[i] + Rd2Rd3 * da23[i]
330 + Rd0Rd3 * da03[i] + Rd1Rd3 * da13[i] + Rd2Rd3 * da23[i] + Rd3Rd3 * da33[i];
339 S dWdW_1 = a[0] + a[1] + a[2] + a[3] + a[4];
340 if(dWdW_max < dWdW_1) dWdW_max = dWdW_1;
341 for(
int i = 0; i < root_num; ++i)
345 if(v >=
tf_t && v <= 1)
347 S value = a[0] * v * v * v * v + a[1] * v * v * v + a[2] * v * v + a[3] * v + a[4];
348 if(value > dWdW_max) dWdW_max = value;
352 return sqrt(dWdW_max);
356 template <
typename S>
363 template <
typename S>
366 return (1 - 3 * t + 3 * t * t - t * t * t) / 6.0;
370 template <
typename S>
373 return (4 - 6 * t * t + 3 * t * t * t) / 6.0;
377 template <
typename S>
380 return (1 + 3 * t + 3 * t * t - 3 * t * t * t) / 6.0;
384 template <
typename S>
387 return t * t * t / 6.0;
bool integrate(S dt) const override
Integrate the motion from 0 to dt We compute the current transformation from zero point instead of fr...
Definition: spline_motion-inl.h:110
S tf_t
The time related with tf.
Definition: spline_motion.h:101
Definition: motion_base.h:52
Main namespace.
Definition: broadphase_bruteforce-inl.h:45
Definition: bv_motion_bound_visitor.h:48
S computeMotionBound(const BVMotionBoundVisitor< S > &mb_visitor) const override
Compute the motion bound for a bounding volume along a given direction n, which is defined in the vis...
Definition: spline_motion-inl.h:129
Interval class for [a, b].
Definition: interval.h:50
SplineMotion(const Vector3< S > &Td0, const Vector3< S > &Td1, const Vector3< S > &Td2, const Vector3< S > &Td3, const Vector3< S > &Rd0, const Vector3< S > &Rd1, const Vector3< S > &Rd2, const Vector3< S > &Rd3)
Construct motion from 4 deBoor points.
Definition: spline_motion-inl.h:52
static int solveCubic(S c[4], S s[3])
Solve a cubic function with coefficients c, return roots s and number of roots.
Definition: polysolver-inl.h:103
void getCurrentTransform(Transform3< S > &tf_) const override
Get the rotation and translation in current step.
Definition: spline_motion-inl.h:143
Definition: bv_motion_bound_visitor.h:45
Compute the motion bound for a bounding volume, given the closest direction n between two query objec...
Definition: bv_motion_bound_visitor.h:62
Definition: taylor_matrix.h:48
Definition: taylor_vector.h:48
void getTaylorModel(TMatrix3< S > &tm, TVector3< S > &tv) const override
Definition: spline_motion-inl.h:150