MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: Problems updating Graphics3D Polygons

  • To: mathgroup at smc.vnet.net
  • Subject: [mg77757] Re: [mg77705] Re: Problems updating Graphics3D Polygons
  • From: DrMajorBob <drmajorbob at bigfoot.com>
  • Date: Sat, 16 Jun 2007 03:25:53 -0400 (EDT)
  • References: <12927846.1181901440802.JavaMail.root@m35> <op.tty2tklpqu6oor@monster.ma.dl.cox.net>
  • Reply-to: drmajorbob at bigfoot.com

Here's a version that works for 2D and 3D (and other, if they existed)  
polygons:

Clear[scalePts, scaleGraph]
scale[pts_, m_] := Module[
   {d = Dimensions[pts][[2]]},
   Which[
    ArrayQ[m] && Dimensions[m] == {d, d}, pts.m,
    VectorQ[m] && Length[m] == d, pts.DiagonalMatrix[m],
    NumericQ[m], pts.DiagonalMatrix[ConstantArray[1, d - 1]~Join~{m}],
    True, Print["error"]; pts
    ]
   ]
scaleGraph[graphics_, m_] :=
  graphics /. Polygon[pts_] :> Polygon[scale[pts, m]]

g = 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}}]}];
scaleGraph[g, 1/3]
scaleGraph[g, {1, 2, 1}]
scaleGraph[g, RandomReal[{1/2, 3/2}, {3, 3}]]

g = Graphics[Polygon[{{1, 0}, {0, Sqrt[3]}, {-1, 0}}]];
scaleGraph[g, 1/3]
scaleGraph[g, {2, 3}]
scaleGraph[g, RandomReal[{1/2, 3/2}, {2, 2}]]

Bobby

On Fri, 15 Jun 2007 11:59:34 -0500, DrMajorBob <drmajorbob at bigfoot.com> 
wrote:

> I'm multiplying the polygon list by a 3x3 matrix.
>
> (I posted this before, but just in case...)
>
> array[dims] checks the dimensions of its argument, threeD changes a  
> scalar or 3-vector into a 3x3, and scaleZ multiplies the polygon list by  
> that matrix. The multiplication is pts.matrix; pts is n x 3 and matrix 
> is 3x3, so the result is n x 3 again, still suitable as the argument to  
> Polygon.
>
> (This could be modified to work for 2D plots as well, but I haven't.)
>
> Clear[scale, array, threeD]
> array[dims_List] = ArrayQ[#] && Dimensions[#] == dims &;
> threeD[m_?(array[{3, 3}])] := m
> threeD[m_?(array[{3}])] := DiagonalMatrix@m
> threeD[f_?NumericQ] := DiagonalMatrix@{1, 1, f}
> scale[graphics_, m_] :=
>   graphics /. Polygon[pts_] :> Polygon[pts.threeD[m]]
>
> 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}}]}]
>
> scale[gobject, 1/3]
>
> scale[gobject, {1, 2, 1}]
>
> scale[gobject, RandomReal[{1/2, 3/2}, {3, 3}]]
>
> Bobby
>
> On Fri, 15 Jun 2007 03:35:22 -0500, chuck009 <dmilioto at comcast.com>  
> wrote:
>
>> Thanks.  Jean-Marc noticed in my original post that I just didn't call  
>> the function correctly.  I like the code you used below, the  
>> pts.{{1,0,0},{0,1,0},{0,0,ratio}}.  I see what it does just not sure of  
>> the construct.  I'll figure it out though.  Thanks!
>>
>>> "In[473]:ExpandZ[g_,ratio_]:
>>> g/.Polygon[pts_]:>Polygon[{#[[1]],#[[2]],#[[3]]*ratio}
>>> & /@pts];"
>>>
>>> There are a couple of "=" signs missing; not sure
>>> what you're seeing at
>>> your machine.
>>>
>>> This works at mine:
>>>
>>> Clear[expandZ]
>>> expandZ[g_, ratio_] :=
>>>    g /. Polygon[pts_] :>
>>> Polygon[{#[[1]], #[[2]], #[[3]]*ratio} & /@
>>> & /@ pts];
>>>
>>> But I prefer
>>>
>>> Clear[expandZ]
>>> expandZ[g_, ratio_] :=
>>>    g /. Polygon[pts_] :>
>>> Polygon[pts.{{1, 0, 0}, {0, 1, 0}, {0, 0,
>>> 0, 0, ratio}}];
>>>
>>
>>
>
>
>



-- 
DrMajorBob at bigfoot.com


  • Prev by Date: Re: SingularityDepth option to NIntegrate in Mathematica 6
  • Next by Date: Re: Re: v6: still no multiple undo?
  • Previous by thread: Re: Re: Problems updating Graphics3D Polygons
  • Next by thread: Notebook History -- what is it good for?