Split a bounding box into 4 parts


I have a series of bounding boxes defined using coordinates like this, minlon, minlat, maxlon, maxlat.

I need to be able to divide these bounding boxes into four equal smaller bounding boxes.

Does anyone know of an algorithm for achieving this? For added complexity the larger bounding box may cross the equator or the prime meridian.

As an example, one of the bounding boxes I have is this one:


I need to split this bounding box into four equal smaller bounding boxes.

Any thoughts are gratefully received.

What’s wrong with simply averaging?
centLon = (minLon + maxLon)/2.0;
centLat = (minLat + maxLat)/2.0;

then wrap around to make sure you’re not exceeding 90/180
something like
if(centLon -180 > 0)
centLon -= 360; (that’s 2 * 180)
else if (centLon + 180 < 0)
centLon += 360;

bbox0 = BBox(minLon, centLon, minLat, centLat);
bbox1 = BBox(centLon, maxLon, minLat, centLat);
bbox2 = BBox(minLon, centLon, centLat, maxLat);
bbox3 = BBox(centLon, maxLon, centLat, maxLat);