Extract cross sections from a plot of multiple spheres in Matlab -


i know locations of spheres (center , radius) in box. want extract cross sections. able plot spheres placed in cube using following matlab code:

[x,y,z] = sphere; spnum = 1:numspheres     surf( x*radius(spnum)+center(spnum,1), y*radius(spnum)+center(spnum,2), z*radius(spnum)+center(spnum,3), ...     'facecolor','r' ); %shading interp; hold on; end axis tight; daspect([1 1 1]); 

in above code, each sphere have different radius , not overlap (so centers different).

the above code not generate cross sections. want extract cross sections similar x-ray ct data: series of images in z-direction. think 'interp2/interp3' , 'slice' functions relevant functions, not sure how use them generate cross sections. appreciate if give pointers or provide sample code problem?

-- in advance.

update:

i tried using meshgrid generate grid points followed function f(x,y,z) follows:

[x,y,z] = meshgrid(1:100,1:100,1:100); f = zeros(size(x),'uint8'); spnum = 1:numspheres     f( sqrt((x - center(spnum,1)).^2 + (y - center(spnum,2)).^2 + (z -     center(spnum,3)).^2) <= radius(spnum) ) = 1; end surf(f); 

followed by:

z = 1; = interp3(x, y, z, x*radius(spnum)+center(spnum,1), y*radius(spnum)+center(spnum,2), z*radius(spnum)+center(spnum,3), z, 'spline'); figure, imshow(i); 

i know interp3 function use since interpolates values of function f(x,y,z) represent spheres @ different location within bounded box (say 1:100, 1:100, 1:100). interpolated values @ particular 'z' (= 1, 2, 3... 100) should give me 100 cross sections (in form of 2-d images).

the flaw in function f itself, since 'surf' throws error saying f should array - "cdata must m-by-n matrix or m-by-n-by-3 array".

can please help.

i figured it. benefit of others, here code.

% 3-d matrix 'f' has value @ particular coordinate set 255 if belongs 1 of spheres , 0 otherwise. [x,y,z] = meshgrid(1:100,1:100,1:100); f = zeros(size(x)); spnum = 1:numspheres     f( sqrt((x - center(spnum,1)).^2 + (y - center(spnum,2)).^2 + (z - center(spnum,3)).^2) <= radius(spnum) ) = 255;         end % extract cross sections f using interp3 function along z-axis. = zeros(size(x)); z = 1:100     i(:,:,z) = interp3(x, y, z, f, 1:100, (1:100)', z, 'spline'); end implay(i,4); 

you test , visualize output setting center (a 3-d vector) , radius of each sphere (some arbitrary numspheres) random values. above code display window cross-sections.

previously, trying use 'surf' render spheres not right. render, have use first code snippet. mistake made using row vector 6th argument instead of column vector.

hope helps.

-- cheers, ram.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -