Skip to content

Commit

Permalink
Merge pull request #267 from vpython/bounding_box
Browse files Browse the repository at this point in the history
fix bound_box
  • Loading branch information
BruceSherwood authored Mar 3, 2024
2 parents 4d34e51 + 4b65186 commit 8c81da5
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions vpython/vpython.py
Original file line number Diff line number Diff line change
Expand Up @@ -1078,16 +1078,20 @@ def rotate(self, angle=None, axis=None, origin=None):
self.addattr('pos')

def bounding_box(self):
centered = ['box', 'compound', 'ellipsoid', 'sphere', 'simple_sphere', 'ring']
centered = False
if self._objName in ['box', 'ellipsoid', 'sphere', 'simple_sphere', 'ring']:
centered = True
elif self._objName[:8] == 'compound': # compound ObjName has trailing index
centered = True
x = norm(self._axis)
y = norm(self._up)
z = norm(cross(x,y))
L = self._size.x
H = self._size.y
W = self._size.z
p = vector(self._pos) # make a copy of pos, so changes to p won't affect the object
if self._objName not in centered:
p = p + 0.5*L*x # move to center
if not centered:
p += 0.5*L*x # move to center
pts = []
for dx in [-L/2, L/2]:
for dy in [-H/2, H/2]:
Expand Down

0 comments on commit 8c81da5

Please sign in to comment.