69 FCL_REAL denom = 1 - A_dot_B * A_dot_B;
74 t = (A_dot_T - B_dot_T * A_dot_B) / denom;
78 u =
t * A_dot_B - B_dot_T;
85 t = u * A_dot_B + A_dot_T;
98 if (fabs(Anorm_dot_B) < 1e-7)
return false;
102 u = -Anorm_dot_T / Anorm_dot_B;
105 t = u * A_dot_B + A_dot_T;
108 v =
t * A_dot_B - B_dot_T;
110 if (Anorm_dot_B > 0) {
111 if (
v > (u + 1e-7))
return true;
113 if (
v < (u - 1e-7))
return true;
124 FCL_REAL A0_dot_B0, A0_dot_B1, A1_dot_B0, A1_dot_B1;
126 A0_dot_B0 = Rab(0, 0);
127 A0_dot_B1 = Rab(0, 1);
128 A1_dot_B0 = Rab(1, 0);
129 A1_dot_B1 = Rab(1, 1);
131 FCL_REAL aA0_dot_B0, aA0_dot_B1, aA1_dot_B0, aA1_dot_B1;
132 FCL_REAL bA0_dot_B0, bA0_dot_B1, bA1_dot_B0, bA1_dot_B1;
134 aA0_dot_B0 =
a[0] * A0_dot_B0;
135 aA0_dot_B1 =
a[0] * A0_dot_B1;
136 aA1_dot_B0 =
a[1] * A1_dot_B0;
137 aA1_dot_B1 =
a[1] * A1_dot_B1;
138 bA0_dot_B0 =
b[0] * A0_dot_B0;
139 bA1_dot_B0 =
b[0] * A1_dot_B0;
140 bA0_dot_B1 =
b[1] * A0_dot_B1;
141 bA1_dot_B1 =
b[1] * A1_dot_B1;
143 Vec3f Tba(Rab.transpose() * Tab);
150 FCL_REAL ALL_x, ALU_x, AUL_x, AUU_x;
151 FCL_REAL BLL_x, BLU_x, BUL_x, BUU_x;
152 FCL_REAL LA1_lx, LA1_ux, UA1_lx, UA1_ux, LB1_lx, LB1_ux, UB1_lx, UB1_ux;
155 ALU_x = ALL_x + aA1_dot_B0;
156 AUL_x = ALL_x + aA0_dot_B0;
157 AUU_x = ALU_x + aA0_dot_B0;
172 BLU_x = BLL_x + bA0_dot_B1;
173 BUL_x = BLL_x + bA0_dot_B0;
174 BUU_x = BLU_x + bA0_dot_B0;
190 if ((UA1_ux >
b[0]) && (UB1_ux >
a[0])) {
191 if (((UA1_lx >
b[0]) ||
192 inVoronoi(
b[1],
a[1], A1_dot_B0, aA0_dot_B0 -
b[0] - Tba[0], A1_dot_B1,
193 aA0_dot_B1 - Tba[1], -Tab[1] - bA1_dot_B0)) &&
195 inVoronoi(
a[1],
b[1], A0_dot_B1, Tab[0] + bA0_dot_B0 -
a[0], A1_dot_B1,
196 Tab[1] + bA1_dot_B0, Tba[1] - aA0_dot_B1))) {
197 segCoords(
t, u,
a[1],
b[1], A1_dot_B1, Tab[1] + bA1_dot_B0,
198 Tba[1] - aA0_dot_B1);
200 S[0] = Tab[0] + Rab(0, 0) *
b[0] + Rab(0, 1) * u -
a[0];
201 S[1] = Tab[1] + Rab(1, 0) *
b[0] + Rab(1, 1) * u -
t;
202 S[2] = Tab[2] + Rab(2, 0) *
b[0] + Rab(2, 1) * u;
215 if ((UA1_lx < 0) && (LB1_ux >
a[0])) {
216 if (((UA1_ux < 0) ||
inVoronoi(
b[1],
a[1], -A1_dot_B0, Tba[0] - aA0_dot_B0,
217 A1_dot_B1, aA0_dot_B1 - Tba[1], -Tab[1])) &&
219 inVoronoi(
a[1],
b[1], A0_dot_B1, Tab[0] -
a[0], A1_dot_B1, Tab[1],
220 Tba[1] - aA0_dot_B1))) {
221 segCoords(
t, u,
a[1],
b[1], A1_dot_B1, Tab[1], Tba[1] - aA0_dot_B1);
223 S[0] = Tab[0] + Rab(0, 1) * u -
a[0];
224 S[1] = Tab[1] + Rab(1, 1) * u -
t;
225 S[2] = Tab[2] + Rab(2, 1) * u;
238 if ((LA1_ux >
b[0]) && (UB1_lx < 0)) {
239 if (((LA1_lx >
b[0]) ||
240 inVoronoi(
b[1],
a[1], A1_dot_B0, -Tba[0] -
b[0], A1_dot_B1, -Tba[1],
241 -Tab[1] - bA1_dot_B0)) &&
242 ((UB1_ux < 0) ||
inVoronoi(
a[1],
b[1], -A0_dot_B1, -Tab[0] - bA0_dot_B0,
243 A1_dot_B1, Tab[1] + bA1_dot_B0, Tba[1]))) {
244 segCoords(
t, u,
a[1],
b[1], A1_dot_B1, Tab[1] + bA1_dot_B0, Tba[1]);
246 S[0] = Tab[0] + Rab(0, 0) *
b[0] + Rab(0, 1) * u;
247 S[1] = Tab[1] + Rab(1, 0) *
b[0] + Rab(1, 1) * u -
t;
248 S[2] = Tab[2] + Rab(2, 0) *
b[0] + Rab(2, 1) * u;
261 if ((LA1_lx < 0) && (LB1_lx < 0)) {
262 if (((LA1_ux < 0) ||
inVoronoi(
b[1],
a[1], -A1_dot_B0, Tba[0], A1_dot_B1,
263 -Tba[1], -Tab[1])) &&
264 ((LB1_ux < 0) ||
inVoronoi(
a[1],
b[1], -A0_dot_B1, -Tab[0], A1_dot_B1,
268 S[0] = Tab[0] + Rab(0, 1) * u;
269 S[1] = Tab[1] + Rab(1, 1) * u -
t;
270 S[2] = Tab[2] + Rab(2, 1) * u;
281 FCL_REAL ALL_y, ALU_y, AUL_y, AUU_y;
284 ALU_y = ALL_y + aA1_dot_B1;
285 AUL_y = ALL_y + aA0_dot_B1;
286 AUU_y = ALU_y + aA0_dot_B1;
288 FCL_REAL LA1_ly, LA1_uy, UA1_ly, UA1_uy, LB0_lx, LB0_ux, UB0_lx, UB0_ux;
316 if ((UA1_uy >
b[1]) && (UB0_ux >
a[0])) {
317 if (((UA1_ly >
b[1]) ||
318 inVoronoi(
b[0],
a[1], A1_dot_B1, aA0_dot_B1 - Tba[1] -
b[1], A1_dot_B0,
319 aA0_dot_B0 - Tba[0], -Tab[1] - bA1_dot_B1)) &&
321 inVoronoi(
a[1],
b[0], A0_dot_B0, Tab[0] -
a[0] + bA0_dot_B1, A1_dot_B0,
322 Tab[1] + bA1_dot_B1, Tba[0] - aA0_dot_B0))) {
323 segCoords(
t, u,
a[1],
b[0], A1_dot_B0, Tab[1] + bA1_dot_B1,
324 Tba[0] - aA0_dot_B0);
326 S[0] = Tab[0] + Rab(0, 1) *
b[1] + Rab(0, 0) * u -
a[0];
327 S[1] = Tab[1] + Rab(1, 1) *
b[1] + Rab(1, 0) * u -
t;
328 S[2] = Tab[2] + Rab(2, 1) *
b[1] + Rab(2, 0) * u;
341 if ((UA1_ly < 0) && (LB0_ux >
a[0])) {
342 if (((UA1_uy < 0) ||
inVoronoi(
b[0],
a[1], -A1_dot_B1, Tba[1] - aA0_dot_B1,
343 A1_dot_B0, aA0_dot_B0 - Tba[0], -Tab[1])) &&
345 inVoronoi(
a[1],
b[0], A0_dot_B0, Tab[0] -
a[0], A1_dot_B0, Tab[1],
346 Tba[0] - aA0_dot_B0))) {
347 segCoords(
t, u,
a[1],
b[0], A1_dot_B0, Tab[1], Tba[0] - aA0_dot_B0);
349 S[0] = Tab[0] + Rab(0, 0) * u -
a[0];
350 S[1] = Tab[1] + Rab(1, 0) * u -
t;
351 S[2] = Tab[2] + Rab(2, 0) * u;
364 if ((LA1_uy >
b[1]) && (UB0_lx < 0)) {
365 if (((LA1_ly >
b[1]) ||
366 inVoronoi(
b[0],
a[1], A1_dot_B1, -Tba[1] -
b[1], A1_dot_B0, -Tba[0],
367 -Tab[1] - bA1_dot_B1)) &&
369 ((UB0_ux < 0) ||
inVoronoi(
a[1],
b[0], -A0_dot_B0, -Tab[0] - bA0_dot_B1,
370 A1_dot_B0, Tab[1] + bA1_dot_B1, Tba[0]))) {
371 segCoords(
t, u,
a[1],
b[0], A1_dot_B0, Tab[1] + bA1_dot_B1, Tba[0]);
373 S[0] = Tab[0] + Rab(0, 1) *
b[1] + Rab(0, 0) * u;
374 S[1] = Tab[1] + Rab(1, 1) *
b[1] + Rab(1, 0) * u -
t;
375 S[2] = Tab[2] + Rab(2, 1) *
b[1] + Rab(2, 0) * u;
388 if ((LA1_ly < 0) && (LB0_lx < 0)) {
389 if (((LA1_uy < 0) ||
inVoronoi(
b[0],
a[1], -A1_dot_B1, Tba[1], A1_dot_B0,
390 -Tba[0], -Tab[1])) &&
391 ((LB0_ux < 0) ||
inVoronoi(
a[1],
b[0], -A0_dot_B0, -Tab[0], A1_dot_B0,
395 S[0] = Tab[0] + Rab(0, 0) * u;
396 S[1] = Tab[1] + Rab(1, 0) * u -
t;
397 S[2] = Tab[2] + Rab(2, 0) * u;
408 FCL_REAL BLL_y, BLU_y, BUL_y, BUU_y;
411 BLU_y = BLL_y + bA1_dot_B1;
412 BUL_y = BLL_y + bA1_dot_B0;
413 BUU_y = BLU_y + bA1_dot_B0;
415 FCL_REAL LA0_lx, LA0_ux, UA0_lx, UA0_ux, LB1_ly, LB1_uy, UB1_ly, UB1_uy;
443 if ((UA0_ux >
b[0]) && (UB1_uy >
a[1])) {
444 if (((UA0_lx >
b[0]) ||
445 inVoronoi(
b[1],
a[0], A0_dot_B0, aA1_dot_B0 - Tba[0] -
b[0], A0_dot_B1,
446 aA1_dot_B1 - Tba[1], -Tab[0] - bA0_dot_B0)) &&
448 inVoronoi(
a[0],
b[1], A1_dot_B1, Tab[1] -
a[1] + bA1_dot_B0, A0_dot_B1,
449 Tab[0] + bA0_dot_B0, Tba[1] - aA1_dot_B1))) {
450 segCoords(
t, u,
a[0],
b[1], A0_dot_B1, Tab[0] + bA0_dot_B0,
451 Tba[1] - aA1_dot_B1);
453 S[0] = Tab[0] + Rab(0, 0) *
b[0] + Rab(0, 1) * u -
t;
454 S[1] = Tab[1] + Rab(1, 0) *
b[0] + Rab(1, 1) * u -
a[1];
455 S[2] = Tab[2] + Rab(2, 0) *
b[0] + Rab(2, 1) * u;
468 if ((UA0_lx < 0) && (LB1_uy >
a[1])) {
469 if (((UA0_ux < 0) ||
inVoronoi(
b[1],
a[0], -A0_dot_B0, Tba[0] - aA1_dot_B0,
470 A0_dot_B1, aA1_dot_B1 - Tba[1], -Tab[0])) &&
472 inVoronoi(
a[0],
b[1], A1_dot_B1, Tab[1] -
a[1], A0_dot_B1, Tab[0],
473 Tba[1] - aA1_dot_B1))) {
474 segCoords(
t, u,
a[0],
b[1], A0_dot_B1, Tab[0], Tba[1] - aA1_dot_B1);
476 S[0] = Tab[0] + Rab(0, 1) * u -
t;
477 S[1] = Tab[1] + Rab(1, 1) * u -
a[1];
478 S[2] = Tab[2] + Rab(2, 1) * u;
491 if ((LA0_ux >
b[0]) && (UB1_ly < 0)) {
492 if (((LA0_lx >
b[0]) ||
493 inVoronoi(
b[1],
a[0], A0_dot_B0, -
b[0] - Tba[0], A0_dot_B1, -Tba[1],
494 -bA0_dot_B0 - Tab[0])) &&
495 ((UB1_uy < 0) ||
inVoronoi(
a[0],
b[1], -A1_dot_B1, -Tab[1] - bA1_dot_B0,
496 A0_dot_B1, Tab[0] + bA0_dot_B0, Tba[1]))) {
497 segCoords(
t, u,
a[0],
b[1], A0_dot_B1, Tab[0] + bA0_dot_B0, Tba[1]);
499 S[0] = Tab[0] + Rab(0, 0) *
b[0] + Rab(0, 1) * u -
t;
500 S[1] = Tab[1] + Rab(1, 0) *
b[0] + Rab(1, 1) * u;
501 S[2] = Tab[2] + Rab(2, 0) *
b[0] + Rab(2, 1) * u;
514 if ((LA0_lx < 0) && (LB1_ly < 0)) {
515 if (((LA0_ux < 0) ||
inVoronoi(
b[1],
a[0], -A0_dot_B0, Tba[0], A0_dot_B1,
516 -Tba[1], -Tab[0])) &&
517 ((LB1_uy < 0) ||
inVoronoi(
a[0],
b[1], -A1_dot_B1, -Tab[1], A0_dot_B1,
521 S[0] = Tab[0] + Rab(0, 1) * u -
t;
522 S[1] = Tab[1] + Rab(1, 1) * u;
523 S[2] = Tab[2] + Rab(2, 1) * u;
534 FCL_REAL LA0_ly, LA0_uy, UA0_ly, UA0_uy, LB0_ly, LB0_uy, UB0_ly, UB0_uy;
562 if ((UA0_uy >
b[1]) && (UB0_uy >
a[1])) {
563 if (((UA0_ly >
b[1]) ||
564 inVoronoi(
b[0],
a[0], A0_dot_B1, aA1_dot_B1 - Tba[1] -
b[1], A0_dot_B0,
565 aA1_dot_B0 - Tba[0], -Tab[0] - bA0_dot_B1)) &&
567 inVoronoi(
a[0],
b[0], A1_dot_B0, Tab[1] -
a[1] + bA1_dot_B1, A0_dot_B0,
568 Tab[0] + bA0_dot_B1, Tba[0] - aA1_dot_B0))) {
569 segCoords(
t, u,
a[0],
b[0], A0_dot_B0, Tab[0] + bA0_dot_B1,
570 Tba[0] - aA1_dot_B0);
572 S[0] = Tab[0] + Rab(0, 1) *
b[1] + Rab(0, 0) * u -
t;
573 S[1] = Tab[1] + Rab(1, 1) *
b[1] + Rab(1, 0) * u -
a[1];
574 S[2] = Tab[2] + Rab(2, 1) *
b[1] + Rab(2, 0) * u;
587 if ((UA0_ly < 0) && (LB0_uy >
a[1])) {
588 if (((UA0_uy < 0) ||
inVoronoi(
b[0],
a[0], -A0_dot_B1, Tba[1] - aA1_dot_B1,
589 A0_dot_B0, aA1_dot_B0 - Tba[0], -Tab[0])) &&
591 inVoronoi(
a[0],
b[0], A1_dot_B0, Tab[1] -
a[1], A0_dot_B0, Tab[0],
592 Tba[0] - aA1_dot_B0))) {
593 segCoords(
t, u,
a[0],
b[0], A0_dot_B0, Tab[0], Tba[0] - aA1_dot_B0);
595 S[0] = Tab[0] + Rab(0, 0) * u -
t;
596 S[1] = Tab[1] + Rab(1, 0) * u -
a[1];
597 S[2] = Tab[2] + Rab(2, 0) * u;
610 if ((LA0_uy >
b[1]) && (UB0_ly < 0)) {
611 if (((LA0_ly >
b[1]) ||
612 inVoronoi(
b[0],
a[0], A0_dot_B1, -Tba[1] -
b[1], A0_dot_B0, -Tba[0],
613 -Tab[0] - bA0_dot_B1)) &&
615 ((UB0_uy < 0) ||
inVoronoi(
a[0],
b[0], -A1_dot_B0, -Tab[1] - bA1_dot_B1,
616 A0_dot_B0, Tab[0] + bA0_dot_B1, Tba[0]))) {
617 segCoords(
t, u,
a[0],
b[0], A0_dot_B0, Tab[0] + bA0_dot_B1, Tba[0]);
619 S[0] = Tab[0] + Rab(0, 1) *
b[1] + Rab(0, 0) * u -
t;
620 S[1] = Tab[1] + Rab(1, 1) *
b[1] + Rab(1, 0) * u;
621 S[2] = Tab[2] + Rab(2, 1) *
b[1] + Rab(2, 0) * u;
634 if ((LA0_ly < 0) && (LB0_ly < 0)) {
635 if (((LA0_uy < 0) ||
inVoronoi(
b[0],
a[0], -A0_dot_B1, Tba[1], A0_dot_B0,
636 -Tba[0], -Tab[0])) &&
637 ((LB0_uy < 0) ||
inVoronoi(
a[0],
b[0], -A1_dot_B0, -Tab[1], A0_dot_B0,
641 S[0] = Tab[0] + Rab(0, 0) * u -
t;
642 S[1] = Tab[1] + Rab(1, 0) * u;
643 S[2] = Tab[2] + Rab(2, 0) * u;
660 if (Rab(2, 0) < 0.0) sep1 +=
b[0] * Rab(2, 0);
661 if (Rab(2, 1) < 0.0) sep1 +=
b[1] * Rab(2, 1);
664 if (Rab(2, 0) > 0.0) sep1 -=
b[0] * Rab(2, 0);
665 if (Rab(2, 1) > 0.0) sep1 -=
b[1] * Rab(2, 1);
670 if (Rab(0, 2) < 0.0) sep2 +=
a[0] * Rab(0, 2);
671 if (Rab(1, 2) < 0.0) sep2 +=
a[1] * Rab(1, 2);
674 if (Rab(0, 2) > 0.0) sep2 -=
a[0] * Rab(0, 2);
675 if (Rab(1, 2) > 0.0) sep2 -=
a[1] * Rab(1, 2);
678 if (sep1 >= sep2 && sep1 >= 0) {
690 if (sep2 >= sep1 && sep2 >= 0) {
691 Vec3f Q_(Tab[0], Tab[1], Tab[2]);
694 P_[0] = Rab(0, 2) * sep2 + Tab[0];
695 P_[1] = Rab(1, 2) * sep2 + Tab[1];
696 P_[2] = Rab(2, 2) * sep2 + Tab[2];
698 P_[0] = -Rab(0, 2) * sep2 + Tab[0];
699 P_[1] = -Rab(1, 2) * sep2 + Tab[1];
700 P_[2] = -Rab(2, 2) * sep2 + Tab[2];
712 return (
sep > 0 ?
sep : 0);
737 Vec3f Ttemp(R0.transpose() * (b2.
Tr - T0) - b1.
Tr);
752 Vec3f Ttemp(R0.transpose() * (b2.
Tr - T0) - b1.
Tr);
758 if (dist <= 0)
return true;
759 sqrDistLowerBound = dist * dist;
770 Vec3f proj(proj0, proj1, proj2);
773 if ((proj0 <
length[0]) && (proj0 > 0) && (proj1 <
length[1]) &&
775 return (abs_proj2 <
radius);
776 }
else if ((proj0 <
length[0]) && (proj0 > 0) &&
777 ((proj1 < 0) || (proj1 >
length[1]))) {
781 }
else if ((proj1 <
length[1]) && (proj1 > 0) &&
782 ((proj0 < 0) || (proj0 >
length[0]))) {
800 Vec3f proj(proj0, proj1, proj2);
803 if ((proj0 <
length[0]) && (proj0 > 0) && (proj1 <
length[1]) &&
811 Tr[2] += 0.5 * (abs_proj2 -
radius);
813 Tr[2] -= 0.5 * (abs_proj2 -
radius);
815 }
else if ((proj0 <
length[0]) && (proj0 > 0) &&
816 ((proj1 < 0) || (proj1 >
length[1]))) {
819 FCL_REAL new_r_sqr = (proj -
v).squaredNorm();
825 -std::sqrt(
radius *
radius - proj2 * proj2) + fabs(proj1 -
y);
827 if (proj1 < 0)
Tr[1] -= delta_y;
831 if (proj1 < 0)
Tr[1] -= delta_y;
834 Tr[2] += 0.5 * (abs_proj2 -
radius);
836 Tr[2] -= 0.5 * (abs_proj2 -
radius);
839 }
else if ((proj1 <
length[1]) && (proj1 > 0) &&
840 ((proj0 < 0) || (proj0 >
length[0]))) {
843 FCL_REAL new_r_sqr = (proj -
v).squaredNorm();
849 -std::sqrt(
radius *
radius - proj2 * proj2) + fabs(proj0 -
x);
851 if (proj0 < 0)
Tr[0] -= delta_x;
855 if (proj0 < 0)
Tr[0] -= delta_x;
858 Tr[2] += 0.5 * (abs_proj2 -
radius);
860 Tr[2] -= 0.5 * (abs_proj2 -
radius);
867 FCL_REAL new_r_sqr = (proj -
v).squaredNorm();
872 FCL_REAL diag = std::sqrt(new_r_sqr - proj2 * proj2);
876 FCL_REAL delta_x = delta_diag / diag * fabs(proj0 -
x);
877 FCL_REAL delta_y = delta_diag / diag * fabs(proj1 -
y);
881 if (proj0 < 0 && proj1 < 0) {
892 if (proj0 < 0 && proj1 < 0) {
898 Tr[2] += 0.5 * (abs_proj2 -
radius);
900 Tr[2] -= 0.5 * (abs_proj2 -
radius);
919 v[0].noalias() = other.
Tr + d0_pos + d1_pos + d2_pos;
920 v[1].noalias() = other.
Tr + d0_pos + d1_pos + d2_neg;
921 v[2].noalias() = other.
Tr + d0_pos + d1_neg + d2_pos;
922 v[3].noalias() = other.
Tr + d0_pos + d1_neg + d2_neg;
923 v[4].noalias() = other.
Tr + d0_neg + d1_pos + d2_pos;
924 v[5].noalias() = other.
Tr + d0_neg + d1_pos + d2_neg;
925 v[6].noalias() = other.
Tr + d0_neg + d1_neg + d2_pos;
926 v[7].noalias() = other.
Tr + d0_neg + d1_neg + d2_neg;
935 v[8].noalias() =
Tr + d0_pos + d1_pos + d2_pos;
936 v[9].noalias() =
Tr + d0_pos + d1_pos + d2_neg;
937 v[10].noalias() =
Tr + d0_pos + d1_neg + d2_pos;
938 v[11].noalias() =
Tr + d0_pos + d1_neg + d2_neg;
939 v[12].noalias() =
Tr + d0_neg + d1_pos + d2_pos;
940 v[13].noalias() =
Tr + d0_neg + d1_pos + d2_neg;
941 v[14].noalias() =
Tr + d0_neg + d1_neg + d2_pos;
942 v[15].noalias() =
Tr + d0_neg + d1_neg + d2_neg;
946 Matrix3f::Scalar s[3] = {0, 0, 0};
962 }
else if (s[2] > s[max]) {
970 bv.
axes.col(0) << E[0][max], E[1][max], E[2][max];
971 bv.
axes.col(1) << E[0][mid], E[1][mid], E[2][mid];
972 bv.
axes.col(2) << E[1][max] * E[2][mid] - E[1][mid] * E[2][max],
973 E[0][mid] * E[2][max] - E[0][max] * E[2][mid],
974 E[0][max] * E[1][mid] - E[0][mid] * E[1][max];