I'm using Mathematica 8 and I am struggling with texturing. Although texturing of polyhedral objects has proved to be relatively simple, I hit a problem trying to texture a sphere. In the documentation, the only way to texture a sphere shown is using SphericalPlot3D
, which, IMHO, is a kludgey solution, especially since I'm trying to perform operations (e.g.: translation) on the sphere. In toto, my question is: is there any way to texture a sphere primitive?
Asked
Active
Viewed 2,161 times
11

Brett Champion
- 8,497
- 1
- 27
- 44

taktoa
- 534
- 2
- 15
-
Related: [RegionPlot on the surface of the unit sphere?](http://stackoverflow.com/q/5788842/616736) and [How do you get custom 3D graphics to display properly in Mathematica?](http://stackoverflow.com/q/5603281/616736) – abcd Jan 02 '12 at 04:23
3 Answers
12
You can't texture a Sphere
directly, but you could create a textured sphere using e.g. SphericalPlot3D
and extract the first part to get a primitive which you can manipulate with Translate
. For example
sphere = SphericalPlot3D[1, th, phi, Mesh -> False, PlotPoints -> 25,
PlotStyle -> {Opacity[1], Texture[ExampleData[{"ColorTexture", "GiraffeFur"}]]},
TextureCoordinateFunction -> ({#4, #5} &)][[1]];
Graphics3D[Translate[sphere, {{0, 0, 0}, {2, 2, 2}}]]

Heike
- 24,102
- 2
- 31
- 45
6
Something like this will be helpful :
sphere = SphericalPlot3D[1, {u, 0, Pi}, {v, 0, 2 Pi},
TextureCoordinateFunction -> ({2 #5, 1 - 2 #4} &),
PlotStyle -> { Lighting -> "Neutral", Axes -> False,
Boxed -> False, Texture[texture]}, Mesh -> None][[1]];
F[k_] := Graphics3D[ Rotate[ sphere, k, {2, 1, 6}, {0, 0, 0}], Boxed -> False]
Now, we can animate a textured sphere rotating (around the vector {2, 1, 6}
anchored at the point {0,0,0}
) :
Animate[F[k], {k, 0, 2 Pi}]

Artes
- 1,133
- 1
- 17
- 24
-
1No, that's what I managed to do... I want to texture a Sphere *primitive*, as produced by the Sphere[] function. – taktoa Jan 01 '12 at 22:12
-
4
3
Just for completeness, you can also generate spheres with textures using ParametricPlot3D
.
map = ExampleData[{"TestImage", "Lena"}];
sphere = ParametricPlot3D[{Cos[u] Sin[v], Sin[u] Sin[v], Cos[v]}, {u,
0, 2 Pi}, {v, 0, Pi}, Mesh -> None,
TextureCoordinateFunction -> ({#4, 1 - #5} &),
Lighting -> "Neutral", Axes -> False, Boxed -> False,
PlotStyle -> Texture[Show[map]]]
If I understand correctly, Heike's answer shows that the first part of the result is a GraphicsComplex, which is a graphics primitive.

cormullion
- 1,672
- 1
- 10
- 24