2
$\begingroup$

I am plotting a simple function:

Plot3D[-RandomReal[{0, 10}] Cos[x/3] Cos[y/3], 
  {x, -π, π}, {y, -π, π}, 
  Axes -> False, 
  Boxed -> False, 
  BoundaryStyle -> None, 
  Mesh -> None]

which Mathematica renders perfectly and which can be viewed, rotated, zoomed and so forth as I wish:

within mathematica

However, when I export via Export["test.obj", %] or also Export["test.wrl", %], I get something completely different/distorted:

wrl export

My thought it could have something to do with clipping, mesh or boundaries, but I've tried playing with a number of different options to no avail. Am I doing something wrong or overlooking something?

$\endgroup$
  • $\begingroup$ Don't you need to state the format? Export["test.obj", %, "PDF"] for instance? $\endgroup$ – David G. Stork Feb 22 '17 at 22:38
  • $\begingroup$ @DavidG.Stork no, I believe the format is inferred automatically by the name: http://reference.wolfram.com/language/howto/… $\endgroup$ – waffl Feb 22 '17 at 22:39
  • $\begingroup$ It may be just an aspect ratio issue. Try rendering your plot with BoxRatios->{1,1,1} $\endgroup$ – george2079 Feb 22 '17 at 22:43
  • $\begingroup$ BoxRatios and ViewPoint don't help... $\endgroup$ – David G. Stork Feb 22 '17 at 22:45
  • $\begingroup$ It could also be an issue with whatever renderer you are using. Have you tried importing back to mathematica? $\endgroup$ – george2079 Feb 22 '17 at 22:55
1
$\begingroup$

The exported files are correct and Plot3D is also correct. How? It all comes down to the BoxRatios option setting.

BoxRatios default setting has been chosen to make most plots look "nice". The effect is that the x-, y-, and z-axis are not to scale. You can see this if you allow the axes to be plotted.

Plot3D[-RandomReal[{0, 10}] Cos[x/3] Cos[y/3], {x, -π, π}, {y, -π, π},
 Boxed -> False,
 BoundaryStyle -> None,
 Mesh -> None]

Mathematica graphics

Notice that the z-axis is 10 units long but is presented as being shorter than the x-axis and y-axis which are only 6 units long.

We can view the plot with axis scaled proportionately by using the Automatic setting for the BoxRatios option.

Plot3D[-RandomReal[{0, 10}] Cos[x/3] Cos[y/3], {x, -π, π}, {y, -π, π},
 Boxed -> False,
 BoundaryStyle -> None,
 Mesh -> None,
 BoxRatios -> Automatic]

Mathematica graphics

Notice that the length of each axis is now proportional to its number of units.

This plot matches the files exported because Mathematica exports the coordinates and the packages used to view the files do not rescale any of the axis.

Hope this helps.

$\endgroup$
0
$\begingroup$

Mathematica has Export for 3D I'm unsure how well it exports to 3DStudio (in past versions, poorly).

The (see URLs) can Export to Renderer format (rayshade or povray) and does preserve things (the whole scene hopfully including text and tick marks - though that is little tested it has examples of 2D plots doing it well) - when they are supported (many things are, many not, Mathematica 11.0 is simply too huge to comment on).

see How to Render, raytrace, Export Graphics3D in Mathematica 11.0 How to Render, raytrace, Export Graphics3D in Mathematica 11.0

and

https://sourceforge.net/projects/rayshade-math/

Both rayshade and povray can be used to Rotate (manipulate) the resulting output realtime without Mathematica.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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