Re: The size of a 3D plot
- To: mathgroup at smc.vnet.net
- Subject: [mg86735] Re: The size of a 3D plot
- From: Mariano Suárez-Alvarez <mariano.suarezalvarez at gmail.com>
- Date: Thu, 20 Mar 2008 02:50:45 -0500 (EST)
- References: <fripuj$r23$1@smc.vnet.net> <frqps5$57c$1@smc.vnet.net>
On Mar 19, 7:28 am, m... at inbox.ru wrote: > On Mar 16, 3:40 am, Mariano Su=E1rez-Alvarez > > <mariano.suarezalva... at gmail.com> wrote: > > Hi all, > > > is there a way to have a 3D graphic be sized so that it fits tightly > > in its bounding box? I seem to only be able to have it sized so that > > the *box* circumscribing it fits in the bounding box, as in > > > Graphics[{Sphere[]}] > > > -- m > > Here's some code that may do what you need, assuming you have a 3D > graphic with white background: > > DynamicModule[ > {update, gr, gr2, k = 4, > w = 360, h = 360, xmarg = 0, ymarg = 0, xd = 0, yd = 0, > vp = {1.3, -2.4, 2.}, va = Automatic, vv = {0, 0, 1}}, > update[] := > (gr = Rasterize[ > Graphics3D[Cylinder[], Boxed -> False, ImageSize -> w, > ViewAngle -> va, ViewPoint -> vp, ViewVertical -> vv], > "Data", ImageResolution -> 72/k]; > {w, h} = k Dimensions[gr][[{2, 1}]]; > gr2 = Split[gr, Min[##] == 255 &]; > {ymarg, yd} = > k {# + #2 - 2, (#2 - #)/2} & @@ Length /@ gr2[[{1, -1}]]; > gr2 = Split[Transpose@gr, Min[##] == 255 &]; > {xmarg, xd} = > k {# + #2 - 2, (#2 - #)/2} & @@ Length /@ gr2[[{-1, 1}]] > ); > update[]; > EventHandler[ > Graphics[Inset[ > Graphics3D[Cylinder[], Boxed -> False, ImageSize -> w, > RotationAction -> "Clip", > ViewAngle -> Dynamic[va], > ViewPoint -> Dynamic[vp], > ViewVertical -> Dynamic[vv]], > {0, 0}, > Dynamic@Offset[{xd, yd}, ImageScaled at {.5, .5}], > Dynamic@Offset@{w, h}, > ContentSelectable -> True], > ImageSize -> Dynamic[{w - xmarg, h - ymarg}, > (w = #[[1]] + xmarg; update[]) &], > ContentSelectable -> True] // > Framed[#, FrameMargins -> 0] &, > {"MouseUp" :> update[]}] > ] > > Maxim Rytin > m... at inbox.ru Ah. Very smart ;-) I really can't believe it is that hard and manual to remove the huge margins in Graphics3D[{Sphere[]}, Boxed->False] They take up a good 60 percent of the area! -- m