12
$\begingroup$

I'm struggling to understand what would be a good way to compose several geometrical transformations to create a single TransformationFunction to be applied to a GeometricTransformation. One way could be to obtain a set of TransformationMatrix and multiply.

On this answer what I would have liked to achieve is to perform two rotations in different axis and then a translation in order to create a realistic trajectory of a falling cube, knowing height vs time and also the angles of elevation and azimuth vs time.

If I give a list of transformation functions these are applied to different copies of the original object instead of the same in sequence

Graphics3D[{
  Opacity[1]
  , Red
  , Arrow[{{0, 0, 0}, {1, 0, 0}}]
  , Green
  , Arrow[{{0, 0, 0}, {0, 1, 0}}]
  , Blue
  , Arrow[{{0, 0, 0}, {0, 0, 1}}]
  , Opacity[0.2]
  , GeometricTransformation[Cuboid[-{1, 1, 1}/4, {1, 1, 1}/4],
   {
    RotationTransform[Pi/4, {0, 0, 1}]
    , TranslationTransform[{1, 1, 1}]
    }
   ]
  }]

Mathematica graphics

How do I properly compose several sequential geometrical transformations ?

$\endgroup$
  • $\begingroup$ I figure out the solution as soon as I posted the question and read one of the Related posts. I'm not sure if I should delete this or not. Anyhow I'm looking forward for other better solutions. $\endgroup$ – rhermans Oct 15 '14 at 22:40
  • 2
    $\begingroup$ You can use Fold too, but matrix multiplication may be slightly faster: How to render a 3D ellipsoid with Graphics3D? $\endgroup$ – Kuba Oct 15 '14 at 22:48
  • 2
    $\begingroup$ FYI: There is nothing wrong with answering your own question. In fact it is a recommended practice if you have something particularly nice you wish to share e.g. (54784). See: (834) $\endgroup$ – Mr.Wizard Oct 15 '14 at 23:48
14
$\begingroup$

Using Composition I can apply RotationTransform, TranslationTransform , ShearingTransform one after the other.

Graphics3D[{
  Opacity[1]
  , Red
  , Arrow[{{0, 0, 0}, {1, 0, 0}}]
  , Green
  , Arrow[{{0, 0, 0}, {0, 1, 0}}]
  , Blue
  , Arrow[{{0, 0, 0}, {0, 0, 1}}]
  , Opacity[0.2]
  , GeometricTransformation[Cuboid[-{1, 1, 1}/4, {1, 1, 1}/4],
   Composition @@ {
     RotationTransform[Pi/4, {0, 0, 1}]
     , TranslationTransform[{1, 1, 1}]
     , ShearingTransform[Pi/8, {1, 0, 0}, {0, 0, 1}]
     }
   ]
  }]

Mathematica graphics

$\endgroup$
  • 2
    $\begingroup$ I did not know that Composition would combine *Transform expressions in this manner so you just taught me something. Thanks and +1. $\endgroup$ – Mr.Wizard Oct 15 '14 at 23:51

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.