Re: Problems updating Graphics3D Polygons
- To: mathgroup at smc.vnet.net
- Subject: [mg77625] Re: Problems updating Graphics3D Polygons
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Thu, 14 Jun 2007 05:19:42 -0400 (EDT)
- Organization: The Open University, Milton Keynes, UK
- References: <f4ol3r$6uj$1@smc.vnet.net>
chuck009 wrote:
> Hello guys. Can you help me write a function which takes a Graphics3D object and multiplies the z-coordinate of each point of all the polygons by a ratio. This is what I have so far but it's not working:
>
> In[473]:=
> ExpandZ[g_,ratio_]:=
> g/.Polygon[pts_]:>Polygon[{#[[1]],#[[2]],#[[3]]*ratio}& /@pts];
>
> When I test it with this simple Graphics3D object:
>
> 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}}]}];
>
> It doesn't do anything:
>
> g2=Expand[gobject,2]
-----^^^^^^
Should have been *ExpandZ*
> InputForm[g2]
>
> Out[475]=
> â??Graphics3Dâ??
>
> Out[476]//InputForm=
> 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}}]}]
>
> I'll keep working on it. Thanks!
>
Your code is fine. However, you have made a spelling mistake: you do not
want Expand bur *ExpandZ* (that is why it is useful to use a lowercase
letter at the beginning of the name of a user define function :-)
In[1]:= ExpandZ[g_, ratio_] := g /. Polygon[pts_] :>
Polygon[({#1[[1]], #1[[2]], #1[[3]]*ratio} & ) /@ pts];
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}}]}];
g2 = ExpandZ[gobject, 2]
InputForm[g2]
Out[4]//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