Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.
Graphics3D[
  Table[
    GeometricTransformation[
      Cuboid[{1, 0, 0}, {.01, .2, .1}], 
      {RotationMatrix[a, {0, 0, .05}], {.001 Cos[a], .001 Sin[a], a}}], 
    {a, -Pi, 2 Pi, .2}], 
  Boxed -> False]

I followed this Documentation Center page about rotating cuboids along a space curve to make the above code (which creates the stairs for spiral staircase). I don't want to just follow it, though, I would like to understand everything I am typing in. After researching the primitives, I know that Cuboid[{a,b,c},{d,e,f}] creates a cuboid with corner {a, b, c} and opposing corner {d, e, f}.

But other than that, I'm not all sure what else is going on. I can guess at what is going on, but that does not make me feel confident in my Mathematica usage.

Specific questions:

  • What does Table do? When reading about it, I cannot make sense of why I need it in my code.
  • Graphics3D creates a 3D image based upon the primitives and directives entered. Is this correct? What else should I know about this?
  • To make sure I understand primitives and directives clearly: Table is a primitive for Graphics3D. GeometricTransformation is a primitive for Table. Cuboid and RotationMatrix are primitives for GeometricTransformation. Boxed is a directive for Graphics3D. And things like {a, b, c} are parameters for equations or primitives. Is this correct? Sorry, this may read like a riddle.
  • Final questions: What exactly does GeometricTransformation do? Is it basically saying "I'd like to rotate something (a cuboid) about an axis and in the shape of a helix?" Where are the vectors/matrices coming to play in this? This is where I read about it, but it does not help me much in understanding what I am doing.
share|improve this question
1  
You can look up the functions in the docs. For example, Table is a very general command that has nothing to do with graphics. Put the cursor on the command and press F1. –  bill s Feb 9 at 5:11
1  
When you try to understand code, reduce individual parts to as small as possible blocks. E.g., you'll understand Table, when you use it in a very simple form, such as Table[4,{5}], which will produce you a list of five 4 (just test it). So Table will produce a list with a certain number of elements. Then try some more complex stuff, e.g. Table[a+4,{a,1,5}], which will again produce a list with 5 elements, this time {5,6,7,8,9}. I'll guess you already figured out, why. Then take it the next step further, and so on. –  Mockup Dungeon Feb 9 at 7:51
    
Hi Harper! Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! –  belisarius Feb 9 at 12:41
    
It is designed to be more efficient with GeometricTransformation and Table transposed, as in the example in the docs. Look at the 4th (last) synopsis at the top of the doc page: GeometricTransformation[g, {t1, t2,...}]. (In the documentation example, Table makes the list of transformations {t1, t2,...}.) –  Michael E2 Feb 9 at 13:19

2 Answers 2

up vote 1 down vote accepted

Although your code produces a picture of a "spiral staircase", there are some choices of parameters the escape my understanding, so let's look at simplified version with some debugging code added.

Module[{t, g},
  g = Graphics3D[
    t = Table[
      GeometricTransformation[
        Cuboid[{1, 0, 0}, {.01, .2, .1}],
        {RotationMatrix[a, {0, 0, 1}],(* rotation by angle a about z-axis *)
         {0, 0, a} (* translation by a along z-axis *)}],
      {a, -Pi, 2 Pi, .2}],
    Boxed -> False];
 Print[Row[{"Number of cuboids: ", Length@t}]];
 g]
Number of cuboids: 48

staircase.png

The Table expression produces 48 cuboids (the steps), each one slightly different from tho others because of the iteration variable a is stepped from -Pi to 2 Pi by step size 0.2. GeometricTransformation applies two geometric transforms to the cuboid as each table element is generated. These are a rotation about and a translation along the z-axis, which are given in its the second argument.

The number 48 comes from the iteration descriptor, {a, -Pi, 2 Pi, .2}, which calls for Ceiling[(2 Pi - (-Pi))/.2] steps (which evaluates to 48).

Edit

This is to satisfy the OP's request for more information on the role of RotationMatrix.

GeometricTransformation needs to told what transforms to use and its second argument supplies that info. In this case, it is given a list of two transforms, a rotation by angle a about the z-axis and a translation by a along the z-axis. Let RotationMatrix[a, {0, 0, 1}], the first item in the list, be denoted by r. Then r.{x, y, z} gives {x Cos[a] - y Sin[a], y Cos[a] + x Sin[a], z}, the rotation of {x, y, z} by angle a about the z-axis.

share|improve this answer
    
Some of my parameters have to do with the other elements of the staircase that I left out of the question because I understand those functions (adequately, at least). I'm sure my parameters are a bit wacky, even considering the other factors the other functions bring in, but I'm just going for understanding right now. And, thank you very much! You answer has especially helped me understand the Table aspect. Do you know how the RotationMatrix come into play? I would think the GeometricTransformation would suffice for rotating the steps in the helical shape. –  Harper Feb 9 at 6:24
    
I think I get the gist of everything going on here now. Thank you so very much! :) –  Harper Feb 9 at 7:08

If you indent the code, it's easier to see its structure

Graphics3D[
    Table[
        GeometricTransformation[
            Cuboid[{1, 0, 0}, {.01, .2, .1}],
            {RotationMatrix[ a, {0, 0, .05}], {.001 Cos[a], .001 Sin[a], a}}],
    {a, -[Pi], 2 Pi, .2}
    ], Boxed -> False
]

Graphics3D is a container for three-dimensional graphics objects, like Cuboid. Table is used here to produce a list of transformed cuboids depending on parameter a. Consider it an iteration construct that stores each step in a list (that will be passed to Graphics3D to be shown). GeometricTransformation takes a graphics object and produce another graphics object that has been transformed according to the specified transformation rule, here a rototranslation (if I am not mistaken).

I have not run the code, but I believe it will generate a series of pictures of a rolling cuboid. Well, sort of... Er, let's say it's 'spirolling'.

share|improve this answer
    
thanks for both the edit and the response! It was very informative. –  Harper Feb 9 at 5:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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