Figure with image mapped to spherical background

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

DGM
DGM on 21 May 2021
Edited: DGM on 21 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.
@DGM Thanks for having a look, I would like to be able to move the view around inside the sphere for verification that what I plot inside the sphere looks right, but your idea might still be useful. My main goal though is to make a video of the simulation I will be plotting so that's why I want the background image to fill up the area of the figure, but cropping a rectangular area of the circle might be the only option.
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?
This demo in the documentation is generally how the project would look if you plot your own space background.
Thank you guys for your help, I just realised that in the image I shared the camera view angle is 170 degrees and thats why it looks weird. Adam I will review that documentation, it looks like it will be helpful as well! The image I am using is from here: https://www.eso.org/public/images/eso0932a/ and I have used it as a texture map for a sphere to be a spherical background.

Sign in to comment.

Answers (2)

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...
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

Products

Release

R2018b

Asked:

on 12 May 2021

Answered:

on 10 Sep 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!