How can I project a 3-D sphere onto a 2-D surface?
108 views (last 30 days)
Show older comments
luc on 11 Dec 2014
Commented: luc on 16 Dec 2014
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,
Mohammad Abouali on 11 Dec 2014
Edited: Mohammad Abouali on 11 Dec 2014
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".
More Answers (1)
Edited: matt dash on 11 Dec 2014
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:
data=[x(:) y(:) z(:)];
axes('xlim',[-1 1],'ylim',[-1 1],'zlim',[-1 1])
L = surface(x,y,z);
for i = 1:1000
npts = randi(n);
disp(['Frames per second = ',num2str(1000/t)])
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.
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!