Get geometries transformation matrix

Hi there,

this might be a quite stupid question.
Is there any chance to get the transformation matrix of an object’s transformation?

I am familiar with the concept of transformation matrices.
In RhinoCommon I found ways to create tranformation matrices, but not something to receive it in order to apply it to other objects.

Thanks,
T.

Hi Tobias,

You have an instance of rg.Transform and you would like to convert it to some list of list representation of the 4x4 matrix, and vice-versa. Did I understand that correctly? If so, then:

import Rhino

# input: xform2

# deconstruct rg.Transform to python LL
matrix = []
for i in xrange(4):
    row_L = []
    for g in xrange(4):
        row_L.append( xform2.Item[i,g] )
    matrix.append( row_L )
print "matrix: ", matrix


# create rg.Transform from python LL matrix
xform = Rhino.Geometry.Transform.Unset

for i in xrange(4):
    for g in xrange(4):
        xform.Item[i,g] = matrix[i][g]
print "xform: ", xform

Why would you like to manipulate the objects, manually by creating transformation matrices?

@djordje, sorry for artriculating myself a bit blurry here.
I want to pick an element, let’s say a box or a surface.
Then I want to align another element at that transformation if possible.
So is it possible to read the transformation matrix of an object in a Rhino-Document?

I mean if this is a practise that is not good at all, I understand.
To me it seems quite handy and efficient, so I though I’d dig into that a bit.

Hi @tobias.stoltmann,
Only block instances contain transformation data (they have ’ InstanceXform’ property).

For all other objects, some custom coded way would have to be written to identify the starting plane and the one to which it needs to be aligned to.

1 Like

@djordje, this is exactly what I missed.
I used that property from block instances and that’s why I thought it would be possible to get that from non-block objects as well.

So I will just continue using planes evaluated from e.g. surfaces and points and then create the transform matrix from the source/target plane.

Thanks a lot!

If you would like to share how complicated the custom code for getting these planes would be looking like, I would be very much interested though.

Hi @tobias.stoltmann,
I don’t have such code.
Check this topic for one example:

@djordje
Thanks! :slight_smile:

1 Like