Skip to content

Commit

Permalink
Revert "Increased resilience of minimal_bounding_sphere method"
Browse files Browse the repository at this point in the history
This reverts commit 40f500c, moving all miniball-related changes to #178.
  • Loading branch information
janbridley committed Feb 27, 2023
1 parent 40f500c commit 9b70d27
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions coxeter/shapes/polyhedron.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,31 +556,21 @@ def minimal_bounding_sphere(self):
'directly from PyPI using "pip install miniball".'
)

# Define a check function to ensure points lie within a sphere
def points_within_sphere(points, center, radius):
return np.linalg.norm(points - center, axis=1) <= radius

# The algorithm in miniball involves solving a linear system and
# can therefore occasionally be somewhat unstable. Applying a
# random rotation will usually fix the issue, and checking if
# points lie inside will guarantee a correct answer.
max_attempts = 20
# random rotation will usually fix the issue.
max_attempts = 10
attempt = 0
current_rotation = [1, 0, 0, 0]
vertices = self.vertices
while attempt < max_attempts:
attempt += 1
try:
center, r2 = miniball.get_bounding_ball(vertices)
assert np.all(points_within_sphere(vertices, center, np.sqrt(r2)))
break
except np.linalg.LinAlgError:
current_rotation = rowan.random.rand(1)
vertices = rowan.rotate(current_rotation, vertices)
except AssertionError:
print("Miniball sphere does not contain vertices. Retesting...")
current_rotation = rowan.random.rand(1)
vertices = rowan.rotate(current_rotation, vertices)
else:
raise RuntimeError("Unable to solve for a bounding sphere.")

Expand Down

0 comments on commit 9b70d27

Please sign in to comment.