Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Box3D:
- def __init__(self, centerX, centerY, centerZ, width, height, depth):
- self.centerX = float(centerX)
- self.centerY = float(centerY)
- self.centerZ = float(centerZ)
- self.width = float(width)
- self.height = float(height)
- self.depth = float(depth)
- def setCenter(self, x, y, z):
- self.centerX = float(x)
- self.centerY = float(y)
- self.centerZ = float(z)
- def setwidth1(self, width):
- self.width = float(width)
- def setheight1(self, height):
- self.height = float(height)
- def setDepth(self, depth):
- self.depth = float(depth)
- def volume_1(self):
- return ((self.width * self.height) * self.depth)
- def surfaceArea1(self):
- return (2 * ((self.width * self.height) + (self.height * self.depth) + (self.depth * self.width)))
- def overlaps(self, otherBox3D):
- return (((self.centerX <= otherBox3D.width) and (self.width >= otherBox3D.centerX)) and ((self.centerY <= otherBox3D.height) and (self.height >= otherBox3D.centerY)))
- def __repr__(self):
- return ('< ' + str(self.width) + '-by-' + str(self.height) + '-by-' + str(self.depth) + ' box with center at (' + str(self.centerX) + ',' + str(self.centerY) + ',' + str(self.centerZ) +')')
- box1 = Box3D(10.0, 5.0, 0.0, 2.0, 1.0, 1.0)
- print (box1)
- box2 = Box3D(0, 0, 0, 3.5, 2.5, 1.0)
- print (box1.volume_1())
- print (box2.surfaceArea1())
- print (box1.overlaps(box2))
- box1.setCenter(2.75, 0.0, 0.0)
- print (box1.overlaps(box2))
- box1.setCenter(2.76, 0.0, 0.0)
- print (box1.overlaps(box2))
- box1.setCenter(2.75,1.75,1.0)
- print (box1.overlaps(box2))
- box1.setCenter(0.0,0.0,0.0)
- print (box1.overlaps(box2))
- box1.setwidth1(50.0)
- print (box1.overlaps(box2))
- box1.setDepth(50.0)
- print (box2.overlaps(box1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement