Transform.scale#
- Transform.scale(
- *factor: float | VectorLike[float],
- point: VectorLike[float] | None = None,
- multiply_mode: Literal['pre', 'post'] | None = None,
Compose a scale matrix.
Create a scale matrix and
compose()it with the current transformationmatrixaccording to pre-multiply or post-multiply semantics.Internally, the matrix is stored in the
matrix_list.- Parameters:
- *factor
float|VectorLike[float] Scale factor(s) 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).
- point
VectorLike[float],optional Point to scale from. By default, the object’s
pointis used, but this can be overridden. If set, two additional transformations are composed and added to thematrix_list:translate()topointbefore the scalingtranslate()away frompointafter the scaling
- multiply_mode‘pre’ | ‘post’,
optional Multiplication mode to use when composing the matrix. By default, the object’s
multiply_modeis used, but this can be overridden. Set this to'pre'for pre-multiplication or'post'for post-multiplication.
- *factor
See also
pyvista.DataObjectFilters.scaleScale a mesh.
pyvista.DataObjectFilters.resizeResize a mesh.
scale_factors,has_scaleGet info about the transform’s scale component.
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.]])