1

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. enter image description here

enter image description here

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.

4

1 回答 1

0

这是我从 Ander Biguri 的提示中找到的解决方案。我使用 surf 来绘制球体而不是 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
于 2018-01-12T14:12:04.783 回答