最佳答案
这是我如何使用 bubbleplot3 来做到这一点除了使用 warp 之外,还可以从文件交换中绘制一组均匀分布的球体将图像显示为球体的纹理映射表面。基本上使用bubbleplot3
创建球体,然后在for循环中获取每个单独的表面对象,并对它们调用warp
以用图像替换其纹理贴图。
对于生成网格立方体,我没有任何功劳,并且稍微修改了@Raf的答案here .
clc;clear;close all
%// Read image
C = flipud(imread('peppers.png'));
%// Generate array of spheres
Radius = 1;
[x,y,z] = meshgrid(0:2:4,0:2:4,0:2:4);
r=repmat(Radius,1,numel(x));
%// Call bubbleplot3
hBubble = bubbleplot3(x,y,z,r,[],[],[],[]);
hold on
%// Get surfaces objects
SurfHandles = findobj('type','surface');
%// Use warp function to replace colordata with image
for k = 1:numel(SurfHandles)
warp(SurfHandles(k).XData,SurfHandles(k).YData,SurfHandles(k).ZData,C)
end
%// Now cube.
%// Credit to Raf here: https://stackoverflow.com/questions/7309188/how-to-plot-3d-grid-cube-in-matlab
CubeData = -1:2:5;
[X, Y] = meshgrid(CubeData,CubeData);
x = [X(:) X(:)]';
y = [Y(:) Y(:)]';
z = [repmat(CubeData(1),1,length(x)); repmat(CubeData(end),1,length(x))];
col = 'b';
plot3(x,y,z,col,'Color','k');
plot3(y,z,x,col,'Color','k');
plot3(z,x,y,col,'Color','k');
rotate3d on
并输出:
关于matlab - 每个单元格中都有球体的 3D 网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32338615/