Compound transformation equivivalent in C#


If I have several Transformation Matrices:

3)And 3 translations

Is there a possibility to merge all those matrices into one?

In grasshopper I used compound component to merge several matrices.

But using rhinocommon I tried to multiply matrices and it does not produce same result, for instance in this example I did not include translation, but still not producing what gh does with compound:

Transform mergedMatrix = Transform.Multiply(Orientation, Rotation);

What is correct way of joining matrices?

Well the order matters, the last transformation in Multyply () is performed first if I recall correctly. Do you get more favorable solutions if you change the order around?

Hi @Petras_Vestartas,

Transform matrices can be multiplied.

var xf_translate = Transform.Translation(...);
var xf_rotate = Transform.Rotation(...);
var xf_scale = Transform.Scale(...);
var xf_final = xf_translate * xf_rotate * xf_scale;
if (xf_final.IsValid)
  // TODO...

Note, the order is important…

– Dale

1 Like

Dear Dale,

Thank you for a reply.

I was very smart so I was multiplying matrices like this:

AllCollectedTransformations *= CurrentTransform;

While it had to be AllCollectedTransformations = CurrentTransform * AllCollectedTransformations ;

Lesson learnt order matters…

Why does multiplying the transforms VS using the compound transform component (which uses GH_Transform, GH_Transform.ComoundTransforms, and ITransform result in a different final transform result even with the same order? (12.9 KB)

Does Compound Transformations takes max 2 transformations?

No it takes many, @DavidRutten said sometime ago the description is not correct.

It seems the multiplication way needs the scale to be plugged first, then move. The compound component needs move first, then scale. Then the results are the same. Which one is the correct logic?

To me the compound component seems correct. First you move up 10, then you scale by the origin at .5 (so the box is now half the size and positioned at 5 units height. because it scaled at .5 towards the origin).

If you plug the multiplication way as move then scale like the compound way then the box goes up 10 units but then scales toward the origin, but maintains its height of 10 units.

Really not sure whats the correct logic. Both kind of make sense in some way. (12.0 KB)

Mathematically, RhinoCommon matrices multiply in the correct way. Intuitively, Grasshopper transforms multiply in the correct way. If you want to first move, then scale, the order for a compound transform is (1) move (2) scale. To achieve the same with RhinoCommon transforms you need scale * move.