I am trying to wrap my head around the transformation matrix in Rhino Python, and was wondering if there was something out there that listed what each item in the matrix controls. For instance scale, rotation, position. Looking through the help this is as close as I got to the structure,but don’t know what each value controls.
Ultimate Goal: I want to click on a block and find out what transformations have been done to it so I can set them to different values if needed.
So through some basic messing I think I figured out where the scale and position entries are. Now I just need to figure out what the rest of the boxes(entries) corollate to. I assume a rotation vector is in there somewhere, but could be wrong. Also not sure what the last row is for.
The Rhino SDK does not contain functions that will decompose a transformation matrix into it’s individual components (e.g. scale, rotation, translation). If you Google the topic, you will probably find lots if information on the subject. Just keep in mind that there is no perfect solution for this, as you will find in your research.
Thanks @dale, just so I understand when I insert a block into Rhino with postion(x,y,z) a scale(x,y,z) and a rotation angle there is no way for me to retrieve it later on???
I guess I need read up on transformation matrix, but I assume it just a matrix that was storing these values and that I could extract a value like position x, and enter a new value for it.
As it seems like the examples I have seen for transformation matrix is say you have matrix of all the points on a cube and you want to move the cube, you could multiple the matrix of the points with the move vector matrix and get the resulting new points for the cube. So I not sure how that equates to properties needed to input a block into Rhino.
There is no perfect way. For example, certain scale operations rotation operations can cause the scale and rotation components of the transform will become mixed.
Here are a couple of sample routines I wrote some time ago. They are fairly rudimentary. If you know that your transform only has particular types of component transforms inside it and if you’re willing to accept the fact that you won’t get an exact version of those transforms back after decomposition, they might work for you.
I’m new to scripting and I’ve found myself in the deep end.
I am trying to find the size of a block. If I use bounding box, the size is incorrect because of its rotation and location in 3Dspace. So my new approach is to use the Transformation Matrix to decompose the Block so that it is back at F4 (where the original block instance started). Then I was hoping to use Bounding Box to get an accurate size.
I am very thankful to find Dales script. When I run the script I am prompted to pick the block. In an attempt to bypass the command line I altered the script to select the block by Object Type. But I get an error (I think because it picks all the blocks in the file instead of one).
Next, I’m unsure whether I can directly use the resulting coordinates to move/scale/rotate back into place. Or do I need to export the coordinates to an excel then call to them to move,scale,rotate.
I’m really new to scripting. I tried to follow your instructions, but I appear to be putting the bbox on the block in 3d space as opposed to using the rhino.worldXY source. Here is the edit i made. Can you advise what I’m doing wrong?
If Rhino.IsBlockInstance(strObject) Then
arrMatrix = Rhino.BlockInstanceXform(strObject)
If IsArray(arrMatrix) Then
arrBlockPlane = Rhino.PlaneTransform(Rhino.WorldXYPlane(), arrMatrix)
If IsArray(arrBlockPlane) Then
box = rhino.BoundingBox(strObject)
Dim distX, distY, distZ
distX = rhino.Distance(box(0), box(1))
distY = rhino.Distance(box(0), box(3))
distZ = rhino.Distance(box(0), box(4))
xlApp.Cells(intCount + 2, 10).Value = round(distX, 2)
xlApp.Cells(intCount + 2, 11).Value = round(distY, 2)
xlApp.Cells(intCount + 2, 12).Value = round(distZ, 2)