matlab - 不同大小颗粒的 3D MATLAB 散点图

标签 matlab plot 3d scatter-plot particles

我正在寻找一种可靠的方法来绘制具有 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])中获得),有可能调整图形窗口的大小并仍然获得相对于颗粒表观大小的适当轴比例):

3D plot of the particles, the color and the size of which represent the radius. Note that the size of the particles is computed that's to the radius.

最佳答案

fourth argumentscatter3以平方点(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');

这是由此产生的情节:

enter image description here

请注意,表面默认根据高度着色。如果你想给它们不同的颜色,你可以修改 CDataFaceColor表面的属性。例如,您可以通过将上面的 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/

相关文章:

image - 如何输出层叠图像或堆叠图像

matlab - 内部和外部颜色不同的表面绘图

r - 图例不显示颜色

R 用不同组的数据绘制图表

matlab - 检测时间扩散回波

android - 有没有办法在 android studio 中使用 SVM 模型(在 matlab 中训练)?

R 绘图限制和轴标签/标题之间的通用距离

c - MS3D 解析 : boneID == joint ID?

performance - 如何加快行进立方体?

c# - 有没有办法在 C# 中用 winforms 或 WPF 制作 3D 游戏?