答案 0 :(得分:4)
除了使用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
输出: