       Re: best way to save 3D plot as .eps for latex document?

• To: mathgroup at smc.vnet.net
• Subject: [mg101884] Re: [mg101867] best way to save 3D plot as .eps for latex document?
• From: Mark McClure <mcmcclur at unca.edu>
• Date: Mon, 20 Jul 2009 19:21:09 -0400 (EDT)
• References: <200907201001.GAA28365@smc.vnet.net>

```On Mon, Jul 20, 2009 at 6:01 AM, summer <summertan at hotmail.com> wrote:

> I have to put a 3D Mathematica plot in a latex document so I save the plot
> by right clicking it and saving as .eps. ...
>
> Is there a way to efficiently save the plot as .eps so that
> 1. the file is small
> 2. quality is still acceptable
> 3. recompiling the latex is fast

Of course, the answer will depend, in part, on the specific graphics you
are rendering.  Here's a specific example, for context.

p[r_, t_] := {r*Cos[t], r*Sin[t], Sin[-r^2]};
pic = ParametricPlot3D[p[r, t], {r, 0, Pi/2}, {t, 0, 2 Pi}]

If pic is then exported to EPS, the file size is nearly 4MB.  I suppose
the file size is so large since the adaptive plotting procedures produce
a large number of points.  I suppose the mesh doesn't look so good after
export to PDF since the mesh lines are generated independently of the
polygons.

An easy fix is to turn off the adaptive plotting procedures by setting
MaxRecusion->0 and to force the mesh lines to be right at the polygonal
edges by specifying Mesh->All.

p[r_, t_] := {r*Cos[t], r*Sin[t], Sin[-r^2]};
pic = ParametricPlot3D[p[r, t], {r, 0, Pi/2}, {t, 0, 2 Pi},
Mesh -> All, MaxRecursion -> 0, PlotPoints -> {15, 40}]

The resulting EPS file is only 800K and the line quality is much better.
Unfortunately, the polygons are all triangulated so the Mesh might not
be what you want.

If you're willing to do a little graphics programming, you can get a
quite satisfying result.  The key point is to generate a collection of
rectangular patches for your surface and to collect them into a
GraphicsComplex with SurfaceNormals specified.

p[r_, t_] := {r*Cos[t], r*Sin[t], Sin[-r^2]};
dr = Pi/30; dt = Pi/20;
polygons =
Table[Polygon[{p[r, t], p[r + dr, t], p[r + dr, t + dt], p[r, t + dt]}],
{r, 0, Pi/2 - dr, dr}, {t, 0, 2 Pi - dt, dt}];
points = Union[Flatten[polygons /. Polygon[{pp__}] -> pp, 1]];
multigon = Polygon[Flatten[polygons /.
Polygon[{pp__}] :> Flatten[Position[points, #] & /@ {pp}], 1]];
n[r_, t_] = Cross[D[p[r, t], r], D[p[r, t], t]];
vns = Join[{{{0, 0, 0}, {0, 0, 1}}},
Flatten[Table[{p[r, t], n[r, t]}, {r, dr, Pi/2, dr},
{t, 0, 2 Pi - dt, dt}], 1]];
vns = Last /@ SortBy[vns, First];
pic = Graphics3D[GraphicsComplex[points, multigon,
VertexNormals -> vns]]

It's clearly a bit more work, but this version is reasonably sized
at 800K and looks pretty nice after export.

Mark McClure

```

• Prev by Date: Re: Linking Manipulate to arrow keys?
• Next by Date: Re: Integral Fails to Converge
• Previous by thread: best way to save 3D plot as .eps for latex document?
• Next by thread: Re: best way to save 3D plot as .eps for latex document?