21
$\begingroup$

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.

$\endgroup$

2 Answers 2

24
$\begingroup$

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

$\endgroup$
3
  • 1
    $\begingroup$ Nice use of [[1]] to extract the GraphicsComplex from the plot! $\endgroup$
    – tkott
    Commented Mar 19, 2012 at 14:22
  • 1
    $\begingroup$ Or slightly more transparently: Cases[(* stuff *), _GraphicsComplex, Infinity] // First. $\endgroup$ Commented Mar 19, 2012 at 15:21
  • 1
    $\begingroup$ Or if you are baffled by GraphicsComplex, try Cases[Normal[plot], _Polygon, Infinity] which will return the (many many) constituting polygons. $\endgroup$
    – Yves Klett
    Commented Mar 19, 2012 at 16:34
15
$\begingroup$

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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