How to compute volume and aspect ratio of a 3D geometry?

I have a set of (x,y,z) coordinates, which typically represent a 3D geometrical object. Is there any MATLAB function that returns:
  1. The volume occupied by that object
  2. The aspect ratio of that object.
Aspect ratio is its size along y-axis divided by its size along x-axis.

1 Comment

Hi Guys,
Very much stuck at the same problem. From a bunch of 3D (irregular) objects ([x,y,z] points) I need to dettermine a simple way to quickly tell whether each one is essentially elongated or roughly-spherical (~globular). This then works as a flag to send it to an appropriate subroutine out of two alternatives to accomplish certain objectives. Apparently, one or the other function works perfectly fine for all examples (full dataset) but I need a programmatically flag each (at the begining of the code) to automatically send them to the appropriate functions (based on overall shape). Tried different brute-force meassures but would wonder and prefer if there's aleardy an inbuilt MATLAB function that is well-tested to have done it correctly! Aspect ratio from a set of points comes as a first natural preference but what I find with that parameter in MATLAB are functions that can only report and reset the aspect ration of plots (daspect, pbaspect). The other possibility that comes to mind is to fit an ellipsoid (and I have the following function that does it) and make it return the ratio of its long and short axes (and this second part is the one which I am not sure how to to accomplish). The max pairwise distance of surface points on the surface of the fitted ellipsoid gives the length of the long axis for sure but then how can one find the short-axes! Any help would be deeply appriciated.
Thanks in anticipation.
Best Regards,
Sankar
function Y=el3(X)
% Y = el3(X) where X is a 3*1 matrix (3D coordinates)
Y=X;
oldmu =mean(X);
X= bsxfun(@minus,X,oldmu); % mean-centered data
[pc val] = eig(X'*X);
nC = X*pc; % data in principle coordinate
a2=(max(nC(:,1))-min(nC(:,1)))/2; %range of data in X
b2=(max(nC(:,2))-min(nC(:,2)))/2; %range of data in Y
c2=(max(nC(:,3))-min(nC(:,3)))/2; %range of data in Z
[x, y, z] = ellipsoid(0,0,0,a2,b2,c2,40);
% fit ellipsoid in principle coordinate
tt=[x(:) y(:) z(:)]*inv(pc); % ellipsoid in non-principle coordinate
nx=reshape(tt(:,1),size(x,1),size(x,2));
ny=reshape(tt(:,2),size(x,1),size(x,2));
nz=reshape(tt(:,3),size(x,1),size(x,2));
% plot ellipsoid in non-principle coordinate
length(nx);
CO1(:,:,1) = zeros(length(nx)); % red
CO1(:,:,2) = ones(length(nx)).*linspace(0.5,0.6,length(nx)); % green
CO1(:,:,3) = ones(length(nx)).*linspace(0,1,length(nx)); % blue
hSurface=surf(nx+oldmu(1), ny+oldmu(2), nz+oldmu(3), CO1, 'EdgeColor','none', 'FaceAlpha',0.3);
hold on;
Y=[reshape(nx+oldmu(1),size(nx,1)*size(nx,2),1),reshape(ny+oldmu(2),size(ny,1)*size(ny,2),1),reshape(nz+oldmu(3),size(nz,1)*size(nz,2),1)];
% plot data in non-principle coordinate
% plot3(Y(:,1),Y(:,2),Y(:,3),'k.')
axis equal;
end

Sign in to comment.

 Accepted Answer

If the volume is convex then the second output argument to
convhulln
will be the volume. If it is not convex then there are tools on the FEX from Luigi Giaccari and Adam A. which will make a good approximation.
Good Luck!

6 Comments

Thanks Sean! In my case, the volume is always convex. So, convhulln works! Any idea about computing the aspect ratio?
Hi Sean, I moved your second "Answer" to this comment section.
Sean de:
Will you always want the aspect ratio based on the global axis? I.e. relative to x,y,z not longest internal dimension?
The definition of aspect ratio is actually one of the aims of my study, in scientific perspective. So answering your question, yes I need its value in either ways, based on the global as well as based on the longest internal dimension. Thanks for your interest!
Well global is easy,
max(x)-min(x)
is the biggest length in x; same for y/z.
For longest internal dimension, the only way I can think of right now is to brute force calculate the distance from every point to every other point:
sqrt((x1-x2).^2+(y1-y2).^2+(z1-z2).^2)
Then you'll have to do some interpolation to find the biggest contained plane orthogonal to this line.
Santosh,
It's difficult to reply in the comments since the text box is only three narrow lines and we can't have formatting. My $0.02
Thanks once again, Sean! I will try your suggestions soon. Have a nice day!

Sign in to comment.

More Answers (0)

Products

Asked:

on 21 Jan 2011

Edited:

on 28 Nov 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!