@@ -890,7 +890,12 @@ static int polytope2(Polytope* pt, const mjCCDStatus* status, mjCCDObj* obj1, mj
890
890
if (mju_abs (det3 (v1 , v3 , v4 )) < mjMINVAL || mju_abs (det3 (v1 , v3 , v5 )) < mjMINVAL ||
891
891
mju_abs (det3 (v1 , v3 , v5 )) < mjMINVAL || mju_abs (det3 (v2 , v3 , v4 )) < mjMINVAL ||
892
892
mju_abs (det3 (v2 , v3 , v5 )) < mjMINVAL || mju_abs (det3 (v2 , v4 , v5 )) < mjMINVAL ) {
893
- return 2 ;
893
+ return mjEPA_P2_INVALID_FACES ;
894
+ }
895
+
896
+ // check that origin is in the hexahedron
897
+ if (!testTetra (v1 , v3 , v4 , v5 ) && !testTetra (v2 , v3 , v4 , v5 )) {
898
+ return mjEPA_P2_MISSING_ORIGIN ;
894
899
}
895
900
896
901
// save vertices and get indices for each one
@@ -914,7 +919,7 @@ static int polytope2(Polytope* pt, const mjCCDStatus* status, mjCCDObj* obj1, mj
914
919
pt -> map [i ] = pt -> faces + i ;
915
920
pt -> faces [i ].index = i ;
916
921
if (pt -> faces [i ].dist < mjMINVAL ) {
917
- return 3 ;
922
+ return mjEPA_P2_ORIGIN_ON_FACE ;
918
923
}
919
924
}
920
925
pt -> nmap = 6 ;
@@ -1003,7 +1008,7 @@ static int polytope3(Polytope* pt, const mjCCDStatus* status, mjCCDObj* obj1, mj
1003
1008
cross3 (n , diff1 , diff2 );
1004
1009
mjtNum n_norm = mju_norm3 (n );
1005
1010
if (n_norm < mjMINVAL ) {
1006
- return 4 ;
1011
+ return mjEPA_P3_BAD_NORMAL ;
1007
1012
}
1008
1013
1009
1014
// negative of triangle normal n
@@ -1016,7 +1021,7 @@ static int polytope3(Polytope* pt, const mjCCDStatus* status, mjCCDObj* obj1, mj
1016
1021
1017
1022
// check that v4 is not contained in the 2-simplex
1018
1023
if (triPointIntersect (v1 , v2 , v3 , v4 )) {
1019
- return 5 ;
1024
+ return mjEPA_P3_INVALID_V4 ;
1020
1025
}
1021
1026
1022
1027
// get 5th vertex in -n direction
@@ -1026,7 +1031,7 @@ static int polytope3(Polytope* pt, const mjCCDStatus* status, mjCCDObj* obj1, mj
1026
1031
1027
1032
// check that v5 is not contained in the 2-simplex
1028
1033
if (triPointIntersect (v1 , v2 , v3 , v5 )) {
1029
- return 6 ;
1034
+ return mjEPA_P3_INVALID_V5 ;
1030
1035
}
1031
1036
1032
1037
// if origin does not lie on simplex then we need to check that the hexahedron contains the
@@ -1036,7 +1041,7 @@ static int polytope3(Polytope* pt, const mjCCDStatus* status, mjCCDObj* obj1, mj
1036
1041
// it but within tolerance from it. In that case the hexahedron could possibly be constructed
1037
1042
// that doesn't contain the origin, but nonetheless there is penetration depth.
1038
1043
if (status -> dist > 10 * mjMINVAL && !testTetra (v1 , v2 , v3 , v4 ) && !testTetra (v1 , v2 , v3 , v5 )) {
1039
- return 7 ;
1044
+ return mjEPA_P3_MISSING_ORIGIN ;
1040
1045
}
1041
1046
1042
1047
// save vertices and get indices for each one
@@ -1061,7 +1066,7 @@ static int polytope3(Polytope* pt, const mjCCDStatus* status, mjCCDObj* obj1, mj
1061
1066
pt -> map [i ] = pt -> faces + i ;
1062
1067
pt -> faces [i ].index = i ;
1063
1068
if (pt -> faces [i ].dist < mjMINVAL ) {
1064
- return 8 ;
1069
+ return mjEPA_P3_ORIGIN_ON_FACE ;
1065
1070
}
1066
1071
}
1067
1072
pt -> nmap = 6 ;
@@ -1444,7 +1449,8 @@ mjtNum mjc_ccd(const mjCCDConfig* config, mjCCDStatus* status, mjCCDObj* obj1, m
1444
1449
obj1 -> center (status -> x1 , obj1 );
1445
1450
obj2 -> center (status -> x2 , obj2 );
1446
1451
status -> gjk_iterations = 0 ;
1447
- status -> epa_iterations = -1 ;
1452
+ status -> epa_iterations = 0 ;
1453
+ status -> epa_status = mjEPA_NOCONTACT ;
1448
1454
status -> tolerance = config -> tolerance ;
1449
1455
status -> max_iterations = config -> max_iterations ;
1450
1456
status -> max_contacts = config -> max_contacts ;
@@ -1551,12 +1557,12 @@ mjtNum mjc_ccd(const mjCCDConfig* config, mjCCDStatus* status, mjCCDObj* obj1, m
1551
1557
} else {
1552
1558
ret = polytope4 (& pt , status , obj1 , obj2 );
1553
1559
}
1560
+ status -> epa_status = ret ;
1554
1561
1555
1562
// simplex not on boundary (objects are penetrating)
1556
1563
if (!ret ) {
1557
1564
dist = - epa (status , & pt , obj1 , obj2 );
1558
1565
} else {
1559
- status -> epa_iterations = - ret ;
1560
1566
dist = 0 ;
1561
1567
}
1562
1568
mj_freeStack (d );
0 commit comments