在 Matlab 中以 3D 形式围绕给定坐标绘制球体
Plotting spheres around given coordinates in 3D in Matlab
我正在研究一个物体在一些粗糙表面上滑动的模型,该表面由位置随机变化很小的球体组成。在图形中,我希望球体具有给定的半径,但是当使用 scatter3 时,这将不起作用,当我放大或缩小时,圆圈的大小会发生变化。我可以通过使用 "rectangle"-function 在 2D 中轻松解决这个问题,但对于 3D 这不起作用。
有没有更好的函数可以围绕点绘制球体?
我已阅读这篇文章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。但它要么对 scatter3 不起作用,要么我做错了。
放大时尺寸会改变。
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
代码的相关部分。将坐标设置为球体的中心并围绕它们绘制球体。
这是我根据 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
我正在研究一个物体在一些粗糙表面上滑动的模型,该表面由位置随机变化很小的球体组成。在图形中,我希望球体具有给定的半径,但是当使用 scatter3 时,这将不起作用,当我放大或缩小时,圆圈的大小会发生变化。我可以通过使用 "rectangle"-function 在 2D 中轻松解决这个问题,但对于 3D 这不起作用。
有没有更好的函数可以围绕点绘制球体?
我已阅读这篇文章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。但它要么对 scatter3 不起作用,要么我做错了。
放大时尺寸会改变。
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
代码的相关部分。将坐标设置为球体的中心并围绕它们绘制球体。
这是我根据 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