Skip to content

Commit 200e671

Browse files
committed
use best tolerance if number of niter_max is too low in MPR (phase 3)
1 parent 01d8a8e commit 200e671

File tree

1 file changed

+16
-9
lines changed
  • src/contactDetection/ContactDetectionMPR

1 file changed

+16
-9
lines changed

src/contactDetection/ContactDetectionMPR/mpr.jl

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ function constructR4(r0::SupportPoint,r1::SupportPoint,r2::SupportPoint,r3::Supp
171171
end
172172

173173
# computes twice a parallelepipedial product (Spatprodukt)
174-
isNextPortal(r0,r1,r2,r4) = dot( cross( (r2.p-r0.p), (r4.p-r0.p) ), r0.n ) <= 0.0 &&
174+
isNextPortal(r0::SupportPoint, r1::SupportPoint, r2::SupportPoint, r4::SupportPoint) = dot( cross( (r2.p-r0.p), (r4.p-r0.p) ), r0.n ) <= 0.0 &&
175175
dot( cross( (r4.p-r0.p), (r1.p-r0.p) ), r0.n ) <= 0.0
176176

177177

@@ -181,8 +181,7 @@ isNextPortal(r0,r1,r2,r4) = dot( cross( (r2.p-r0.p), (r4.p-r0.p) ), r0.n ) <= 0.
181181
# r1r2r4
182182
# r2r3r4
183183
# r3r1r4
184-
function createBabyTetrahedrons(r0::SupportPoint,r1::SupportPoint,r2::SupportPoint,r3::SupportPoint,r4::SupportPoint,
185-
shapeA::Composition.Object3D,shapeB::Composition.Object3D)
184+
function createBabyTetrahedrons(r0::SupportPoint, r1::SupportPoint, r2::SupportPoint, r3::SupportPoint, r4::SupportPoint)
186185
nextPortal = true
187186
if isNextPortal(r0,r1,r2,r4)
188187
r3 = r4
@@ -200,7 +199,7 @@ end
200199
scaleVector(scale, ri) = ri.*scale
201200

202201

203-
function skalarization(r0,r1,r2,r3)
202+
function skalarization(r0::SupportPoint, r1::SupportPoint, r2::SupportPoint, r3::SupportPoint)
204203
x = maximum([abs.(r0.p) abs.(r1.p) abs.(r2.p) abs.(r3.p)])
205204
scale = 1/x
206205
r0.p = scaleVector(scale, r0.p)
@@ -210,7 +209,7 @@ function skalarization(r0,r1,r2,r3)
210209
return (r0, r1, r2, r3, scale)
211210
end
212211

213-
function finalTC2(r1, r2, r3, r4)
212+
function finalTC2(r1::SupportPoint, r2::SupportPoint, r3::SupportPoint, r4::SupportPoint)
214213
#println("TC 2")
215214
#if !analyzeFinalPortal(r1.p, r2.p, r3.p, r4.p, neps)
216215
# error("shapeA = ", shapeA, " shapeB = ", shapeB)
@@ -220,7 +219,8 @@ function finalTC2(r1, r2, r3, r4)
220219
return distance, r1, r2, r3, r4
221220
end
222221

223-
function finalTC3(r0, r1, r2, r3, r4)
222+
223+
function finalTC3(r0::SupportPoint, r1::SupportPoint, r2::SupportPoint, r3::SupportPoint, r4::SupportPoint)
224224
#println("TC 3")
225225

226226
#doesRayIntersectPortal(r1.p,r2.p,r3.p, r4.p,neps)
@@ -330,7 +330,6 @@ function mprGeneral(ch::Composition.ContactDetectionMPR_handler, shapeA::Composi
330330
### Phase 3.2: check if r4 is close to the origin ###
331331
# check if the new point r4 is already on the plane of the triangle r1,r2,r3,
332332
# we're already as close as we can get to the origin
333-
334333
TC2 = norm(cross(r4.p,r4.n)) # TC2
335334
TC3 = abs(dot(r4.p-r1.p, r4.n)) # TC3
336335
## TERMINATION CONDITION 2 ##
@@ -365,7 +364,7 @@ function mprGeneral(ch::Composition.ContactDetectionMPR_handler, shapeA::Composi
365364

366365
#### Phase 3.3: construct baby tetrahedrons with r1,r2,r3,r4 and create a new portal ###
367366
# Construction of three baby tetrahedrons
368-
(nextPortal, r1,r2,r3) = createBabyTetrahedrons(r0,r1,r2,r3,r4,shapeA,shapeB)
367+
(nextPortal, r1,r2,r3) = createBabyTetrahedrons(r0,r1,r2,r3,r4)
369368

370369
if !nextPortal # createBabyTetrahedrons failed
371370
@warn("MPR (phase 3): Numerical issues with distance computation between $(Modia3D.fullName(shapeA)) and $(Modia3D.fullName(shapeB)). tol_rel increased locally for this computation to $new_tol.")
@@ -379,7 +378,15 @@ function mprGeneral(ch::Composition.ContactDetectionMPR_handler, shapeA::Composi
379378
end
380379
end
381380
end
382-
error("MPR (phase 3): Numerical issues with distance computation between $(Modia3D.fullName(shapeA)) and $(Modia3D.fullName(shapeB)).")
381+
@warn("MPR (phase 3): Numerical issues with distance computation between $(Modia3D.fullName(shapeA)) and $(Modia3D.fullName(shapeB)). Too less iteration steps (actually $niter_max). tol_rel increased locally for this computation to $new_tol.")
382+
if isTC2
383+
(distance,r1,r2,r3,r4) = finalTC2(r1_new,r2_new,r3_new,r4_new)
384+
return (distance, r4.a, r4.b, r4.n, true, r1.a, r1.b, r2.a, r2.b, r3.a, r3.b)
385+
end
386+
if isTC3
387+
(distance,r1,r2,r3,r4) = finalTC3(r0, r1_new, r2_new, r3_new, r4_new)
388+
return (distance, r4.a, r4.b, r4.n, true, r1.a, r1.b, r2.a, r2.b, r3.a, r3.b)
389+
end
383390
end
384391

385392

0 commit comments

Comments
 (0)