Advertisement
Guest User

Untitled

a guest
Oct 16th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. class Box3D:
  2. def __init__(self, centerX, centerY, centerZ, width, height, depth):
  3. self.centerX = float(centerX)
  4. self.centerY = float(centerY)
  5. self.centerZ = float(centerZ)
  6. self.width = float(width)
  7. self.height = float(height)
  8. self.depth = float(depth)
  9. def setCenter(self, x, y, z):
  10. self.centerX = float(x)
  11. self.centerY = float(y)
  12. self.centerZ = float(z)
  13. def setwidth1(self, width):
  14. self.width = float(width)
  15. def setheight1(self, height):
  16. self.height = float(height)
  17. def setDepth(self, depth):
  18. self.depth = float(depth)
  19. def volume_1(self):
  20. return ((self.width * self.height) * self.depth)
  21. def surfaceArea1(self):
  22. return (2 * ((self.width * self.height) + (self.height * self.depth) + (self.depth * self.width)))
  23. def overlaps(self, otherBox3D):
  24. return (((self.centerX <= otherBox3D.width) and (self.width >= otherBox3D.centerX)) and ((self.centerY <= otherBox3D.height) and (self.height >= otherBox3D.centerY)))
  25. def __repr__(self):
  26. 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) +')')
  27.  
  28. box1 = Box3D(10.0, 5.0, 0.0, 2.0, 1.0, 1.0)
  29. print (box1)
  30. box2 = Box3D(0, 0, 0, 3.5, 2.5, 1.0)
  31. print (box1.volume_1())
  32. print (box2.surfaceArea1())
  33. print (box1.overlaps(box2))
  34. box1.setCenter(2.75, 0.0, 0.0)
  35. print (box1.overlaps(box2))
  36. box1.setCenter(2.76, 0.0, 0.0)
  37. print (box1.overlaps(box2))
  38. box1.setCenter(2.75,1.75,1.0)
  39. print (box1.overlaps(box2))
  40. box1.setCenter(0.0,0.0,0.0)
  41. print (box1.overlaps(box2))
  42. box1.setwidth1(50.0)
  43. print (box1.overlaps(box2))
  44. box1.setDepth(50.0)
  45. print (box2.overlaps(box1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement