73 t = (A_dot_T - B_dot_T * A_dot_B) / denom;
77 u =
t * A_dot_B - B_dot_T;
84 t = u * A_dot_B + A_dot_T;
97 if (fabs(Anorm_dot_B) < 1e-7)
return false;
101 u = -Anorm_dot_T / Anorm_dot_B;
104 t = u * A_dot_B + A_dot_T;
107 v =
t * A_dot_B - B_dot_T;
109 if (Anorm_dot_B > 0) {
110 if (
v > (u + 1e-7))
return true;
112 if (
v < (u - 1e-7))
return true;
123 CoalScalar A0_dot_B0, A0_dot_B1, A1_dot_B0, A1_dot_B1;
125 A0_dot_B0 = Rab(0, 0);
126 A0_dot_B1 = Rab(0, 1);
127 A1_dot_B0 = Rab(1, 0);
128 A1_dot_B1 = Rab(1, 1);
130 CoalScalar aA0_dot_B0, aA0_dot_B1, aA1_dot_B0, aA1_dot_B1;
131 CoalScalar bA0_dot_B0, bA0_dot_B1, bA1_dot_B0, bA1_dot_B1;
133 aA0_dot_B0 =
a[0] * A0_dot_B0;
134 aA0_dot_B1 =
a[0] * A0_dot_B1;
135 aA1_dot_B0 =
a[1] * A1_dot_B0;
136 aA1_dot_B1 =
a[1] * A1_dot_B1;
137 bA0_dot_B0 =
b[0] * A0_dot_B0;
138 bA1_dot_B0 =
b[0] * A1_dot_B0;
139 bA0_dot_B1 =
b[1] * A0_dot_B1;
140 bA1_dot_B1 =
b[1] * A1_dot_B1;
142 Vec3s Tba(Rab.transpose() * Tab);
151 CoalScalar LA1_lx, LA1_ux, UA1_lx, UA1_ux, LB1_lx, LB1_ux, UB1_lx, UB1_ux;
154 ALU_x = ALL_x + aA1_dot_B0;
155 AUL_x = ALL_x + aA0_dot_B0;
156 AUU_x = ALU_x + aA0_dot_B0;
171 BLU_x = BLL_x + bA0_dot_B1;
172 BUL_x = BLL_x + bA0_dot_B0;
173 BUU_x = BLU_x + bA0_dot_B0;
189 if ((UA1_ux >
b[0]) && (UB1_ux >
a[0])) {
190 if (((UA1_lx >
b[0]) ||
191 inVoronoi(
b[1],
a[1], A1_dot_B0, aA0_dot_B0 -
b[0] - Tba[0], A1_dot_B1,
192 aA0_dot_B1 - Tba[1], -Tab[1] - bA1_dot_B0)) &&
194 inVoronoi(
a[1],
b[1], A0_dot_B1, Tab[0] + bA0_dot_B0 -
a[0], A1_dot_B1,
195 Tab[1] + bA1_dot_B0, Tba[1] - aA0_dot_B1))) {
196 segCoords(
t, u,
a[1],
b[1], A1_dot_B1, Tab[1] + bA1_dot_B0,
197 Tba[1] - aA0_dot_B1);
199 S[0] = Tab[0] + Rab(0, 0) *
b[0] + Rab(0, 1) * u -
a[0];
200 S[1] = Tab[1] + Rab(1, 0) *
b[0] + Rab(1, 1) * u -
t;
201 S[2] = Tab[2] + Rab(2, 0) *
b[0] + Rab(2, 1) * u;
214 if ((UA1_lx < 0) && (LB1_ux >
a[0])) {
215 if (((UA1_ux < 0) ||
inVoronoi(
b[1],
a[1], -A1_dot_B0, Tba[0] - aA0_dot_B0,
216 A1_dot_B1, aA0_dot_B1 - Tba[1], -Tab[1])) &&
218 inVoronoi(
a[1],
b[1], A0_dot_B1, Tab[0] -
a[0], A1_dot_B1, Tab[1],
219 Tba[1] - aA0_dot_B1))) {
220 segCoords(
t, u,
a[1],
b[1], A1_dot_B1, Tab[1], Tba[1] - aA0_dot_B1);
222 S[0] = Tab[0] + Rab(0, 1) * u -
a[0];
223 S[1] = Tab[1] + Rab(1, 1) * u -
t;
224 S[2] = Tab[2] + Rab(2, 1) * u;
237 if ((LA1_ux >
b[0]) && (UB1_lx < 0)) {
238 if (((LA1_lx >
b[0]) ||
239 inVoronoi(
b[1],
a[1], A1_dot_B0, -Tba[0] -
b[0], A1_dot_B1, -Tba[1],
240 -Tab[1] - bA1_dot_B0)) &&
241 ((UB1_ux < 0) ||
inVoronoi(
a[1],
b[1], -A0_dot_B1, -Tab[0] - bA0_dot_B0,
242 A1_dot_B1, Tab[1] + bA1_dot_B0, Tba[1]))) {
243 segCoords(
t, u,
a[1],
b[1], A1_dot_B1, Tab[1] + bA1_dot_B0, Tba[1]);
245 S[0] = Tab[0] + Rab(0, 0) *
b[0] + Rab(0, 1) * u;
246 S[1] = Tab[1] + Rab(1, 0) *
b[0] + Rab(1, 1) * u -
t;
247 S[2] = Tab[2] + Rab(2, 0) *
b[0] + Rab(2, 1) * u;
260 if ((LA1_lx < 0) && (LB1_lx < 0)) {
261 if (((LA1_ux < 0) ||
inVoronoi(
b[1],
a[1], -A1_dot_B0, Tba[0], A1_dot_B1,
262 -Tba[1], -Tab[1])) &&
263 ((LB1_ux < 0) ||
inVoronoi(
a[1],
b[1], -A0_dot_B1, -Tab[0], A1_dot_B1,
267 S[0] = Tab[0] + Rab(0, 1) * u;
268 S[1] = Tab[1] + Rab(1, 1) * u -
t;
269 S[2] = Tab[2] + Rab(2, 1) * u;
283 ALU_y = ALL_y + aA1_dot_B1;
284 AUL_y = ALL_y + aA0_dot_B1;
285 AUU_y = ALU_y + aA0_dot_B1;
287 CoalScalar LA1_ly, LA1_uy, UA1_ly, UA1_uy, LB0_lx, LB0_ux, UB0_lx, UB0_ux;
315 if ((UA1_uy >
b[1]) && (UB0_ux >
a[0])) {
316 if (((UA1_ly >
b[1]) ||
317 inVoronoi(
b[0],
a[1], A1_dot_B1, aA0_dot_B1 - Tba[1] -
b[1], A1_dot_B0,
318 aA0_dot_B0 - Tba[0], -Tab[1] - bA1_dot_B1)) &&
320 inVoronoi(
a[1],
b[0], A0_dot_B0, Tab[0] -
a[0] + bA0_dot_B1, A1_dot_B0,
321 Tab[1] + bA1_dot_B1, Tba[0] - aA0_dot_B0))) {
322 segCoords(
t, u,
a[1],
b[0], A1_dot_B0, Tab[1] + bA1_dot_B1,
323 Tba[0] - aA0_dot_B0);
325 S[0] = Tab[0] + Rab(0, 1) *
b[1] + Rab(0, 0) * u -
a[0];
326 S[1] = Tab[1] + Rab(1, 1) *
b[1] + Rab(1, 0) * u -
t;
327 S[2] = Tab[2] + Rab(2, 1) *
b[1] + Rab(2, 0) * u;
340 if ((UA1_ly < 0) && (LB0_ux >
a[0])) {
341 if (((UA1_uy < 0) ||
inVoronoi(
b[0],
a[1], -A1_dot_B1, Tba[1] - aA0_dot_B1,
342 A1_dot_B0, aA0_dot_B0 - Tba[0], -Tab[1])) &&
344 inVoronoi(
a[1],
b[0], A0_dot_B0, Tab[0] -
a[0], A1_dot_B0, Tab[1],
345 Tba[0] - aA0_dot_B0))) {
346 segCoords(
t, u,
a[1],
b[0], A1_dot_B0, Tab[1], Tba[0] - aA0_dot_B0);
348 S[0] = Tab[0] + Rab(0, 0) * u -
a[0];
349 S[1] = Tab[1] + Rab(1, 0) * u -
t;
350 S[2] = Tab[2] + Rab(2, 0) * u;
363 if ((LA1_uy >
b[1]) && (UB0_lx < 0)) {
364 if (((LA1_ly >
b[1]) ||
365 inVoronoi(
b[0],
a[1], A1_dot_B1, -Tba[1] -
b[1], A1_dot_B0, -Tba[0],
366 -Tab[1] - bA1_dot_B1)) &&
368 ((UB0_ux < 0) ||
inVoronoi(
a[1],
b[0], -A0_dot_B0, -Tab[0] - bA0_dot_B1,
369 A1_dot_B0, Tab[1] + bA1_dot_B1, Tba[0]))) {
370 segCoords(
t, u,
a[1],
b[0], A1_dot_B0, Tab[1] + bA1_dot_B1, Tba[0]);
372 S[0] = Tab[0] + Rab(0, 1) *
b[1] + Rab(0, 0) * u;
373 S[1] = Tab[1] + Rab(1, 1) *
b[1] + Rab(1, 0) * u -
t;
374 S[2] = Tab[2] + Rab(2, 1) *
b[1] + Rab(2, 0) * u;
387 if ((LA1_ly < 0) && (LB0_lx < 0)) {
388 if (((LA1_uy < 0) ||
inVoronoi(
b[0],
a[1], -A1_dot_B1, Tba[1], A1_dot_B0,
389 -Tba[0], -Tab[1])) &&
390 ((LB0_ux < 0) ||
inVoronoi(
a[1],
b[0], -A0_dot_B0, -Tab[0], A1_dot_B0,
394 S[0] = Tab[0] + Rab(0, 0) * u;
395 S[1] = Tab[1] + Rab(1, 0) * u -
t;
396 S[2] = Tab[2] + Rab(2, 0) * u;
410 BLU_y = BLL_y + bA1_dot_B1;
411 BUL_y = BLL_y + bA1_dot_B0;
412 BUU_y = BLU_y + bA1_dot_B0;
414 CoalScalar LA0_lx, LA0_ux, UA0_lx, UA0_ux, LB1_ly, LB1_uy, UB1_ly, UB1_uy;
442 if ((UA0_ux >
b[0]) && (UB1_uy >
a[1])) {
443 if (((UA0_lx >
b[0]) ||
444 inVoronoi(
b[1],
a[0], A0_dot_B0, aA1_dot_B0 - Tba[0] -
b[0], A0_dot_B1,
445 aA1_dot_B1 - Tba[1], -Tab[0] - bA0_dot_B0)) &&
447 inVoronoi(
a[0],
b[1], A1_dot_B1, Tab[1] -
a[1] + bA1_dot_B0, A0_dot_B1,
448 Tab[0] + bA0_dot_B0, Tba[1] - aA1_dot_B1))) {
449 segCoords(
t, u,
a[0],
b[1], A0_dot_B1, Tab[0] + bA0_dot_B0,
450 Tba[1] - aA1_dot_B1);
452 S[0] = Tab[0] + Rab(0, 0) *
b[0] + Rab(0, 1) * u -
t;
453 S[1] = Tab[1] + Rab(1, 0) *
b[0] + Rab(1, 1) * u -
a[1];
454 S[2] = Tab[2] + Rab(2, 0) *
b[0] + Rab(2, 1) * u;
467 if ((UA0_lx < 0) && (LB1_uy >
a[1])) {
468 if (((UA0_ux < 0) ||
inVoronoi(
b[1],
a[0], -A0_dot_B0, Tba[0] - aA1_dot_B0,
469 A0_dot_B1, aA1_dot_B1 - Tba[1], -Tab[0])) &&
471 inVoronoi(
a[0],
b[1], A1_dot_B1, Tab[1] -
a[1], A0_dot_B1, Tab[0],
472 Tba[1] - aA1_dot_B1))) {
473 segCoords(
t, u,
a[0],
b[1], A0_dot_B1, Tab[0], Tba[1] - aA1_dot_B1);
475 S[0] = Tab[0] + Rab(0, 1) * u -
t;
476 S[1] = Tab[1] + Rab(1, 1) * u -
a[1];
477 S[2] = Tab[2] + Rab(2, 1) * u;
490 if ((LA0_ux >
b[0]) && (UB1_ly < 0)) {
491 if (((LA0_lx >
b[0]) ||
492 inVoronoi(
b[1],
a[0], A0_dot_B0, -
b[0] - Tba[0], A0_dot_B1, -Tba[1],
493 -bA0_dot_B0 - Tab[0])) &&
494 ((UB1_uy < 0) ||
inVoronoi(
a[0],
b[1], -A1_dot_B1, -Tab[1] - bA1_dot_B0,
495 A0_dot_B1, Tab[0] + bA0_dot_B0, Tba[1]))) {
496 segCoords(
t, u,
a[0],
b[1], A0_dot_B1, Tab[0] + bA0_dot_B0, Tba[1]);
498 S[0] = Tab[0] + Rab(0, 0) *
b[0] + Rab(0, 1) * u -
t;
499 S[1] = Tab[1] + Rab(1, 0) *
b[0] + Rab(1, 1) * u;
500 S[2] = Tab[2] + Rab(2, 0) *
b[0] + Rab(2, 1) * u;
513 if ((LA0_lx < 0) && (LB1_ly < 0)) {
514 if (((LA0_ux < 0) ||
inVoronoi(
b[1],
a[0], -A0_dot_B0, Tba[0], A0_dot_B1,
515 -Tba[1], -Tab[0])) &&
516 ((LB1_uy < 0) ||
inVoronoi(
a[0],
b[1], -A1_dot_B1, -Tab[1], A0_dot_B1,
520 S[0] = Tab[0] + Rab(0, 1) * u -
t;
521 S[1] = Tab[1] + Rab(1, 1) * u;
522 S[2] = Tab[2] + Rab(2, 1) * u;
533 CoalScalar LA0_ly, LA0_uy, UA0_ly, UA0_uy, LB0_ly, LB0_uy, UB0_ly, UB0_uy;
561 if ((UA0_uy >
b[1]) && (UB0_uy >
a[1])) {
562 if (((UA0_ly >
b[1]) ||
563 inVoronoi(
b[0],
a[0], A0_dot_B1, aA1_dot_B1 - Tba[1] -
b[1], A0_dot_B0,
564 aA1_dot_B0 - Tba[0], -Tab[0] - bA0_dot_B1)) &&
566 inVoronoi(
a[0],
b[0], A1_dot_B0, Tab[1] -
a[1] + bA1_dot_B1, A0_dot_B0,
567 Tab[0] + bA0_dot_B1, Tba[0] - aA1_dot_B0))) {
568 segCoords(
t, u,
a[0],
b[0], A0_dot_B0, Tab[0] + bA0_dot_B1,
569 Tba[0] - aA1_dot_B0);
571 S[0] = Tab[0] + Rab(0, 1) *
b[1] + Rab(0, 0) * u -
t;
572 S[1] = Tab[1] + Rab(1, 1) *
b[1] + Rab(1, 0) * u -
a[1];
573 S[2] = Tab[2] + Rab(2, 1) *
b[1] + Rab(2, 0) * u;
586 if ((UA0_ly < 0) && (LB0_uy >
a[1])) {
587 if (((UA0_uy < 0) ||
inVoronoi(
b[0],
a[0], -A0_dot_B1, Tba[1] - aA1_dot_B1,
588 A0_dot_B0, aA1_dot_B0 - Tba[0], -Tab[0])) &&
590 inVoronoi(
a[0],
b[0], A1_dot_B0, Tab[1] -
a[1], A0_dot_B0, Tab[0],
591 Tba[0] - aA1_dot_B0))) {
592 segCoords(
t, u,
a[0],
b[0], A0_dot_B0, Tab[0], Tba[0] - aA1_dot_B0);
594 S[0] = Tab[0] + Rab(0, 0) * u -
t;
595 S[1] = Tab[1] + Rab(1, 0) * u -
a[1];
596 S[2] = Tab[2] + Rab(2, 0) * u;
609 if ((LA0_uy >
b[1]) && (UB0_ly < 0)) {
610 if (((LA0_ly >
b[1]) ||
611 inVoronoi(
b[0],
a[0], A0_dot_B1, -Tba[1] -
b[1], A0_dot_B0, -Tba[0],
612 -Tab[0] - bA0_dot_B1)) &&
614 ((UB0_uy < 0) ||
inVoronoi(
a[0],
b[0], -A1_dot_B0, -Tab[1] - bA1_dot_B1,
615 A0_dot_B0, Tab[0] + bA0_dot_B1, Tba[0]))) {
616 segCoords(
t, u,
a[0],
b[0], A0_dot_B0, Tab[0] + bA0_dot_B1, Tba[0]);
618 S[0] = Tab[0] + Rab(0, 1) *
b[1] + Rab(0, 0) * u -
t;
619 S[1] = Tab[1] + Rab(1, 1) *
b[1] + Rab(1, 0) * u;
620 S[2] = Tab[2] + Rab(2, 1) *
b[1] + Rab(2, 0) * u;
633 if ((LA0_ly < 0) && (LB0_ly < 0)) {
634 if (((LA0_uy < 0) ||
inVoronoi(
b[0],
a[0], -A0_dot_B1, Tba[1], A0_dot_B0,
635 -Tba[0], -Tab[0])) &&
636 ((LB0_uy < 0) ||
inVoronoi(
a[0],
b[0], -A1_dot_B0, -Tab[1], A0_dot_B0,
640 S[0] = Tab[0] + Rab(0, 0) * u -
t;
641 S[1] = Tab[1] + Rab(1, 0) * u;
642 S[2] = Tab[2] + Rab(2, 0) * u;
659 if (Rab(2, 0) < 0.0) sep1 +=
b[0] * Rab(2, 0);
660 if (Rab(2, 1) < 0.0) sep1 +=
b[1] * Rab(2, 1);
663 if (Rab(2, 0) > 0.0) sep1 -=
b[0] * Rab(2, 0);
664 if (Rab(2, 1) > 0.0) sep1 -=
b[1] * Rab(2, 1);
669 if (Rab(0, 2) < 0.0) sep2 +=
a[0] * Rab(0, 2);
670 if (Rab(1, 2) < 0.0) sep2 +=
a[1] * Rab(1, 2);
673 if (Rab(0, 2) > 0.0) sep2 -=
a[0] * Rab(0, 2);
674 if (Rab(1, 2) > 0.0) sep2 -=
a[1] * Rab(1, 2);
677 if (sep1 >= sep2 && sep1 >= 0) {
689 if (sep2 >= sep1 && sep2 >= 0) {
690 Vec3s Q_(Tab[0], Tab[1], Tab[2]);
693 P_[0] = Rab(0, 2) * sep2 + Tab[0];
694 P_[1] = Rab(1, 2) * sep2 + Tab[1];
695 P_[2] = Rab(2, 2) * sep2 + Tab[2];
697 P_[0] = -Rab(0, 2) * sep2 + Tab[0];
698 P_[1] = -Rab(1, 2) * sep2 + Tab[1];
699 P_[2] = -Rab(2, 2) * sep2 + Tab[2];
711 return (
sep > 0 ?
sep : 0);
736 Vec3s Ttemp(R0.transpose() * (b2.
Tr - T0) - b1.
Tr);
751 Vec3s Ttemp(R0.transpose() * (b2.
Tr - T0) - b1.
Tr);
757 if (dist <= 0)
return true;
758 sqrDistLowerBound = dist * dist;
769 Vec3s proj(proj0, proj1, proj2);
772 if ((proj0 <
length[0]) && (proj0 > 0) && (proj1 <
length[1]) &&
774 return (abs_proj2 <
radius);
775 }
else if ((proj0 <
length[0]) && (proj0 > 0) &&
776 ((proj1 < 0) || (proj1 >
length[1]))) {
780 }
else if ((proj1 <
length[1]) && (proj1 > 0) &&
781 ((proj0 < 0) || (proj0 >
length[0]))) {
799 Vec3s proj(proj0, proj1, proj2);
802 if ((proj0 <
length[0]) && (proj0 > 0) && (proj1 <
length[1]) &&
810 Tr[2] += 0.5 * (abs_proj2 -
radius);
812 Tr[2] -= 0.5 * (abs_proj2 -
radius);
814 }
else if ((proj0 <
length[0]) && (proj0 > 0) &&
815 ((proj1 < 0) || (proj1 >
length[1]))) {
824 -std::sqrt(
radius *
radius - proj2 * proj2) + fabs(proj1 -
y);
826 if (proj1 < 0)
Tr[1] -= delta_y;
830 if (proj1 < 0)
Tr[1] -= delta_y;
833 Tr[2] += 0.5 * (abs_proj2 -
radius);
835 Tr[2] -= 0.5 * (abs_proj2 -
radius);
838 }
else if ((proj1 <
length[1]) && (proj1 > 0) &&
839 ((proj0 < 0) || (proj0 >
length[0]))) {
848 -std::sqrt(
radius *
radius - proj2 * proj2) + fabs(proj0 -
x);
850 if (proj0 < 0)
Tr[0] -= delta_x;
854 if (proj0 < 0)
Tr[0] -= delta_x;
857 Tr[2] += 0.5 * (abs_proj2 -
radius);
859 Tr[2] -= 0.5 * (abs_proj2 -
radius);
871 CoalScalar diag = std::sqrt(new_r_sqr - proj2 * proj2);
875 CoalScalar delta_x = delta_diag / diag * fabs(proj0 -
x);
876 CoalScalar delta_y = delta_diag / diag * fabs(proj1 -
y);
880 if (proj0 < 0 && proj1 < 0) {
891 if (proj0 < 0 && proj1 < 0) {
897 Tr[2] += 0.5 * (abs_proj2 -
radius);
899 Tr[2] -= 0.5 * (abs_proj2 -
radius);
918 v[0].noalias() = other.
Tr + d0_pos + d1_pos + d2_pos;
919 v[1].noalias() = other.
Tr + d0_pos + d1_pos + d2_neg;
920 v[2].noalias() = other.
Tr + d0_pos + d1_neg + d2_pos;
921 v[3].noalias() = other.
Tr + d0_pos + d1_neg + d2_neg;
922 v[4].noalias() = other.
Tr + d0_neg + d1_pos + d2_pos;
923 v[5].noalias() = other.
Tr + d0_neg + d1_pos + d2_neg;
924 v[6].noalias() = other.
Tr + d0_neg + d1_neg + d2_pos;
925 v[7].noalias() = other.
Tr + d0_neg + d1_neg + d2_neg;
934 v[8].noalias() =
Tr + d0_pos + d1_pos + d2_pos;
935 v[9].noalias() =
Tr + d0_pos + d1_pos + d2_neg;
936 v[10].noalias() =
Tr + d0_pos + d1_neg + d2_pos;
937 v[11].noalias() =
Tr + d0_pos + d1_neg + d2_neg;
938 v[12].noalias() =
Tr + d0_neg + d1_pos + d2_pos;
939 v[13].noalias() =
Tr + d0_neg + d1_pos + d2_neg;
940 v[14].noalias() =
Tr + d0_neg + d1_neg + d2_pos;
941 v[15].noalias() =
Tr + d0_neg + d1_neg + d2_neg;
961 }
else if (s[2] > s[max]) {
969 bv.
axes.col(0) << E[0][max], E[1][max], E[2][max];
970 bv.
axes.col(1) << E[0][mid], E[1][mid], E[2][mid];
971 bv.
axes.col(2) << E[1][max] * E[2][mid] - E[1][mid] * E[2][max],
972 E[0][mid] * E[2][max] - E[0][max] * E[2][mid],
973 E[0][max] * E[1][mid] - E[0][mid] * E[1][max];