How can I project a 3-D sphere onto a 2-D surface?
47 次查看(过去 30 天)
显示 更早的评论
I got a matrix M with 3 col, n rows. The points created by the matrix are all on a sphere with radius r. In a seperate matrix, let's call it "U", same size. Has either 0's or the exact same row. (indicating parts of the the sphere that have been selected).
So a sphere where nothing has been selected is a 3xn matrix filled with 0's.
I want to project the sphere onto a 2D surface (lets ignore the z, and plot x and y), which gives me a "double" sphere, spanned by points. I used the scatter command to get this result. I shifted half of the circle down in y, so u would get two circles next to eachother.
Now... here's my question:
Can I create a memory efficient 2-D plot, in which the points are translated to "surface parts", in order to better indicate which parts of the sphere has been seen.
The reason for the memory efficient part is due to a constant refresh of the data.
See attached picture for an more visual explanation.
Added question: say I don't cut the circle in half in the middle, but say at 1/3. What would be the most easy way to "fold" the data points outward that would otherwise be obscured by the datapoints that have the same x&y, but different z points.
(see explanation in the left down corner)
Thanks in advance,
5 个评论
采纳的回答
Mohammad Abouali
2014-12-11
编辑:Mohammad Abouali
2014-12-11
This is called map projection. There are multiple methods. check any map projection resource.
The best resource is perhaps this:
MATLAB has a built-in command [x,y] = mfwdtran(lat,lon) There are some other command that might be helpful too, such as projfwd() .
These commands are part of "Mapping Toolbox".
更多回答(1 个)
matt dash
2014-12-11
编辑:matt dash
2014-12-11
Ok... based on your code above, if your question is just how you can quickly update the data to reflect new information about which points are on/off, the answer is that you can use NaNs to turn points off (looks like you already know this) and then set the x/y/z data of the trisurf or surf object to quickly update the sphere. Here is an example... on my computer this gives me about 400 frames per second in 2014b, or 60 frames per second in earlier versions... so this should be fast enough to keep up with the max possible speed of your monitor:
[x,y,z]=sphere(50);
data=[x(:) y(:) z(:)];
figure('renderer','opengl')
axes('xlim',[-1 1],'ylim',[-1 1],'zlim',[-1 1])
L = surface(x,y,z);
view(3)
axis square
n=size(data,1);
tic
for i = 1:1000
npts = randi(n);
idx=false(n,1);
idx(1:npts)=true;
idx=idx(randperm(n));
thisx=x;
thisy=y;
thisz=z;
thisx(idx)=nan;
thisy(idx)=nan;
thisz(idx)=nan;
set(L,'xdata',thisx,'ydata',thisy,'zdata',thisz);
drawnow;
end
t=toc
disp(['Frames per second = ',num2str(1000/t)])
2 个评论
matt dash
2014-12-11
I'm not sure about the 2d vs 3d thing. All matlab axes are 3d, they just appear 2d when you view them from above. So a "2D" plot is identical to a 3D plot with all the z values set to 0. I'm not sure if this really provides any performance benefit.
As far as plotting both halves of the sphere separately, i would just define a plane, and use it in a condition that checks which side of the plane each point of the sphere is. Then have one plot show the points on one side, one plot show the points on the other side. Same idea applies if you had a more complex condition (splitting the sphere into 3 regions etc). I'm still not clear if you want to apply some additional transformation, like a map projection, but in any case I can't help you with that. If you happen to have the mapping toolbox it has many transformations built in.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!