coords.Coords.translate#
- Coords.translate(dir, step=1.0, inplace=False)#
Return a translated copy of the
Coordsobject.Translate the Coords by a vector determined from dir and step:
If
diris an int, it specifies a coordinate axis (0, 1, or 2), and the Coords are shifted bystepalong that axis.If
diris a vector, the Coords are shifted bystep * dir.
Parameters#
- dir: int (0,1,2) or float array_like (…,3)
The translation vector. If an int, it specifies a global axis and the translation is in the direction of that axis. If an array_like, it specifies one or more translation vectors. If more than one, the array should be broadcastable to the Coords shape: this allows to translate different parts of the Coords over different vectors, all in one operation.
- step: float
If
diris an int, this is the length of the translation. Else, it is a multiplying factor applied todirprior to applying the translation.
Returns#
- Coords
The Coords translated over the specified vector(s).
See Also#
centered(): translate to center around originalign(): translate to align bounding box
Examples#
>>> x = Coords([1.0, 1.0, 1.0]) >>> print(x.translate(1)) [1. 2. 1.] >>> print(x.translate(1,step = 1.)) [1. 2. 1.] >>> print(x.translate([0.0, 1.0, 0.0])) [1. 2. 1.] >>> print(x.translate([0.0, 2.0, 0.0], 0.5)) [1. 2. 1.]
>>> x = Coords(np.arange(4).reshape(2,2,1)) >>> x Coords([[[0., 0., 0.], [1., 0., 0.]], [[2., 0., 0.], [3., 0., 0.]]]) >>> x.translate([[10.,-5.,0.],[20.,4.,0.]]) # translate with broadcasting Coords([[[10., -5., 0.], [21., 4., 0.]], [[12., -5., 0.], [23., 4., 0.]]])