2
votes

I have an array of position and radius of multiple spheres. I am trying to express them in one single 3D volume plot so that i can see how well they are packed.

From the Matlab documentation i found the following code. What changes should i make so that we can express it for an array of position and radius for multiple spheres?

 [x,y,z] = sphere;
 figure
 surf(x,y,z)

 hold on
 surf(x+3,y-2,z); % centered at (3,-2,0)
 surf(x,y+1,z-3); % centered at (0,1,-3)
2

2 Answers

4
votes

you can use scatter3sph from the file exchange, it's like scatter3 only drawing spheres, instead of flat circles. It can represent three quantities: height (Z), color and size for each combination of two variables (X and Y). The spheres will look "spherical" no matter the axis scaling.

enter image description here

0
votes

I would not use sphere for visualizing several spherical objects in 3D, as it will produce ovoidal shapes - would need to play with aspect ratios that are problematic in 3D.

I would use instead a 3D-scatter plot with circle markers of different sizes. Here is a piece of code for 30 spheres.

pos = rand(30,3);       % position matrix
r = rand(30,1) * 1000;  % radius matrix, scaling is mandatory

scatter3( pos(:,1) , pos(:,2) , pos(:,3) , r , 'fill' )

enter image description here