RE: scaling/translating Polyhedra - is this how??
- To: mathgroup at smc.vnet.net
- Subject: [mg38634] RE: [mg38588] scaling/translating Polyhedra - is this how??
- From: "David Park" <djmp at earthlink.net>
- Date: Wed, 1 Jan 2003 03:40:37 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Relishguy, You are certainly on to the correct idea. It is very useful to be able to manipulate the graphic primitives. Another method is to use a rule on the primitive graphics... {x_?NumberQ, y_?NumberQ, z_?NumberQ} -> {fx[x,y,z], fy[x,y,z], fz[x,y,z]} Here are some other tricks. You can use the following packages... Needs["Graphics`Polyhedra`"] Needs["Graphics`Shapes`"] The Shapes package has routines AffineShape, TranslateShape, RotateShape and Wireframe. The Polyhedron function from the Polyhedra package also allows scaling and shifting of the polyhedra. In the following plot I show 1) the original Tetrahedron. 2) the Tetrahedron scaled and shifted and rendered as a wireframe. 3) a Cube that is stretched, rotated and translated. 4) a helix that has been defined parametrically. helix[r_, t_] := {r Cos[t], r Sin[t], t/4} + {2, 0, 0} Show[ Polyhedron[Tetrahedron], Polyhedron[Tetrahedron, {0, 0, 0.5}, 1.2] // WireFrame, Graphics3D[Cube[]] // AffineShape[#, {0.5, 1, 1.5}] & // RotateShape[#, Pi/4, 0, 0] & // TranslateShape[#, {2, 3, 4}] &, ParametricPlot3D[helix[1, t] // Evaluate, {t, 0, 24}, DisplayFunction -> Identity], Axes -> True]; I consider this construction a little unintuitive. The Polyhedron command appears to be similar to the Graphics3D command but with a different usage. Suppose you want to add a surface color to the first polyhedron and the cube, do the wireframe in blue, and the helix in red. It is a little difficult to slip in all these directives. The DrawGraphics package from my web site is a little more natural. The above plot would be done as... Needs["DrawGraphics`DrawingMaster`"] Needs["Graphics`Polyhedra`"] helix[r_, t_] := {r Cos[t], r Sin[t], t/4} + {2, 0, 0} Draw3DItems[ {Tetrahedron[], Tetrahedron[] // UseAffineShape[{1.2, 1.2, 1.2}] // UseTranslateShape[{0, 0, 0.5}] // UseWireFrame, Cube[] // UseAffineShape[{0.5, 1, 1.5}] // UseRotateShape[Pi/4, 0, 0] // UseTranslateShape[{2, 3, 4}], ParametricDraw3D[helix[1, t] // Evaluate, {t, 0, 24}]}, Background -> Linen, ImageSize -> 450]; Now we can easily add graphics directives since everything is on the graphic primitives and directives level. Draw3DItems[ {SurfaceColor[CadetBlue], Tetrahedron[], Blue, Tetrahedron[] // UseAffineShape[{1.2, 1.2, 1.2}] // UseTranslateShape[{0, 0, 0.5}] // UseWireFrame, SurfaceColor[CadmiumYellow], Cube[] // UseAffineShape[{0.5, 1, 1.5}] // UseRotateShape[Pi/4, 0, 0] // UseTranslateShape[{2, 3, 4}], VenetianRed, ParametricDraw3D[helix[1, t] // Evaluate, {t, 0, 24}]}, NeutralLighting[0.3, 0.5, 0.3], Background -> Linen, ImageSize -> 450]; The NeutralLighting command inserts lighting options that control the saturation, brightness of the lights and the ambient lighting. With less saturated lighting than the standard, pastel surface colors display better. You can also rotate the lights about the vertical axis. David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ From: Relishguy [mailto:relishguy at pluggedin.org] To: mathgroup at smc.vnet.net I wanted to just display a tetrahedron scaled smaller and translated along the z-axis like the example on p.517 of the S.Wolfram book (V.4). After I figured out that the example used a cuboid and the constructor for the tetrahedron would not work the same way, I devised a way to accomplish this. However, I have seen so many exercises that can be accomplished more easily when I gain more knowledge. I figured out that the tetrahedron is just a list of polygons, which are just a list of triples. So, here goes: <<Graphics`Polyhedra` t0=Tetrahedron[] f0=Function[x,0.2*x] (* make it 20% as big *) t1=Map[f0,t0,{4}] (* go down to level 4 *) f1=Function[x,{x[[1]], x[[2]], x[[3]]+0.1}] (* move it up by 0.1 *) t2=Map[f1, f2, {3}] (*this time it should work on the points *) Show[Graphics3D[{t2}]] Is there some easier way to translate/scale a polyhedron (or polygon)? Thanks in advance. Regards.. Note: Of course, I am happy that this can be accomplished at all, using these weird "map"ings! :-))