使用matlab将球体投影到平面上

5 3d matlab geometry 2d projection

这可能是非常基本的matlab,所以请原谅我.我使用命令sphere创建一个3D球体,并x,y,z使用冲浪产生它的矩阵.例如:

[x,y,z]=sphere(64);
Run Code Online (Sandbox Code Playgroud)

我想将这个3D球体投影(或求和)到一个笛卡尔2D平面(例如XY平面)中,以获得将成为该球体投影的2D矩阵.使用imshowimagesc输出应该看起来像这样:

在此输入图像描述

简单的求和显然不起作用,我怎样才能在Matlab中实现呢?

Flo*_*ris 1

我可能完全误解了你的问题,在这种情况下我深表歉意;但我认为以下三种方法之一实际上可能正是您所需要的。请注意,方法 3 给出的图像看起来很像您提供的示例...但我以非常不同的路线到达那里(根本不使用该sphere命令,而是通过直接工作来计算“内部体素”和“外部体素”以及距中心的距离)。我将第二张图像与第三张图像进行了反转,因为这样看起来更好 - 用零填充球体使其看起来几乎像一个黑色圆盘。

在此输入图像描述

%% method 1: find the coordinates, and histogram them
[x y z]=sphere(200);
xv = linspace(-1,1,40);
[xh xc]=histc(x(:), xv);
[yh yc]=histc(y(:), xv);

% sum the occurrences of coordinates using sparse:
sm = sparse(xc, yc, ones(size(xc)));
sf = full(sm);

figure; 
subplot(1,3,1);
imagesc(sf); axis image; axis off
caxis([0 sf(19,19)]) % add some clipping
title 'projection of point density'

%% method 2: fill a sphere and add its volume elements:
xv = linspace(-1,1,100);
[xx yy zz]=meshgrid(xv,xv,xv);
rr = sqrt(xx.^2 + yy.^2 + zz.^2);
vol = zeros(numel(xv)*[1 1 1]);
vol(rr<1)=1;
proj = sum(vol,3);
subplot(1,3,2)
imagesc(proj); axis image; axis off; colormap gray
title 'projection of volume'

%% method 3: visualize just a thin shell:
vol2 = ones(numel(xv)*[1 1 1]);
vol2(rr<1) = 0;
vol2(rr<0.95)=1;
projShell = sum(vol2,3);
subplot(1,3,3);
imagesc(projShell); axis image; axis off; colormap gray
title 'projection of a shell'
Run Code Online (Sandbox Code Playgroud)