# reconstruct matrix with absolute scale

## Recommended Posts

Hi,

I needed to scale down the objects of my RBD sim and the way to do this is well covered in an entagma turorial. In short, a geometry wrangle node connected in the pre-solve input of the solver, gets then modifies and then sets the transform matrix of the packed primitives using the primintrinsic functions. I need to control the scale with an animated value but to do so I need to set the absolute value of the scale. The way it is now the transformation is relative. For example if the input value is a constant 0.5, applying this scale to the input matrix modifies the modified matrix and is quickly solved to a scale of 0. What I want is to keep the scale constant at 0.5.

I was under the impression that a 3x3 (as well as 4x4) matrix has its scale values diagonal at row 0 column 0, row 1 column 1 and row 2 column 2. If that was the case I could just set these values. However when the object is rotated by the solver it looks like the rotation is solved as a skew/scale combination. Modifiing the values above gives a different result from the expected.

Is there a way to extract the rotation from the matrix and then create a new matrix with my absolute scale and appy the rotation only to it? Or is there any other way I can achieve this?

I've attached an example scene.

absoluteScale.hipnc

##### Share on other sites

I`m not sure what do you exactly need, but may be this will help

By the way you can always create you own matrix by basis ( 3 ortogonal vectors ) and point position. You can use polyFrame node to create those vectors, then just put them one by one in 3x3 matrix to each row and use translate node (in Point VOP ) to add position in each frame, then you will get 4x4 matrix. If you will apply this matrix to static object (1st frame geo) it will start to move and finally you can manipulate each step to achive result that you need.

Edited by Sega
• 1

##### Share on other sites

Extracting the rotation this way worked great. Thank you. Here's the vex code in case someone is looking to something similar, note that the intrinsic attribute is a 3x3 matrix with only the rotation and scale, just ignore the last row and column from the examples above.

```matrix3 m = primintrinsic(0, "transform", @ptnum);

// extract scale
float s[];
for(int i=0; i<3; i++)
{
vector r = set( getcomp(m, 0, i), getcomp(m, 1, i), getcomp(m, 2, i) );
s[i] = length( r );
}

// extract rotation
for(int row=0; row<3; row++)
for(int col=0; col<3; col++)
{
float val = getcomp(m, row, col);
setcomp(m, val/s[col], row, col);
}

float scale = 0.5;
matrix3 mm = ident();
scale(mm, set(scale, scale, scale));

mm*=m;
setprimintrinsic(0, "transform", @ptnum, mm, "set");```

Edited by agelosc
• 2

##### Share on other sites

this is why i love this forum.

##### Share on other sites

Or use cracktransform.

• 1

## Create an account

Register a new account