Re: Problems updating Graphics3D Polygons

• To: mathgroup at smc.vnet.net
• Subject: [mg77684] Re: Problems updating Graphics3D Polygons
• From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
• Date: Fri, 15 Jun 2007 04:24:31 -0400 (EDT)
• Organization: The Open University, Milton Keynes, UK
• References: <f4r3ap\$92h\$1@smc.vnet.net>

chuck009 wrote:
> Hey guys.  I did make progress with this by coding:
>
> UpdatePoints[factor_][p_] := Block[{x, y, z},
>       {x, y, z} = p;
>       z *= factor;
>       Return[{x, y, z}];
>       ];
>
> ScaleZ[graphics_, factor_] := Module[{g2}, g2 = graphics /.Polygon[pts_] :> Polygon[UpdatePoints[factor] /@ pts];
>       Return[g2];
>       ];
>
> Perhaps though someone can suggest a more elegant "one-liner"
>

*Return* is useless here.

In[1]:= gobject = Graphics3D[{Polygon[{{0., 0.5, 1.28}, {0., 0., 1.},
{0.5, 0., 1.28}, {0.5, 0.5, 1.64}}],
Polygon[{{0.5, 0.5, 1.64}, {0.5, 0., 1.28}, {1., 0., 2.71},
{1., 0.5, 3.49}}]}];
UpdatePoints[factor_][p_] := Block[{x, y, z},
{x, y, z} = p; z *= factor; {x, y, z}]
ScaleZ[graphics_, factor_] := Module[{g2},
g2 = graphics /. Polygon[pts_] :> Polygon[UpdatePoints[factor] /@
pts]; g2]
g2 = ScaleZ[gobject, 2]
InputForm[g2]

Out[5]//InputForm=
Graphics3D[{Polygon[{{0., 0.5, 2.56}, {0., 0., 2.}, {0.5, 0., 2.56},
{0.5, 0.5, 3.28}}], Polygon[{{0.5, 0.5, 3.28}, {0.5, 0., 2.56},
{1., 0., 5.42}, {1., 0.5, 6.98}}]}]

What do you like in your original function *ExpandZ* ?

In[6]:= ExpandZ[g_, ratio_] := g /. Polygon[pts_] :>
Polygon[({#1[[1]], #1[[2]], #1[[3]]*ratio} & ) /@ pts]
g2 = ExpandZ[gobject, 2]
InputForm[g2]

Out[8]//InputForm=
Graphics3D[{Polygon[{{0., 0.5, 2.56}, {0., 0., 2.}, {0.5, 0., 2.56},
{0.5, 0.5, 3.28}}], Polygon[{{0.5, 0.5, 3.28}, {0.5, 0., 2.56},
{1., 0., 5.42}, {1., 0.5, 6.98}}]}]

Regards,
Jean-Marc

• Prev by Date: Re: v6: still no multiple undo?
• Next by Date: Re: NDSolve, Loop, Table, Plot
• Previous by thread: Re: Re: Problems updating Graphics3D Polygons
• Next by thread: Re: Re: Problems updating Graphics3D Polygons