Code covered by the BSD License  

Highlights from
Minimal Bounding Box

4.85714
4.9 | 7 ratings Rate this file 36 Downloads (last 30 days) File Size: 5.04 KB File ID: #18264 Version: 1.1
image thumbnail

Minimal Bounding Box

by

 

09 Jan 2008 (Updated )

Minimal bounding box around points in the (x,y,z) space

| Watch this File

File Information
Description

With this function one can easily compute the minimal box (with right angles) around a set of points in 3d.
The extremal property of the box is determined either in terms of volume, surface or sum of edgelengths.

The calculation is based on heuristics only, but a huge number of tests did not show any counterexamples yet.

The algorithm behind the function is subdivided into three levels of accuracy with differing runtimes.

x = rand(10000,1);
y = rand(10000,1);
z = rand(10000,1);

tic;[rotmat,cornerpoints,volume,surface] = minboundbox(x,y,z,'v',3);toc
Elapsed time is 10.772170 seconds.

volume =
    0.9993
surface =
    5.9974

My thanks to John d'Errico and Roger Stafford for numerous discussions about proofs and algorithms in this context.

John also wrote minboundrect from the FEX, which heavily influenced this submission.

Also in this archive i included a small plot function (plotminbox) to show the resulting box via connecting the cornerpoints.

Acknowledgements

A Suite Of Minimal Bounding Objects inspired this file.

Required Products MATLAB
MATLAB release MATLAB 8.4 (R2014b)
MATLAB Search Path
/
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (11)
17 Feb 2015 Johannes Korsawe

Ishan,
i tested the code on the latest release R2014b and it worked. No idea what is going wrong on your side. The error has to be debugged on your system line by line.
Regards, Johannes

Comment only
16 Feb 2015 Ishan

Ishan (view profile)

Johannes,

Indeed, I replaced it with convhulln and the necessary argument. However, the error persists.

Are there any online resources available which can guide me through the process which you have used to program this function?

I am planning to write an updated version of your function which will be compatible for more recent versions of MATLAB. If I can gain a clear understanding of the background, perhaps I will be able to release it on FEX.

Any help would be much appreciated!

Thank you for your time,
Ishan

Comment only
16 Feb 2015 Johannes Korsawe

Ishan,
i wrote an update for releases >= 2010a. Perhaps convhull failed in your test.
Best, Johannes

Comment only
14 Feb 2015 Ishan

Ishan (view profile)

On MATLAB 2014a, I am encountering the following error:

Error using *
Inner matrix dimensions must agree.

Error in minboundbox>minrect (line 310)
rot_i = Rmat(-edgeangles(i));xyr = xy*rot_i;

Error in minboundbox>checkbox (line 274)
rot2 = minrect(x_i,y_i,metric); % find the optimal
rotation around z-axis

Error in minboundbox (line 170)
[d, rotmat, minmax] =
checkbox(alpha(i),beta(i),gamma(i),xyz,metric,d,rotmat,minmax);

Could someone please help me understand what flags to look for (or tests to run) in order to debug this? For input, I've used Johannes example of 10000x1 rand vectors.

Comment only
11 Jun 2014 Wolfgang  
18 Jan 2014 fourar redha  
17 Jan 2014 Matt Kindig

A simple fix to reduce the run-time is to replace the line:

rot_i = Rmat(-edgeangles(i));

with these lines:
theta = -edgeangles(i);
rot_i = [cos(theta), sin(theta); -sin(theta) cos(theta)];

In my testing, this reduces the run-time by a factor of ~2.

26 Dec 2013 Shunzhou  
30 May 2013 jia

jia (view profile)

 
21 Jul 2011 Steven

Steven (view profile)

Nice work. Thank you.

01 May 2011 Mark

Mark (view profile)

This file saved me a ton of work, and has worked great for all of my tests, thanks!

Updates
16 Feb 2015 1.1

Compatability issues. Convhull changed in Release 2010a.

Contact us