@@ -243,6 +243,93 @@ function finalTC3(r0::SupportPoint, r1::SupportPoint, r2::SupportPoint, r3::Supp
243243 return distance, r1, r2, r3, r4
244244end
245245
246+
247+ function phase3 (r0:: SupportPoint , r1:: SupportPoint , r2:: SupportPoint , r3:: SupportPoint , neps:: Float64 , niter_max:: Int64 ,tol_rel:: Float64 , shapeA:: Composition.Object3D ,shapeB:: Composition.Object3D , scale:: Float64 )
248+ r1org = r1
249+ r2org = r2
250+ r3org = r3
251+ new_tol = 42.0
252+ isTC2 = false
253+ isTC3 = false
254+ r1_new:: SupportPoint = r0
255+ r2_new:: SupportPoint = r0
256+ r3_new:: SupportPoint = r0
257+ r4_new:: SupportPoint = r0
258+ for i in 1 : niter_max
259+ # ## Phase 3.1: construct r4 ###
260+ # Find support point using the tetrahedron face
261+ (r3,r4,n4) = constructR4 (r0,r1,r2,r3,neps,shapeA,shapeB, scale)
262+
263+
264+ # ## Phase 3.2: check if r4 is close to the origin ###
265+ # check if the new point r4 is already on the plane of the triangle r1,r2,r3,
266+ # we're already as close as we can get to the origin
267+ TC2 = norm (cross (r4. p,r4. n)) # TC2
268+ TC3 = abs (dot (r4. p- r1. p, r4. n)) # TC3
269+ # # TERMINATION CONDITION 2 ##
270+ if TC2 < tol_rel
271+ (distance,r1,r2,r3,r4) = finalTC2 (r1,r2,r3,r4)
272+ return (distance, r4. a, r4. b, r4. n, true , r1. a, r1. b, r2. a, r2. b, r3. a, r3. b)
273+
274+ # # TERMINATION CONDITION 3 ##
275+ elseif TC3 < tol_rel
276+ (distance,r1,r2,r3,r4) = finalTC3 (r0, r1, r2, r3, r4)
277+ return (distance, r4. a, r4. b, r4. n, true , r1. a, r1. b, r2. a, r2. b, r3. a, r3. b)
278+ else
279+ if TC2 < new_tol
280+ new_tol = TC2
281+ isTC2 = true
282+ isTC3 = false
283+ r1_new = r1
284+ r2_new = r2
285+ r3_new = r3
286+ r4_new = r4
287+ end
288+ if TC3 < new_tol
289+ new_tol = TC3
290+ isTC2 = false
291+ isTC3 = true
292+ r1_new = r1
293+ r2_new = r2
294+ r3_new = r3
295+ r4_new = r4
296+ end
297+ end
298+
299+ # ### Phase 3.3: construct baby tetrahedrons with r1,r2,r3,r4 and create a new portal ###
300+ # Construction of three baby tetrahedrons
301+ (nextPortal, r1,r2,r3) = createBabyTetrahedrons (r0,r1,r2,r3,r4)
302+
303+ if ! nextPortal # createBabyTetrahedrons failed
304+ @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, r4. a, r4. b, r4. n, true , r1. a, r1. b, r2. a, r2. b, r3. a, r3. b)
308+ end
309+ if isTC3
310+ (distance,r1,r2,r3,r4) = finalTC3 (r0, r1_new, r2_new, r3_new, r4_new)
311+ return (distance, r4. a, r4. b, r4. n, true , r1. a, r1. b, r2. a, r2. b, r3. a, r3. b)
312+ end
313+ end
314+ end
315+ @warn (" MPR (phase 3): Numerical issues with distance computation between $(Modia3D. fullName (shapeA)) and $(Modia3D. fullName (shapeB)) . Max. number of iterations (= $niter_max ) is reached. niter_max increased locally by 10 and phase 3 is rerun until counter is bigger than 100." )
316+
317+ if niter_max < 100
318+ phase3 (r0, r1org, r2org, r3org, neps, niter_max + 10 , tol_rel, shapeA, shapeB, scale)
319+ else
320+ @warn (" MPR (phase 3): Max. number of iterations (= $niter_max ) is reached and $niter_max > 100. tol_rel increased locally for this computation to $new_tol ." )
321+
322+ if isTC2
323+ (distance,r1,r2,r3,r4) = finalTC2 (r1_new,r2_new,r3_new,r4_new)
324+ return (distance, r4. a, r4. b, r4. n, true , r1. a, r1. b, r2. a, r2. b, r3. a, r3. b)
325+ end
326+ if isTC3
327+ (distance,r1,r2,r3,r4) = finalTC3 (r0, r1_new, r2_new, r3_new, r4_new)
328+ return (distance, r4. a, r4. b, r4. n, true , r1. a, r1. b, r2. a, r2. b, r3. a, r3. b)
329+ end
330+ end
331+ end
332+
246333# MPR - Minkowski Portal Refinement algorithm
247334# construction of points r0 is in the interior of Minkowski Difference and points r1,r2,r3,r4 are on the boundary of Minkowski Difference
248335# Phase 1
@@ -322,79 +409,7 @@ function mprGeneral(ch::Composition.ContactDetectionMPR_handler, shapeA::Composi
322409
323410
324411 # ########## Phase 3, Minkowski Portal Refinement ###################
325- new_tol = 42.0
326- isTC2 = false
327- isTC3 = false
328- r1_new:: SupportPoint = r0
329- r2_new:: SupportPoint = r0
330- r3_new:: SupportPoint = r0
331- r4_new:: SupportPoint = r0
332- for i in 1 : niter_max
333- # ## Phase 3.1: construct r4 ###
334- # Find support point using the tetrahedron face
335- (r3,r4,n4) = constructR4 (r0,r1,r2,r3,neps,shapeA,shapeB, scale)
336-
337-
338- # ## Phase 3.2: check if r4 is close to the origin ###
339- # check if the new point r4 is already on the plane of the triangle r1,r2,r3,
340- # we're already as close as we can get to the origin
341- TC2 = norm (cross (r4. p,r4. n)) # TC2
342- TC3 = abs (dot (r4. p- r1. p, r4. n)) # TC3
343- # # TERMINATION CONDITION 2 ##
344- if TC2 < tol_rel
345- (distance,r1,r2,r3,r4) = finalTC2 (r1,r2,r3,r4)
346- return (distance, r4. a, r4. b, r4. n, true , r1. a, r1. b, r2. a, r2. b, r3. a, r3. b)
347-
348- # # TERMINATION CONDITION 3 ##
349- elseif TC3 < tol_rel
350- (distance,r1,r2,r3,r4) = finalTC3 (r0, r1, r2, r3, r4)
351- return (distance, r4. a, r4. b, r4. n, true , r1. a, r1. b, r2. a, r2. b, r3. a, r3. b)
352- else
353- if TC2 < new_tol
354- new_tol = TC2
355- isTC2 = true
356- isTC3 = false
357- r1_new = r1
358- r2_new = r2
359- r3_new = r3
360- r4_new = r4
361- end
362- if TC3 < new_tol
363- new_tol = TC3
364- isTC2 = false
365- isTC3 = true
366- r1_new = r1
367- r2_new = r2
368- r3_new = r3
369- r4_new = r4
370- end
371- end
372-
373- # ### Phase 3.3: construct baby tetrahedrons with r1,r2,r3,r4 and create a new portal ###
374- # Construction of three baby tetrahedrons
375- (nextPortal, r1,r2,r3) = createBabyTetrahedrons (r0,r1,r2,r3,r4)
376-
377- if ! nextPortal # createBabyTetrahedrons failed
378- @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- if isTC2
380- (distance,r1,r2,r3,r4) = finalTC2 (r1_new,r2_new,r3_new,r4_new)
381- return (distance, r4. a, r4. b, r4. n, true , r1. a, r1. b, r2. a, r2. b, r3. a, r3. b)
382- end
383- if isTC3
384- (distance,r1,r2,r3,r4) = finalTC3 (r0, r1_new, r2_new, r3_new, r4_new)
385- return (distance, r4. a, r4. b, r4. n, true , r1. a, r1. b, r2. a, r2. b, r3. a, r3. b)
386- end
387- end
388- end
389- @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 ." )
390- if isTC2
391- (distance,r1,r2,r3,r4) = finalTC2 (r1_new,r2_new,r3_new,r4_new)
392- return (distance, r4. a, r4. b, r4. n, true , r1. a, r1. b, r2. a, r2. b, r3. a, r3. b)
393- end
394- if isTC3
395- (distance,r1,r2,r3,r4) = finalTC3 (r0, r1_new, r2_new, r3_new, r4_new)
396- return (distance, r4. a, r4. b, r4. n, true , r1. a, r1. b, r2. a, r2. b, r3. a, r3. b)
397- end
412+ phase3 (r0, r1, r2, r3, neps, niter_max, tol_rel, shapeA, shapeB, scale)
398413end
399414
400415
0 commit comments