Figure with image mapped to spherical background
Show older comments
Hi, I am trying to make a 3-D plot which has a spherical background image. I have tried making a larger sphere that an image is mapped to, and then placing the other data to be plotted inside this sphere, and placing the camera inside the sphere. However when I do this the the figure displays as a circle, rather than the background image filling up the whole square area of the figure.
I have:

and my code is:
axis([-10 10 -10 10 -10 10])
[x,y,z]=sphere(50);
spherescale=10;
hold on
U_im=imread('esoMilkyway.jpg'); % Import texture data for Universe
Bg=surf((x*spherescale),(y*spherescale), (z*spherescale));
set(Bg,'facecolor','texturemap','cdata',U_im,'edgecolor','none');
daspect([1 1 1]);
campos([1 0 0]);
axis off
The effect that I am trying to reproduce can be seen at 20:45 in this video: https://uk.mathworks.com/videos/modeling-and-simulation-with-matlab-a-case-study-in-problem-based-learning-90422.html I'm sure I am just missing a simple solution but I have done lots of research on google and I can't find any examples of what I am trying to do.
Also, when I rotate the figure the camera moves itself out of the sphere which is also something I would like to stop happening. If anyone can help me out that would be greatly appreciated. Thanks!
7 Comments
Daire Vickers
on 13 May 2021
For what it's worth, I messed around with this for about an hour and got nothing but frustrated. I tried messing around with camva() and position, and got some maybe helpful results, but the bottom line was that the moment anything is moved, campos reverts. I imagine there's a way around that, but it's not obvious to me. If nothing else,it may be possible to just write a function that's called whenever the figure is updated, and use that to re-scale the campos radius.
Daire Vickers
on 21 May 2021
Adam Danz
on 21 May 2021
In the video you shared the camera angle changes which means the background would need to counter-rotate. The range of rotation of the camera needs to equal the viewing angle of the image. In other words, if the camera in your animation has 360deg rotation then your image needs to be a 360deg image rather than the 10-20deg (???) image you shared as an example. Do you really need the fancy image background? Can you just use randomly plotted white pixels as a star background?
Adam Danz
on 21 May 2021
This demo in the documentation is generally how the project would look if you plot your own space background.
Daire Vickers
on 21 May 2021
Edited: Daire Vickers
on 21 May 2021
Adam Danz
on 31 May 2021
This might be helpful to look through
Answers (2)
Tiago Padovan
on 10 Sep 2021
0 votes
Any update in this matter? I just started facing the same issue.

I have an animation where the camera rotates around the ISS (which I obtained from an STL file).
When I try adding an oversized sphere with the image of the night sky covering it and plot the other elemrnts inside it, it does not work. The image of the stars appears and it actually rotates as expected from a backgorund (oposite to the objects' rotation), but the objects insite are not visible...
Image Analyst
on 10 Sep 2021
0 votes
See the examples in the documentation for pcshow() in the Computer Vision Toolbox.
Categories
Find more on Graphics Object Properties 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!