How to compute volume and aspect ratio of a 3D geometry?
8 views (last 30 days)
Show older comments
I have a set of (x,y,z) coordinates, which typically represent a 3D geometrical object. Is there any MATLAB function that returns:
- The volume occupied by that object
- The aspect ratio of that object.
Aspect ratio is its size along y-axis divided by its size along x-axis.
1 Comment
sankar basu
on 28 Nov 2020
Edited: sankar basu
on 28 Nov 2020
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
Accepted Answer
Sean de Wolski
on 21 Jan 2011
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
Sean de Wolski
on 21 Jan 2011
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
More Answers (0)
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!