6
$\begingroup$

I want to paste an image on the surface of a 3D plot. For example consider this image which I want to paste on the surface of this sphere

ContourPlot3D[x^2 + y^2 + z^2 == 1, {x, -1, 1}, {y, -1, 1}, {z, -1, 1}, Mesh -> 1]

What will be the best way to do that?

EDIT and Clarification

My main objective is not to make a globe but to find a general way to use any arbitrary image on a surface. I choose the map and sphere just as an example (a popular one). Texture is a good option, but I find some difficulty to use it with ContourPlot3D or Plot3D. To make my point clear, I would request to show me an example with this image and the following surface,

Plot3D[Abs[x y], {x, -1, 1}, {y, -1, 1}]
$\endgroup$
4
  • $\begingroup$ This should probably do it. $\endgroup$ Commented Jun 23, 2013 at 21:17
  • 1
    $\begingroup$ Look up Texture in Mathematica's document center. There are several examples that do precisely this. $\endgroup$ Commented Jun 23, 2013 at 21:27
  • $\begingroup$ Related: mathematica.stackexchange.com/a/3632/57 $\endgroup$ Commented Jun 23, 2013 at 21:29
  • 2
    $\begingroup$ Come on, just do exactly the same thing: Plot3D[Abs[x y], {x, -1, 1}, {y, -1, 1}, PlotStyle -> Texture[Import["https://i.sstatic.net/XVgk0.jpg"]], Lighting -> "Neutral"] $\endgroup$
    – user484
    Commented Jun 23, 2013 at 22:52

2 Answers 2

9
$\begingroup$

This question is very similar to How to make a 3D globe. There is some difference, as that question dealt with building a globe from scratch, whereas this question has a predefined image. There is a little difference in that you'll need to manually trim the boundary of your image. Here's how did it:

pic = Import["https://i.sstatic.net/5JpK4.jpg"];
{width, height} = ImageDimensions[pic];
w = 40; h = 45;
pic = ImageTake[pic, {h, height - h}, {w, width - w}];
ParametricPlot3D[{Cos[u] Sin[v], Sin[u] Sin[v], Cos[v]} ,
  {u, 0, 2 Pi}, {v, 0, Pi}, Mesh -> None, PlotPoints -> 100,
  TextureCoordinateFunction -> ({#4, 1 - #5} &), Boxed -> False,
  PlotStyle -> Texture[Show[pic, ImageSize -> 1000]],
  Lighting -> "Neutral", Axes -> False, RotationAction -> "Clip",
  ViewPoint -> {-2.026774, 2.07922, 1.73753418},
  ImageSize -> 600]

enter image description here

$\endgroup$
1
  • $\begingroup$ @smtg using Mark McClure's answer to fulfill your requirements in the Edit/Clarification: Plot3D[Abs[x y], {x, -1, 1}, {y, -1, 1}, TextureCoordinateFunction -> ({#1, 1 - #2} &), PlotStyle -> Texture[Show[pic, ImageSize -> 1000]], Lighting -> "Neutral", Mesh -> False] The only difference is in the TextureCoordinateFunction. $\endgroup$ Commented Jun 24, 2013 at 12:53
8
$\begingroup$

You could use ContourPlot3D, but I'd use SphericalPlot3D instead. That's because you're plotting a spere anyways and SphericalPlot3D seems to be the better functionality on that matter.

I leave the rest of the options such as in your example for ContourPlot3D.

SphericalPlot3D[1, {u, 0, Pi}, {v, 0, 2 Pi}, PlotPoints -> 50, 
    MaxRecursion -> 0, Mesh -> True, 
    TextureCoordinateFunction -> ({#5, 1 - #4} &), 
    PlotStyle -> 
        Directive[Texture[Import["https://i.sstatic.net/5JpK4.jpg"]], 
        Specularity[White, 50]], Lighting -> "Neutral"]

Personally I'd remove any mesh, axis and boxes, but this is just a matter of taste.

enter image description here

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.