-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Game Physics Cookbook
By :
A containing rectangle is very similar to a containing circle. We will find the minimum non-oriented rectangle that contains a set of points. Depending on the shape being contained, a rectangle might be a tighter fit than a circle:

The ContainingRectangle function is going to be very similar to the ContainingCircle function. Just like ContainingCircle, this function will take an array of points, and a count of the number of points in the array. Given this set of input points, ContainingRectangle will return the minimum non-oriented rectangle that encompasses every point.
Follow these steps to create a function that will create a bounding rectangle from a set of points:
Declare the ContainingRectangle function in Geometry2D.h:
Rectangle2D ContainingRectangle(Point2D* pointArray, int arrayCount);
Implement the ContainingRectangle function in Geometry2D.cpp:
Rectangle2D ContainingRectangle(Point2D* pointArray,
int arrayCount) {
vec2 min =...