Transform.scale

Transform.scale#

Transform.scale(
*factor: float | VectorLikeFloat,
point: VectorLikeFloat | None = None,
multiply_mode: Literal['pre', 'post'] | None = None,
) → Transform[source]#

Compose a scale matrix.

Create a scale matrix and compose() it with the current transformation matrix according to pre-multiply or post-multiply semantics.

Internally, the matrix is stored in the matrix_list.

Parameters:
*factorfloat | VectorLikeFloat

Scale factors to use. Use a single number for uniform scaling or three numbers for non-uniform scaling. The three factors may be passed as a single vector (one arg) or an unpacked vector (three args).

pointVectorLikeFloat, optional

Point to scale from. By default, the object’s point is used, but this can be overridden. If set, two additional transformations are composed and added to the matrix_list:

multiply_mode‘pre’ | ‘post’, optional

Multiplication mode to use when composing the matrix. By default, the object’s multiply_mode is used, but this can be overridden. Set this to 'pre' for pre-multiplication or 'post' for post-multiplication.

Examples#

Download Python source code | Download Jupyter notebook

Compose a scale matrix.

>>> import pyvista as pv
>>> transform = pv.Transform().scale(1, 2, 3)
>>> transform.matrix
array([[1., 0., 0., 0.],
       [0., 2., 0., 0.],
       [0., 0., 3., 0.],
       [0., 0., 0., 1.]])

Compose a second scale matrix using *.

>>> transform = transform * 2
>>> transform.matrix
array([[2., 0., 0., 0.],
       [0., 4., 0., 0.],
       [0., 0., 6., 0.],
       [0., 0., 0., 1.]])

Scale from a point. Check the matrix_list to see that a translation is added before and after the scaling.

>>> transform = pv.Transform().scale(7, point=(1, 2, 3))
>>> translation_to_origin = transform.matrix_list[0]
>>> translation_to_origin
array([[ 1.,  0.,  0., -1.],
       [ 0.,  1.,  0., -2.],
       [ 0.,  0.,  1., -3.],
       [ 0.,  0.,  0.,  1.]])
>>> scale = transform.matrix_list[1]
>>> scale
array([[7., 0., 0., 0.],
       [0., 7., 0., 0.],
       [0., 0., 7., 0.],
       [0., 0., 0., 1.]])
>>> translation_from_origin = transform.matrix_list[2]
>>> translation_from_origin
array([[1., 0., 0., 1.],
       [0., 1., 0., 2.],
       [0., 0., 1., 3.],
       [0., 0., 0., 1.]])

See Also#

pyvista.DataObjectFilters.scale

Scale a mesh.

pyvista.DataObjectFilters.resize

Resize a mesh.

scale_factors, has_scale

Get info about the transform’s scale component.