Home Plotting spheres around given coordinates in 3D in Matlab

# Plotting spheres around given coordinates in 3D in Matlab

Slobodan
1#
Slobodan Published in 2018-01-12 11:17:53Z
 I am working on model of an object sliding on some rough surface consisting of spheres with a small random variance in position. In the graphics I want the spheres to be of a given radius, however when using scatter3 this wont work, the sizes of the circles change when I zoom in or out. I could easily solve this in 2D by using "rectangle"-function instead but for 3D this doesn't work. Is there a better function for plotting spheres around points? I have read this https://se.mathworks.com/matlabcentral/answers/101738-how-do-i-specify-the-size-of-the-markers-created-by-the-scatter-plot-in-units-proportional-to-the-da. But it either doesn't work for scatter3 or I do it wrong. Sizes change when zooming in. fig = figure(1); hold on daspect([1,1,1]); surface.xnum = 16; surface.znum = 16; surface.r = 1; circlenumber = 0; for n = 1:surface.xnum for m = 1:surface.znum circlenumber = circlenumber + 1; surface.circlecentre(circlenumber,:) = [n + 0.1*surface.r*randn , 0, m + 0.1*surface.r*randn ]; plt.surface = scatter3(surface.circlecentre(circlenumber, 1),surface.circlecentre(circlenumber, 2),surface.circlecentre(circlenumber, 3), 850*surface.r,'filled','r','MarkerEdgeColor','k'); end end  Relevant part of the code. Setting coordinates to center of the spheres and plotting spheres around them.
Slobodan
2#
 This was the solution i found by the hint from Ander Biguri. I used surf to plot spheres instead of scatter3. fig = figure(1); hold on daspect([1,1,1]); colormap summer shading interp % removes the lines in surfplot surface.xnum = 8; surface.znum = 8; surface.r = 0.75; circlenumber = 0; for m = 1:surface.xnum for n = 1:surface.znum circlenumber = circlenumber + 1; surface.circlecentre(circlenumber,:) = [m + 0.1*surface.r*randn ,0 , n + 0.1*surface.r*randn ]; [x,y,z] = sphere; surf(x*surface.r+m*2*surface.r+0.1*surface.r*randn, y*surface.r, z*surface.r+n*2*surface.r+0.1*surface.r*randn,'Edgecolor','none'); end end