Question: 1. Create a Box class, representing rectangular 3D boxes. The boxes can be any size and can be located anywhere in 3D space, but in

1. Create a Box class, representing rectangular 3D boxes. The boxes can be any size and can be located anywhere in 3D space, but in this simple version their orientations are fixed so that their edges are always aligned with/parallel to coordinate system axes. You class must implement all the methods below:

__init__(self, centerX = 0.0, centerY = 0.0, centerZ = 0.0, width = 1.0, height = 1.0, depth = 1.0)

setCenter(self, x, y, z)

setWidth(self, width)

setHeight(self, height)

setDepth(self, depth)

volume(self)

surfaceArea(self)

overlaps(self, otherBox)

contains(self, otherBox)

__repr__(self)

Note that "width" is a box's extent along the x dimension, while "height" and "depth" are the y and z extents, respectively. box1.overlaps(box2) should return True if the two 3D boxes touch/intersect at all (even they just touch exactly at their edges or corners). box1.contains(box2) should return True if no point of box2 is outside of box1 Note: think carefully about the overlaps and contains test. It is easy to get these wrong. I recommend (before you start coding) sketching some pictures to help you analyze the possibilities. Use of the class in a Python shell might look like this:

 >>> box1 = Box(10.0, 5.0, 0.0, 2.0, 1.0, 1.0) >>> box1 < 2-by-1-by-1 3D box with center at (10.0, 5.0, 0.0) > >>> box2 = Box(0, 0, 0, 3.5, 2.5, 1.0) >>> box1.volume() 2.0 >>> box2.surfaceArea() 29.5 >>> box1.overlaps(box2) False >>> box1.setCenter(2.75, 0.0, 0.0) >>> box1.overlaps(box2) True >>> box1.setCenter(2.76, 0.0, 0.0) >>> box1.overlaps(box2) False >>> box1.setCenter(2.75, 1.75, 1.0) >>> box1.overlaps(box2) True >>> box1.setCenter(0.0, 0.0, 0.0) >>> box1.overlaps(box2) True >>> box1.setWidth(50.0) >>> box1.overlaps(box2) True >>> box1.setDepth(50.0) >>> box2.overlaps(box1) True >>> box3 = Box(0, 0, 0) >>> box2.contains(box3) True >>> box4 = Box(10.0, 5.0, 0.0, 2.0, 1.0, 1.0) >>> box4.contains(box3) False 

As part of your .py file for this problem, include a testBox function that demonstrates use of the Box class, printing helpful output.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!