coords.Coords.rotate#
- Coords.rotate(angle, axis=2, around=None, angle_spec=0.017453292519943295)#
Return a copy rotated over angle around axis.
Parameters#
- angle: float or float array_like (3,3)
If a float, it is the rotation angle, by default in degrees, and the parameters (angle, axis, angle_spec) are passed to
rotationMatrix()to produce a (3,3) rotation matrix. Alternatively, the rotation matrix may be directly provided in the angle parameter. The axis and angle_spec are then ignored.- axis: int (0,1,2) or float array_like (3,)
Only used if angle is a float. If provided, it specifies the direction of the rotation axis: either one of 0,1,2 for a global axis, or a vector with 3 components for a general direction. The default (axis 2) is convenient for working with 2D-structures in the x-y plane.
0= x-axis,1= y-axis,2= z-axis.- around: float array_like (3,)
If provided, it specifies a point on the rotation axis. If not, the rotation axis goes through the origin of the global axes.
- angle_spec: float, at.DEG or RAD, optional
Only used if angle is a float. The default (at.DEG) interpretes the angle in degrees. Use RAD to specify the angle in radians.
Returns#
- Coords
The Coords rotated as specified by the parameters.
See Also#
translate(): translate a Coordsaffine(): rotate and translate a Coords
Examples#
>>> X = Coords([[0.0, 0.0],[1.0, 0.0],[1.0, 1.0],[0.0, 1.0]]) >>> print(X.rotate(30)) [[ 0. 0. 0. ] [ 0.866 0.5 0. ] [ 0.366 1.366 0. ] [-0.5 0.866 0. ]] >>> print(X.rotate(30,axis=0)) [[0. 0. 0. ] [1. 0. 0. ] [1. 0.866 0.5 ] [0. 0.866 0.5 ]] >>> print(X.rotate(30,axis=0,around=[0.,0.5,0.])) [[ 0. 0.067 -0.25 ] [ 1. 0.067 -0.25 ] [ 1. 0.933 0.25 ] [ 0. 0.933 0.25 ]]
The module arraytools, here imported as at, provides a function to generate a rotation matrix:
>>> m = at.rotationMatrix(30,axis=0) >>> print(X.rotate(m)) [[0. 0. 0. ] [1. 0. 0. ] [1. 0.866 0.5 ] [0. 0.866 0.5 ]]