Containing rectangle
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:
Getting ready
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.
How to do it…
Follow these steps to create a function that will create a bounding rectangle from a set of points:
Declare the
ContainingRectangle
function inGeometry2D.h
:Rectangle2D ContainingRectangle(Point2D* pointArray, int arrayCount);
Implement the
ContainingRectangle
function inGeometry2D.cpp
:Rectangle2D ContainingRectangle(Point2D* pointArray, int arrayCount) { vec2 min =...