我正在寻找一种可靠的方法来绘制具有 3D 坐标和半径的 3D 粒子:
x=[0 1 1 0 0 1 1 0]';
y=[0 0 1 1 0 0 1 1]';
z=[0 0 0 0 1 1 1 1]';
radius=[0.1 0.5 0.1 1 1 0.4 0.6 0.2]';
我尝试使用:
scatter3(x,y,z,4/3*pi.*radius.^3,'filled')
问题:如何以保证相对大小和位置守恒的方式绘制粒子(因此当修改窗口大小时,粒子看到它们的大小随轴相应地调整)?
基本上,我想在 MATLAB 中获得以下图表(我使用 Ovito 从我生成的 .xyz(文本)文件(它包含 [x;y;z;radius])中获得),有可能调整图形窗口的大小并仍然获得相对于颗粒表观大小的适当轴比例):
最佳答案
fourth argument至 scatter3
以平方点(1 点 = 1/72 英寸)为单位定义标记区域,它与图形/屏幕大小相关,因此与轴数据单位无关。如果您想定义粒子相对于位置数据的半径(这样原点处半径为 1 的粒子将在 x、y 和 z 方向上跨越 [-1 1]
)那么 scatter3
将不起作用。
一种选择是将每个粒子绘制为 sphere使用 surf
,如图所示here .以下是使用示例数据执行此操作的方法:
% Data and unit sphere surface coordinates:
x = [0 1 1 0 0 1 1 0].';
y = [0 0 1 1 0 0 1 1].';
z = [0 0 0 0 1 1 1 1].';
radius = [0.1 0.5 0.1 1 1 0.4 0.6 0.2].';
[xS, yS, zS] = sphere;
% Plot spheres:
for pt = 1:numel(x)
surf(x(pt)+xS.*radius(pt), ... % Shift and scale x data
y(pt)+yS.*radius(pt), ... % Shift and scale y data
z(pt)+zS.*radius(pt), ... % Shift and scale z data
'EdgeColor', 'none');
hold on;
end
% Modify figure and axes:
axis equal
set(gcf, 'Color', 'k');
set(gca, 'Color', 'k', 'Box', 'on', 'BoxStyle', 'full', ...
'XColor', 'w', 'YColor', 'w', 'ZColor', 'w', 'GridColor', 'none');
这是由此产生的情节:
请注意,表面默认根据高度着色。如果你想给它们不同的颜色,你可以修改 CData
和 FaceColor
表面的属性。例如,您可以通过将上面的 surf
调用修改为:
surf(x(pt)+xS.*radius(pt), ...
y(pt)+yS.*radius(pt), ...
z(pt)+zS.*radius(pt), ...
radius(pt).*ones(size(xS)), ...
'FaceColor', 'flat', 'EdgeColor', 'none');
关于matlab - 不同大小颗粒的 3D MATLAB 散点图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46495863/