Project a sphere into a plane using matlab

This is probably a very simple matlab, so forgive me. I use the command sphereto create a 3D sphere and has matrices x,y,zthat will produce it with surf. For instance:

[x,y,z]=sphere(64);

I would like to project (or summarize) this three-dimensional sphere into one of the Cartesian two-dimensional planes (for example, the XY plane) to get a 2D matrix that will be the projection of this sphere. Using imshowor imagescon output should look something like this:

enter image description here

simple summation obviously doesn't work, how can I do this in matlab?

+5
source share
3 answers

, , ; , , . , 3 , , ... ( sphere , " " " ", ). , , .

enter image description here

%% 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'
+1

X-Y Matlab, :

[x,y,z] = sphere(64);
surf(x,y,zeros(size(z)));

, Matlab , , ...

0

I would look at projections of maps that are designed for this purpose.

A search in "map projections matlab" provides Matrix documentation for mapping tools . However, if you need or need to minimize your own, there is a good summary on the USGS website as well as wikipedia .

0
source

All Articles