Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Computing a smallest (axis-aligned) rectangle that encloses a set of objects in

ID: 3592128 • Letter: C

Question

Computing a smallest (axis-aligned) rectangle that encloses a set of objects in the plane is a very common computational problem arising in graphics and thus game development too. Write a function, called min_enclosing_rectangle, that has 3 input parameters. The first is a number representing a radius of a circle and the next two are two numbers representing the x- and y-coordinates of its center. Consider the smallest axis-aligned rectangle that contains that circle. The function should return the x- and y-coordinates of the bottom-left corner of that rectangle. If side is a negative number, min_enclosing_rectangle should return None. The question should be done in python 3

Explanation / Answer

Here ABC'D' is the bounding box.

After you're certain there's a collision, you need to check which above case it belongs to. If the bottom of the rectangle is above the center, then the first, if the top is above but the bottom is below, then it's the second case, and if the top is below the center, then it's the third.

If it's the first or the third case and the rectangle goes right (it has a positive velocity), then you need to set the center's x coordinate based on the algorithm:

where r is the radius of the circle.

If the rectangle is goes left (it has a negative x velocity), then the new center's x coordinate is

If it's the second case and the rectangle goes right, then the new center x is

And if it goes to left, the new x is

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote