Features of using the scale matrix

To manipulate object transformations with matrices, Blender includes the “mathutils” module in which the “Matrix” class is defined. With this class, you can simply create the necessary transformation matrices – translation, rotation, and scale.

The following command is used to create a scale matrix:

where:

SCALE_VALUE – the multiplier. How many times you need to change the scale with the resulting matrix,

MATRIX_SIZE – the size of the resulting matrix,

AXIS – a vector that determines on which axes the object will be scaled with the resulting matrix.

For example, to create a matrix of 2x scaling along the X-axis, you need to execute the following:

Everything looks simple, but this method has one non-obvious feature.

If you need to create a scaling matrix along all three axes simultaneously, it seems logical to specify all the axes in the “AXES” parameter when calling this method :

But this doesn’t work, the resulting matrix is ​​not correct!

To create a scaling matrix along all three axes, you need to create separate scaling matrices for each of the axes and then multiply them:

Now we get the correct matrix for scaling along three axes.

0 0 votes
Article Rating
Subscribe
Notify of
guest

2 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
mod
mod
1 year ago

try
scale = Matrix.Diagonal( Vector( [dims[0], dims[1], dims[2], 1] ) )

Nikita
Editor
1 year ago
Reply to  mod

The shortest way?