File Exchange

## 2D minimal bounding box

version 1.1.0.0 (1.95 KB) by
Compute quickly the minimal bounding box of a set of 2D points

21 Downloads

Updated 06 May 2011

View License

Compute the minimal bounding box of a set of 2D points, similarly to the "Minimal Bounding Rectangle" of John D'Errico.

However:
- The algorithm is fully vectorized (matlab implementation, no for loop). Thus it is better for big set of points
- It computes only the minimum area rectangle, not the minimum perimeter

### Cite As

julien diener (2020). 2D minimal bounding box (https://www.mathworks.com/matlabcentral/fileexchange/31126-2d-minimal-bounding-box), MATLAB Central File Exchange. Retrieved .

### Comments and Ratings (14)

Manoj Dhiman

Worked like a charm!!

Ashim Neupane

Cuong Pham

Anurag Sai

deru jian

Manuel Celaya

Great and Simple Code! It just does exactly what I needed.

Thanks Julien!

Steven Michaels

Leox91

Josh Peters

Christopher

Excellent script! Did EXACTLY what I was looking for. Thanks & Good Job!

julien diener

I corrected the bug (wait a few days for it to be updated on this site). Actually it is strange that it worked before...
Thanks for the remark.

John, if you want to update your file with my vectorized algorithm, I don't mind. Yours is more polished.

Frank Fournel

Hello,
I was looking for this kind of code. Thank you very much it is very helpfull.... but it does not work well. If you remove the outlier, you should find back the rectangle. And sometime (quite often) it is not the case. I've not found yet why there is a bug. I will use the John D'Errico's code instead at the moement.

Sean de

Well done!

A (small) speed gain to be had if you assign:
bb(:,4) = bmax(1)*Rf(:,1) + bmin(2)*Rf(:,2);
first as to preallocate bb.

John D'Errico

A nice refinement of my code, using the same ideas that made it efficient (i.e, we need only look at the edges from the convex hull) but then avoiding an explicit loop (by use of a vectorized form) over those edges. Well done by Julien.

### Updates

 6 May 2011 1.1.0.0 bug corrected
##### MATLAB Release Compatibility
Created with R2007a
Compatible with any release
##### Platform Compatibility
Windows macOS Linux
##### Acknowledgements

Inspired: Protein Array Tool