Code covered by the BSD License

Highlights from Minimal Bounding Box

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

Minimal Bounding Box

Johannes Korsawe (view profile)

09 Jan 2008 (Updated )

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

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
`/`
17 Nov 2015 ibtissem jbira

ibtissem jbira (view profile)

i need the algorithm of this code :
I did not understand how you calculated BOO
at the beginning you start with calucul of its convex hull but after I understood nothing !!!

Comment only
17 Feb 2015 Johannes Korsawe

Johannes Korsawe (view profile)

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!

Ishan

Comment only
16 Feb 2015 Johannes Korsawe

Johannes Korsawe (view profile)

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

Wolfgang (view profile)

18 Jan 2014 fourar redha

fourar redha (view profile)

17 Jan 2014 Matt Kindig

Matt Kindig (view profile)

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!