@@ -556,31 +556,21 @@ def minimal_bounding_sphere(self):
556
556
'directly from PyPI using "pip install miniball".'
557
557
)
558
558
559
- # Define a check function to ensure points lie within a sphere
560
- def points_within_sphere (points , center , radius ):
561
- return np .linalg .norm (points - center , axis = 1 ) <= radius
562
-
563
559
# The algorithm in miniball involves solving a linear system and
564
560
# can therefore occasionally be somewhat unstable. Applying a
565
- # random rotation will usually fix the issue, and checking if
566
- # points lie inside will guarantee a correct answer.
567
- max_attempts = 20
561
+ # random rotation will usually fix the issue.
562
+ max_attempts = 10
568
563
attempt = 0
569
564
current_rotation = [1 , 0 , 0 , 0 ]
570
565
vertices = self .vertices
571
566
while attempt < max_attempts :
572
567
attempt += 1
573
568
try :
574
569
center , r2 = miniball .get_bounding_ball (vertices )
575
- assert np .all (points_within_sphere (vertices , center , np .sqrt (r2 )))
576
570
break
577
571
except np .linalg .LinAlgError :
578
572
current_rotation = rowan .random .rand (1 )
579
573
vertices = rowan .rotate (current_rotation , vertices )
580
- except AssertionError :
581
- print ("Miniball sphere does not contain vertices. Retesting..." )
582
- current_rotation = rowan .random .rand (1 )
583
- vertices = rowan .rotate (current_rotation , vertices )
584
574
else :
585
575
raise RuntimeError ("Unable to solve for a bounding sphere." )
586
576
0 commit comments