4
$\begingroup$

I'm high school student, and I am doing research about buildings using Mathematica. I want to plot the polyhedron shown below:

the desired polyhedron

I have tried using Table, but it doesn't work. Please help me.

v = Table[
   {
    {-2, -2, h}
    , {-2, 2, h}
    , {2, 2, h}
    , {2, -2, h}
    , {-3, -3, h + 3}
    , {-3, 3, h + 3}
    , {3, 3, h + 3}
    , {3, -3, h + 3}
    }
   , {h, 0, 1, 3}
   ];
i = {
   {1, 2, 3, 4}
   , {1, 2, 6, 5}
   , {2, 3, 7, 6}
   , {3, 4, 8, 7}
   , {4, 1, 5, 8}
   , {5, 6, 7, 8}
   };

Graphics3D[GraphicsComplex[v, Polygon[i]], Axes -> True]
$\endgroup$
  • 1
    $\begingroup$ Welcome to Mathematica.SE. Could you be more specific in your question? . Only good questions are likely to get great answers. Please edit your question to improve it and make more clear what you are asking. Also consider taking the tour. $\endgroup$ – rhermans Aug 21 '15 at 14:57
  • 3
    $\begingroup$ Aren't you doing exactly that? $\endgroup$ – Dr. belisarius Aug 21 '15 at 15:04
  • $\begingroup$ Can you clarify what you need, because you are using a Table, do you just want help to simplifiy your code? $\endgroup$ – M.R. Aug 21 '15 at 15:51
  • $\begingroup$ sorry. I want to regulate height using table $\endgroup$ – 유민우 Aug 22 '15 at 1:05
  • $\begingroup$ In case this was contributing to your confusion, please note that the iteration specifier {h, 0, 1, 3} makes h run from 0 to 1 in steps of 3. So in fact h only ever takes the value 0. To run from 0 to 3 in steps of 1, use {h, 0, 3, 1} or just {h, 0, 3}. (The final value and step are given in the opposite order compared to, e.g., Matlab.) $\endgroup$ – Stephen Powell Aug 23 '15 at 10:00
8
$\begingroup$

I am glad that you are using Mathematica in your high school project.

I think you forgot to mention in your question that the code you posted doesn't actually produce the image you showed; you may also want to mention where you obtained that image.

Anyway, since your figure is made up of repeating units, I generated one unit, then translated it multiple times to generate the rest of the figure. You could use the following code as an inspiration to tweak to your desires:

Graphics3D[
  Table[
    GeometricTransformation[
      Pyramid[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, -2}}],
      TranslationTransform[{0, 0, n}]
    ],
    {n, 0, 5, 1}
  ],
  Axes -> True
]

pyramids


UPDATE

As @GuessWhoItIs mentioned in his comment, this is a pretty versatile approach. You can swap out different 3D repeating units, and the rest of the code will do the stacking for you.

In fact, a more faithful representation of what you showed in the picture can be obtained using a pyramidal frustum (e.g. a pyramid with the tip chopped off) as the repeating unit:

repeatingUnit = Hexahedron[{
    (*bottom face*)
    {-2, -2, 0}, {2, -2, 0}, {2, 2, 0}, {-2, 2, 0},
    (*top face*)
    {-3, -3, 3}, {3, -3, 3}, {3, 3, 3}, {-3, 3, 3}
    }];

Graphics3D[
  Table[
    GeometricTransformation[
      repeatingUnit,
      TranslationTransform[{0, 0, n}]
    ],
    {n, 0, 15, 3}
  ],
  Axes -> True
]

frusta

You can explore further by considering e.g. less regular pyramids, pyramids with non-horizontal bases, etc.

$\endgroup$
  • $\begingroup$ Hopefully, OP realizes that the Pyramid[] in your code is replaceable, if, say, he wants frustums instead. $\endgroup$ – J. M. will be back soon Aug 21 '15 at 16:58
  • $\begingroup$ @Guess Good point. I updated the code to include that, in specific to separate the construction of an explicit repeating unit from the generation of the 3D graphic itself. $\endgroup$ – MarcoB Aug 21 '15 at 17:19
  • $\begingroup$ +1 for the effort put into interpreting a weird question $\endgroup$ – Dr. belisarius Aug 21 '15 at 17:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.