How can I create a plot like this using MATLAB?
1 view (last 30 days)
Show older comments
Hey there!
I'm trying to create a plot like the one shown below:
I am particularly concerned about how to do two things:
- How can I make the sphere to be shaded with a colormap depending on the incident angle of the light?
- (Less important) How can I tilt the sphere, like the tilt the planet has?
Thank you in advance!
0 Comments
Accepted Answer
Star Strider
on 27 Jan 2016
Rotating the colormap is difficult, and I haven’t solved that. Plotting, rotating, and lighting the sphere is relatively straightforward:
[Xs,Ys,Zs] = sphere(50);
Axis = [[0;0], [0;0], [-1;1]];
figure(1)
hs = surf(Xs, Ys, Zs);
hold on
ls = plot3(Axis(:,1), Axis(:,2), 2*Axis(:,3));
hold off
rotate(hs, [-2, 1, 0], 23.5)
rotate(ls, [-2, 1, 0], 23.5)
axis equal
shading interp
camlight(60,-10)
colormap(jet(50))
3 Comments
Star Strider
on 27 Jan 2016
Edited: Star Strider
on 27 Jan 2016
Our pleasure!
Mike, thank you for your contribution. That would make a good blog post. (Hint!)
Andres, when you’re satisfied that your code does what you want and is reasonably robust, consider documenting it and posting it on the File Exchange. I’m certain others will find it useful. It’s also easier to search the File Exchange than it is to search Answers.
More Answers (0)
See Also
Categories
Find more on Graphics Objects in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!