Skip to content

Commit 10aab86

Browse files
committed
introduce function terminateMPR
1 parent 3f7a7cb commit 10aab86

File tree

1 file changed

+17
-21
lines changed
  • src/contactDetection/ContactDetectionMPR

1 file changed

+17
-21
lines changed

src/contactDetection/ContactDetectionMPR/mpr.jl

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,19 @@ function finalTC3(r0::SupportPoint{T}, r1::SupportPoint{T}, r2::SupportPoint{T},
244244
end
245245

246246

247+
function terminateMPR(r0::SupportPoint{T}, r1::SupportPoint{T}, r2::SupportPoint{T},
248+
r3::SupportPoint{T}, r4::SupportPoint{T}, isTC2::Bool, isTC3::Bool)::Tuple{T, SupportPoint{T}, SupportPoint{T}, SupportPoint{T}, SupportPoint{T}} where {T}
249+
if isTC2
250+
(distance,r1,r2,r3,r4) = finalTC2(r1, r2, r3, r4)
251+
return distance, r1, r2, r3, r4
252+
end
253+
if isTC3
254+
(distance,r1,r2,r3,r4) = finalTC3(r0, r1, r2, r3, r4)
255+
return distance, r1, r2, r3, r4
256+
end
257+
end
258+
259+
247260
function phase3(r0::SupportPoint{T}, r1::SupportPoint{T}, r2::SupportPoint{T}, r3::SupportPoint{T}, niter_max::Int64, tol_rel::T, shapeA::Composition.Object3D{F}, shapeB::Composition.Object3D{F}, scale::T) where {T,F}
248261
r1org = r1
249262
r2org = r2
@@ -268,13 +281,11 @@ function phase3(r0::SupportPoint{T}, r1::SupportPoint{T}, r2::SupportPoint{T}, r
268281
TC3 = abs(dot(r4.p-r1.p, r4.n)) # TC3
269282
## TERMINATION CONDITION 2 ##
270283
if TC2 < tol_rel
271-
(distance,r1,r2,r3,r4) = finalTC2(r1,r2,r3,r4)
272-
return distance, r1, r2, r3, r4
284+
return finalTC2(r1,r2,r3,r4)
273285

274286
## TERMINATION CONDITION 3 ##
275287
elseif TC3 < tol_rel
276-
(distance,r1,r2,r3,r4) = finalTC3(r0, r1, r2, r3, r4)
277-
return distance, r1, r2, r3, r4
288+
return finalTC3(r0, r1, r2, r3, r4)
278289
else
279290
if TC2 < new_tol
280291
new_tol = TC2
@@ -302,26 +313,11 @@ function phase3(r0::SupportPoint{T}, r1::SupportPoint{T}, r2::SupportPoint{T}, r
302313

303314
if !nextPortal # createBabyTetrahedrons failed
304315
@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.")
305-
if isTC2
306-
(distance,r1,r2,r3,r4) = finalTC2(r1_new,r2_new,r3_new,r4_new)
307-
return distance, r1, r2, r3, r4
308-
end
309-
if isTC3
310-
(distance,r1,r2,r3,r4) = finalTC3(r0, r1_new, r2_new, r3_new, r4_new)
311-
return distance, r1, r2, r3, r4
312-
end
316+
return terminateMPR(r0, r1_new, r2_new, r3_new, r4_new, isTC2, isTC3)
313317
end
314318
end
315319
@warn("MPR (phase 3): Max. number of iterations (mprIterMax = $niter_max) is reached. Please, increase mprIterMax. tol_rel increased locally for this computation to $new_tol. Look at shapes $(Modia3D.fullName(shapeA)) and $(Modia3D.fullName(shapeB)).")
316-
if isTC2
317-
(distance,r1,r2,r3,r4) = finalTC2(r1_new,r2_new,r3_new,r4_new)
318-
return distance, r1, r2, r3, r4
319-
end
320-
if isTC3
321-
(distance,r1,r2,r3,r4) = finalTC3(r0, r1_new, r2_new, r3_new, r4_new)
322-
return distance, r1, r2, r3, r4
323-
end
324-
return distance, r1, r2, r3, r4 # needed for a unique return type
320+
return terminateMPR(r0, r1_new, r2_new, r3_new, r4_new, isTC2, isTC3)
325321
end
326322

327323
# MPR - Minkowski Portal Refinement algorithm

0 commit comments

Comments
 (0)