How to write a transformation matrix in Python?

Hi every one,

I´m having a problem relating to transformation matrix in python,

  1. How to select the object I want to transform
  2. how to choose a base point of transformation for the choosen geometry?
  3. How to populate the transformation matrix with the values I have (the 16 values of them) ?

An example and a simple explanation would be perfect.

Thanks in advance

Hi @Nader_Belal,

RhinoCommon’s 4x4 transformation matrix is the Transform structure.

Here is an example of moving an object. The sample also provides dynamic feedback.

https://github.com/mcneel/rhino-developer-samples/blob/6/rhinopython/SampleMove.py

– Dale

Thank you dale,

I was was aware of Transform structure, the problem is that I’ve the values of M00 - M33 and I don’t know how to write them in the matrix Transform structure.

Hi @Nader_Belal,

You can always just do this:

import Rhino

point = Rhino.Geometry.Point3d(1.0, 2.0, 3.0)

xform = Rhino.Geometry.Transform(0)
xform[0, 3] = point.X
xform[1, 3] = point.Y
xform[2, 3] = point.Z
xform[3, 3] = 1.0

print xform.IsValid

– Dale

1 Like

@dale Sorry to bother you.

I have a surface that represents a loaded picture in Rhino’s document as PicFrame with Python, but as you know, PicFrame origin would be point 0,0.

The problem is that I need to define the center of the upper left pixel as the origin point (assume that 1 pixel = 1 rhino unit) to apply a transformation matrix that may include a shear and/or tilt operation (I have their values), so how to do the transformation correctly ???

Another question: Are xform operations (tilt/shear included) are origin independent ?