Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sphere is one of the three-dimensional graphics primitives available in Mathematica and can be easily used to created very useful images. For instance, in the figure below I created three images of an ellipsoidal object that is lit from a fixed direction and it is then just rotated around the z-axis.

GraphicsRow[
    Table[
        Graphics3D[
        Rotate[Scale[{GrayLevel[.7], Sphere[]}, {1, 1.5, 1}, {0, 0, 0}], 
        i Degree, {0, 0, 1}], PlotRange -> {{-2, 2}, {-2, 2}, {-2, 2}}, 
        AspectRatio -> 1, Background -> Black, Boxed -> False, 
        ViewPoint -> Front, SphericalRegion -> True, 
        Lighting -> {{"Directional", White, ImageScaled[{0, 0, 1}]}}
    ], {i, {0, 45, 90}}]]

ellipsoidalObject

Suppose that instead of using the ellipsoidal object I would like to use an object like this bump:

Plot3D[Exp[-(x^2 + y^2)], {x, -2, 2}, {y, -2, 2}]

bump

Is there a way to create a "graphics primitive" object of the bump, so as to just use it instead of Sphere in the above example?

I suppose there should be a way to extract all the polygons specifying the shape of the bump, but I couldn't find a way to do it. Any other approach is also more than welcome.

share|improve this question

2 Answers 2

up vote 19 down vote accepted

The result of Plot3D and related functions is something of the form Graphics3D[primitives, options], so to extract the graphics primitives you can simply take the first part of the plot. These can then be manipulated similar to Sphere[] in your example, e.g.

plot = Plot3D[Exp[-(x^2 + y^2)], {x, -2, 2}, {y, -2, 2}][[1]];

GraphicsRow[
 Table[Graphics3D[
   Rotate[Scale[{GrayLevel[.7], plot}, {1, 1.5, 1}, {0, 0, 0}], 
    i Degree, {0, 0, 1}], PlotRange -> {{-2, 2}, {-2, 2}, {-2, 2}}, 
   AspectRatio -> 1, Background -> Black, Boxed -> False, 
   ViewPoint -> Front, SphericalRegion -> True, 
   Lighting -> {{"Directional", White, 
      ImageScaled[{0, 0, 1}]}}], {i, {0, 45, 90}}]]

Mathematica graphics

share|improve this answer
1  
Nice use of [[1]] to extract the GraphicsComplex from the plot! –  tkott Mar 19 '12 at 14:22
1  
Or slightly more transparently: Cases[(* stuff *), _GraphicsComplex, Infinity] // First. –  J. M. Mar 19 '12 at 15:21
1  
Or if you are baffled by GraphicsComplex, try Cases[Normal[plot], _Polygon, Infinity] which will return the (many many) constituting polygons. –  Yves Klett Mar 19 '12 at 16:34

I think what you're looking for is BSplineSurface. For your given example, try:

cpts = Table[{x, y, Exp[-(x^2 + y^2)]}, {x, -2, 2, 0.1}, {y, -2, 2, 
    0.1}];

Graphics3D[BSplineSurface[cpts], Boxed -> False]

Which gives:

Mathematica graphics

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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