Acceleration vector(s) in ECEF coordinates (ax, ay, az) in m/s².
Associated with a Time object for the time instances of the accelerations.
Internal use only, typically created from Path objects.
No data validation is performed.
Parameters:
vec (Array) – Acceleration vectors in ECEF coordinates (ax, ay, az) in m/s². Shape (n, 3).
time (Time) – Time object associated with the accelerations. Length must match number of acceleration vectors.
backend (BackendArg, optional) – Array backend to use (numpy, jax, etc.). Defaults to numpy.
_xp (Any)
classmethodfrom_data(vec, time, backend=None)[source]¶
Create an Acceleration object from acceleration vector array and Time object.
A reference frame defined by a rotation and location.
Can be static or time-varying, and can have rotation defined relative to another Frame.
Combines RotationLike and Location objects, and manages time associations.
Parameters:
rot (Rotation | RotationSequence) – A scipy Rotation object (single rotation) or RotationSequence (time-tagged rotations).
If a single Rotation is provided, the frame rotation is static.
loc (Location, optional) – A Location object (Point or Path) defining the frame origin in ECEF coordinates.
If not provided, the frame origin is assumed to be at the origin of the reference frame.
If loc is provided, it must be a singular Point (1x3) for static frames.
Use Path objects for time-varying locations.
ref_frame (Frame, optional) – A reference Frame object to define the rotation relative to.
If not provided, the rotation is assumed to be absolute (e.g., from ECEF frame).
backend (BackendArg, optional) – Array backend to use (numpy, jax, etc.). Defaults to numpy.
Replace a rotation in the rotation chain with a new rotation.
This is an advanced feature and currently only applicable for static rotations.
Should primarily be used for optimisation purposes in autograd frameworks, such as
correcting misalignment.
Parameters:
frame_name (str) – Name of the frame whose rotation is to be replaced.
new_rot (Rotation) – New scipy Rotation object to replace the existing rotation.
Sample the Frame object at specific times, returning a new Frame with
time-varying components sampled at those times. The new frame can then be
indexed at these times directly to avoid interpolation
Parameters:
time (Time) – Time object specifying the times to sample the Frame at.
Returns:
New Frame object with components sampled at the specified times.
Path of multiple Point objects with associated Time.
Enables interpolation between points over time and calculation of velocity.
Must have at least 2 points with associated Time.
Parameters:
point (Point | list of Point) – Point object or list of Point objects with associated Time.
If a list is provided, all Points must have the same backend and associated Time.
backend (BackendArg, optional) – Array backend to use (numpy, jax, etc.). Defaults to numpy.
Find the times when the Path crosses the given altitude (in metres).
Uses linear interpolation between points to find the crossing times.
Note: This function is not JIT-compatible due to data validation checks.
Truncate the Path to the given start and end times.
If start_time or end_time is None, the Path is truncated to the start or end of the Path respectively.
Note: This function is not JIT-compatible due to data validation checks.
Point(s) in ECEF coordinates, stored as (x, y, z) in metres.
Can represent a single point or multiple points, and can be associated with
a Time object for time instances of the points.
Parameters:
ecef (Array) – ECEF coordinates as (x, y, z) in metres. Shape (3,) or (1,3) for single points, (n, 3) for multiple points.
time (Time, optional) – Time object associated with the points. If provided, the length of time must match the number of points.
Defaults to TIME_INVARIANT for static points.
backend (BackendArg, optional) – Array backend to use (numpy, jax, etc.). Defaults to numpy.
A ray defined by an origin point, direction vector, reference frame, and optional time.
Parameters:
dir_rel (Array) – Nx3 array of ray direction vectors in local frame.
Need not be normalised. E.g., (1, 0, 0) is a ray pointing along axis 1 of reference frame.
origin_rel (Array) – 1x3 or Nx3 array defining the ray origin(s) in local frame (meters).
Typically (0,0,0) for camera reference frames, or ECEF coordinates for ECEF frame rays.
frame (Frame, optional) – Reference frame for the ray origin and direction.
time (Time, optional) – Time object associated with the rays.
Must be same length as origin if provided. Defaults to TIME_INVARIANT.
check (bool, optional) – If True (default), validate non-zero direction vectors; disable for JIT paths.
backend (BackendArg, optional) – Array backend to use (numpy, jax, etc.). Defaults to numpy.
Notes
For calculating metrics (e.g. az/el), the axis are assumed (1) forward, (2) right, (3) down (FRD frame).
Although stored in local coordiantes, rays are globally defined by their reference frame.
Monotonically increasing time is required for interpolation. But to prevent data-dependent control flow,
this is not checked on initialization. Use Time.is_increasing to check if needed.
Apply atmospheric refraction correction to the Ray object using Bennett’s formula.
Altitude sets the exponential scale height (metres) for the correction.
Returns:
New Ray object with refraction-corrected direction vectors.
Get the ray origin point(s) as ECEF.
Note: this involves a frame transformation. For repeated access,
recommend converting the Ray to ECEF frame first using to_ecef().
Get the unit direction vector(s) of the ray in ECEF frame.
Note: this involves a frame transformation. For repeated access,
recommend converting the Ray to ECEF frame first using to_ecef().
This class provides an interface to initialize from and represent rotations
with:
Quaternions
Rotation Matrices
Rotation Vectors
Modified Rodrigues Parameters
Euler Angles
Davenport Angles (Generalized Euler Angles)
The following operations on rotations are supported:
Application on vectors
Rotation Composition
Rotation Inversion
Rotation Indexing
A Rotation instance can contain a single rotation transform or rotations of
multiple leading dimensions. E.g., it is possible to have an N-dimensional array of
(N, M, K) rotations. When applied to other rotations or vectors, standard
broadcasting rules apply.
Indexing within a rotation is supported to access a subset of the rotations stored
in a Rotation instance.
To create Rotation objects use from_... methods (see examples below).
Rotation(...) is not supposed to be instantiated directly.
A Rotation instance can be initialized in any of the above formats and
converted to any of the others. The underlying object is independent of the
representation used for initialization.
Consider a counter-clockwise rotation of 90 degrees about the z-axis. This
corresponds to the following quaternion (in scalar-last format):
It is also possible to initialize multiple rotations in a single instance
using any of the from_... functions. Here we initialize a stack of 3
rotations using the from_euler method:
These examples serve as an overview into the Rotation class and highlight
major functionalities. For more thorough examples of the range of input and
output formats supported, consult the individual method’s examples.
Estimate a rotation to optimally align two sets of vectors.
Find a rotation between frames A and B which best aligns a set of
vectors a and b observed in these frames. The following loss
function is minimized to solve for the rotation matrix
\(C\):
where \(w_i\)’s are the weights corresponding to each vector.
The rotation is estimated with Kabsch algorithm [1]_, and solves what
is known as the “pointing problem”, or “Wahba’s problem” [2]_.
Note that the length of each vector in this formulation acts as an
implicit weight. So for use cases where all vectors need to be
weighted equally, you should normalize them to unit length prior to
calling this method.
There are two special cases. The first is if a single vector is given
for a and b, in which the shortest distance rotation that aligns
b to a is returned.
The second is when one of the weights is infinity. In this case, the
shortest distance rotation between the primary infinite weight vectors
is calculated as above. Then, the rotation about the aligned primary
vectors is calculated such that the secondary vectors are optimally
aligned per the above loss function. The result is the composition
of these two rotations. The result via this process is the same as the
Kabsch algorithm as the corresponding weight approaches infinity in
the limit. For a single secondary vector this is known as the
“align-constrain” algorithm [3]_.
For both special cases (single vectors or an infinite weight), the
sensitivity matrix does not have physical meaning and an error will be
raised if it is requested. For an infinite weight, the primary vectors
act as a constraint with perfect alignment, so their contribution to
rssd will be forced to 0 even if they are of different lengths.
Parameters:
a (array_like, shape (3,) or (N, 3)) – Vector components observed in initial frame A. Each row of a
denotes a vector.
b (array_like, shape (3,) or (N, 3)) – Vector components observed in another frame B. Each row of b
denotes a vector.
weights (array_like shape (N,), optional) – Weights describing the relative importance of the vector
observations. If None (default), then all values in weights are
assumed to be 1. One and only one weight may be infinity, and
weights must be positive.
return_sensitivity (bool, optional) – Whether to return the sensitivity matrix. See Notes for details.
Default is False.
rotation (Rotation instance) – Best estimate of the rotation that transforms b to a.
rssd (float) – Stands for “root sum squared distance”. Square root of the weighted
sum of the squared distances between the given sets of vectors
after alignment. It is equal to sqrt(2*minimum_loss), where
minimum_loss is the loss function evaluated for the found
optimal rotation.
Note that the result will also be weighted by the vectors’
magnitudes, so perfectly aligned vector pairs will have nonzero
rssd if they are not of the same length. This can be avoided by
normalizing them to unit length prior to calling this method,
though note that doing this will change the resulting rotation.
sensitivity_matrix (ndarray, shape (3, 3)) – Sensitivity matrix of the estimated rotation estimate as explained
in Notes. Returned only when return_sensitivity is True. Not
valid if aligning a single pair of vectors or if there is an
infinite weight, in which cases an error will be raised.
Notes
The sensitivity matrix gives the sensitivity of the estimated rotation
to small perturbations of the vector measurements. Specifically we
consider the rotation estimate error as a small rotation vector of
frame A. The sensitivity matrix is proportional to the covariance of
this rotation vector assuming that the vectors in a was measured with
errors significantly less than their lengths. To get the true
covariance matrix, the returned sensitivity matrix must be multiplied
by harmonic mean [4] of variance in each observation. Note that
weights are supposed to be inversely proportional to the observation
variances to get consistent results. For example, if all vectors are
measured with the same accuracy of 0.01 (weights must be all equal),
then you should multiple the sensitivity matrix by 0.01**2 to get the
covariance.
Refer to [5] for more rigorous discussion of the covariance
estimation. See [6] for more discussion of the pointing problem and
minimal proper pointing.
This function does not support broadcasting or ND arrays with N > 2.
Array API Standard Support
align_vectors has experimental support for Python Array API Standard compatible
backends in addition to NumPy. Please consider testing these features
by setting an environment variable SCIPY_ARRAY_API=1 and providing
CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following
combinations of backend and device (or other capability) are supported.
The error for the first vector is 0, and for the last two the error is
magnitude 0.1. The rssd is the square root of the sum of the
weighted squared errors, and the default weights are all 1, so in this
case the rssd is calculated as
sqrt(1*0**2+1*0.1**2+1*(-0.1)**2)=0.141421356237308
Concatenate a sequence of Rotation objects into a single object.
This is useful if you want to, for example, take the mean of a set of
rotations and need to pack them into a single object to do so.
Parameters:
rotations (sequence of Rotation objects) – The rotations to concatenate. If a single Rotation object is
passed in, a copy is returned.
Returns:
concatenated – The concatenated rotations.
Return type:
Rotation instance
Notes
Added in version 1.8.0.
Array API Standard Support
concatenate has experimental support for Python Array API Standard compatible
backends in addition to NumPy. Please consider testing these features
by setting an environment variable SCIPY_ARRAY_API=1 and providing
CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following
combinations of backend and device (or other capability) are supported.
Note that it may be simpler to create the desired rotations by passing
in a single list of the data during initialization, rather then by
concatenating:
Rotations in 3-D can be represented by a sequence of 3
rotations around a sequence of axes.
The three rotations can either be in a global frame of reference
(extrinsic) or in a body centred frame of reference (intrinsic), which
is attached to, and moves with, the object under rotation [1]_.
For both Euler angles and Davenport angles, consecutive axes must
be are orthogonal (axis2 is orthogonal to both axis1 and
axis3). For Euler angles, there is an additional relationship
between axis1 or axis3, with two possibilities:
axis1 and axis3 are also orthogonal (asymmetric sequence)
axis1==axis3 (symmetric sequence)
For Davenport angles, this last relationship is relaxed [2]_, and only
the consecutive orthogonal axes requirement is maintained.
Parameters:
axes (array_like, shape (3,) or (..., [1 or 2 or 3], 3)) – Axis of rotation, if one dimensional. If two or more dimensional, describes
the sequence of axes for rotations, where each axes[…, i, :] is the ith
axis. If more than one axis is given, then the second axis must be
orthogonal to both the first and third axes.
order (string) – If it is equal to ‘e’ or ‘extrinsic’, the sequence will be
extrinsic. If it is equal to ‘i’ or ‘intrinsic’, sequence
will be treated as intrinsic.
angles (float or array_like, shape (..., [1 or 2 or 3])) – Angles specified in radians (degrees is False) or degrees
(degrees is True).
Each angle i in the last dimension of angles turns around the corresponding
axis axis[…, i, :]. The resulting rotation has the shape
np.broadcast_shapes(np.atleast_2d(axes).shape[:-2], np.atleast_1d(angles).shape[:-1])
Dimensionless angles are thus only valid for a single axis.
degrees (bool, optional) – If True, then the given angles are assumed to be in degrees.
Default is False.
Returns:
rotation – Object containing the rotation represented by the sequence of
rotations around given axes with given angles.
Return type:
Rotation instance
Notes
Array API Standard Support
from_davenport has experimental support for Python Array API Standard compatible
backends in addition to NumPy. Please consider testing these features
by setting an environment variable SCIPY_ARRAY_API=1 and providing
CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following
combinations of backend and device (or other capability) are supported.
Library
CPU
GPU
NumPy
✅
n/a
CuPy
n/a
✅
PyTorch
✅
✅
JAX
✅
✅
Dask
⛔
n/a
See dev-arrayapi for more information.
References
Examples
>>> fromscipy.spatial.transformimportRotationasR
Davenport angles are a generalization of Euler angles, when we use the
canonical basis axes:
>>> ex=[1,0,0]>>> ey=[0,1,0]>>> ez=[0,0,1]
Initialize a single rotation with a given axis sequence:
Rotations in 3-D can be represented by a sequence of 3
rotations around a sequence of axes. In theory, any three axes spanning
the 3-D Euclidean space are enough. In practice, the axes of rotation are
chosen to be the basis vectors.
The three rotations can either be in a global frame of reference
(extrinsic) or in a body centred frame of reference (intrinsic), which
is attached to, and moves with, the object under rotation [1]_.
Parameters:
seq (string) – Specifies sequence of axes for rotations. Up to 3 characters
belonging to the set {‘X’, ‘Y’, ‘Z’} for intrinsic rotations, or
{‘x’, ‘y’, ‘z’} for extrinsic rotations. Extrinsic and intrinsic
rotations cannot be mixed in one function call.
angles (float or array_like, shape (..., [1 or 2 or 3])) – Euler angles specified in radians (degrees is False) or degrees
(degrees is True).
Each character in seq defines one axis around which angles turns.
The resulting rotation has the shape np.atleast_1d(angles).shape[:-1].
Dimensionless angles are thus only valid for single character seq.
degrees (bool, optional) – If True, then the given angles are assumed to be in degrees.
Default is False.
Returns:
rotation – Object containing the rotation represented by the sequence of
rotations around given axes with given angles.
Return type:
Rotation instance
Notes
Array API Standard Support
from_euler has experimental support for Python Array API Standard compatible
backends in addition to NumPy. Please consider testing these features
by setting an environment variable SCIPY_ARRAY_API=1 and providing
CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following
combinations of backend and device (or other capability) are supported.
Rotations in 3 dimensions can be represented with 3 x 3 orthogonal
matrices [1]_. If the input is not orthogonal, an approximation is
created by orthogonalizing the input matrix using the method described
in [2]_, and then converting the orthogonal rotation matrices to
quaternions using the algorithm described in [3]_. Matrices must be
right-handed.
Parameters:
matrix (array_like, shape (..., 3, 3)) – A single matrix or an ND array of matrices, where the last two dimensions
contain the rotation matrices.
assume_valid (bool, optional) – Must be False unless users can guarantee the input is a valid rotation
matrix, i.e. it is orthogonal, rows and columns have unit norm and the
determinant is 1. Setting this to True without ensuring these properties
is unsafe and will silently lead to incorrect results. If True,
normalization steps are skipped, which can improve runtime performance.
Default is False.
Returns:
rotation – Object containing the rotations represented by the rotation
matrices.
Return type:
Rotation instance
Notes
This function was called from_dcm before.
Added in version 1.4.0.
Array API Standard Support
from_matrix has experimental support for Python Array API Standard compatible
backends in addition to NumPy. Please consider testing these features
by setting an environment variable SCIPY_ARRAY_API=1 and providing
CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following
combinations of backend and device (or other capability) are supported.
Initialize from Modified Rodrigues Parameters (MRPs).
MRPs are a 3 dimensional vector co-directional to the axis of rotation and whose
magnitude is equal to tan(theta/4), where theta is the angle of
rotation (in radians) [1]_.
MRPs have a singularity at 360 degrees which can be avoided by ensuring the
angle of rotation does not exceed 180 degrees, i.e. switching the direction of
the rotation when it is past 180 degrees.
Parameters:
mrp (array_like, shape (..., 3)) – A single vector or an ND array of vectors, where the last dimension
contains the rotation parameters.
Returns:
rotation – Object containing the rotations represented by input MRPs.
Return type:
Rotation instance
Notes
Added in version 1.6.0.
Array API Standard Support
from_mrp has experimental support for Python Array API Standard compatible
backends in addition to NumPy. Please consider testing these features
by setting an environment variable SCIPY_ARRAY_API=1 and providing
CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following
combinations of backend and device (or other capability) are supported.
Rotations in 3 dimensions can be represented using unit norm
quaternions [1]_.
The 4 components of a quaternion are divided into a scalar part w
and a vector part (x,y,z) and can be expressed from the angle
theta and the axis n of a rotation as follows:
There are 2 conventions to order the components in a quaternion:
scalar-first order – (w,x,y,z)
scalar-last order – (x,y,z,w)
The choice is controlled by scalar_first argument.
By default, it is False and the scalar-last order is assumed.
Advanced users may be interested in the “double cover” of 3D space by
the quaternion representation [2]_. As of version 1.11.0, the
following subset (and only this subset) of operations on a Rotation
r corresponding to a quaternion q are guaranteed to preserve
the double cover property: r=Rotation.from_quat(q),
r.as_quat(canonical=False), r.inv(), and composition using the
* operator such as r*r.
Parameters:
quat (array_like, shape (..., 4)) – Each row is a (possibly non-unit norm) quaternion representing an
active rotation. Each quaternion will be normalized to unit norm.
scalar_first (bool, optional) – Whether the scalar component goes first or last.
Default is False, i.e. the scalar-last order is assumed.
Returns:
rotation – Object containing the rotations represented by input quaternions.
Return type:
Rotation instance
Notes
Array API Standard Support
from_quat has experimental support for Python Array API Standard compatible
backends in addition to NumPy. Please consider testing these features
by setting an environment variable SCIPY_ARRAY_API=1 and providing
CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following
combinations of backend and device (or other capability) are supported.
Library
CPU
GPU
NumPy
✅
n/a
CuPy
n/a
✅
PyTorch
✅
✅
JAX
✅
✅
Dask
⛔
n/a
See dev-arrayapi for more information.
References
Examples
>>> fromscipy.spatial.transformimportRotationasR
A rotation can be initialized from a quaternion with the scalar-last
(default) or scalar-first component order as shown below:
A rotation vector is a 3 dimensional vector which is co-directional to
the axis of rotation and whose norm gives the angle of rotation [1]_.
Parameters:
rotvec (array_like, shape (..., 3)) – A single vector or an ND array of vectors, where the last dimension
contains the rotation vectors.
degrees (bool, optional) –
If True, then the given magnitudes are assumed to be in degrees.
Default is False.
Added in version 1.7.0.
Returns:
rotation – Object containing the rotations represented by input rotation
vectors.
Return type:
Rotation instance
Notes
Array API Standard Support
from_rotvec has experimental support for Python Array API Standard compatible
backends in addition to NumPy. Please consider testing these features
by setting an environment variable SCIPY_ARRAY_API=1 and providing
CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following
combinations of backend and device (or other capability) are supported.
If rng is passed by keyword, types other than numpy.random.Generator are
passed to numpy.random.default_rng to instantiate a Generator.
If rng is already a Generator instance, then the provided instance is
used. Specify rng for repeatable function behavior.
If this argument is passed by position or random_state is passed by keyword,
legacy behavior for the argument random_state applies:
If random_state is None (or numpy.random), the numpy.random.RandomState
singleton is used.
If random_state is an int, a new RandomState instance is used,
seeded with random_state.
If random_state is already a Generator or RandomState instance then
that instance is used.
Changed in version 1.15.0: As part of the SPEC-007
transition from use of numpy.random.RandomState to
numpy.random.Generator, this keyword was changed from random_state to rng.
For an interim period, both keywords will continue to work, although only one
may be specified at a time. After the interim period, function calls using the
random_state keyword will emit warnings. The behavior of both random_state and
rng are outlined above, but only the rng keyword should be used in new code.
shape (tuple of ints, optional) – Shape of random rotations to generate. If specified, num must be None.
Returns:
random_rotation – Contains a single rotation if num is None. Otherwise contains a
stack of num rotations.
Return type:
Rotation instance
See also
scipy.stats.special_ortho_group()
Notes
This function is optimized for efficiently sampling random rotation
matrices in three dimensions. For generating random rotation matrices
in higher dimensions, see scipy.stats.special_ortho_group.
Examples
>>> fromscipy.spatial.transformimportRotationasR
Sample a single rotation:
>>> R.random().as_euler('zxy',degrees=True)array([-110.5976185 , 55.32758512, 76.3289269 ]) # random
If the original frame rotates to the final frame by this rotation, then
its application to a vector can be seen in two ways:
As a projection of vector components expressed in the final frame
to the original frame.
As the physical rotation of a vector being glued to the original
frame as it rotates. In this case the vector components are
expressed in the original frame before and after the rotation.
In terms of rotation matrices, this application is the same as
self.as_matrix()@vectors.
Parameters:
vectors (array_like, shape (..., 3)) – Each vectors[…, :] represents a vector in 3D space. The shape of
rotations and shape of vectors given must follow standard numpy
broadcasting rules: either one of them equals unity or they both
equal each other.
inverse (boolean, optional) – If True then the inverse of the rotation(s) is applied to the input
vectors. Default is False.
Returns:
rotated_vectors – Result of applying rotation on input vectors.
Shape is determined according to numpy broadcasting rules. I.e., the result
will have the shape np.broadcast_shapes(r.shape, v.shape[:-1]) + (3,)
apply has experimental support for Python Array API Standard compatible
backends in addition to NumPy. Please consider testing these features
by setting an environment variable SCIPY_ARRAY_API=1 and providing
CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following
combinations of backend and device (or other capability) are supported.
Determine if another rotation is approximately equal to this one.
Equality is measured by calculating the smallest angle between the
rotations, and checking to see if it is smaller than atol.
Parameters:
other (Rotation instance) – Object containing the rotations to measure against this one.
atol (float, optional) – The absolute angular tolerance, below which the rotations are
considered equal. If not given, then set to 1e-8 radians by
default.
degrees (bool, optional) – If True and atol is given, then atol is measured in degrees. If
False (default), then atol is measured in radians.
Returns:
approx_equal – Whether the rotations are approximately equal, bool if object
contains a single rotation and ndarray if object contains multiple
rotations.
Return type:
ndarray or bool
Notes
Array API Standard Support
approx_equal has experimental support for Python Array API Standard compatible
backends in addition to NumPy. Please consider testing these features
by setting an environment variable SCIPY_ARRAY_API=1 and providing
CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following
combinations of backend and device (or other capability) are supported.
Any orientation can be expressed as a composition of 3 elementary
rotations.
For both Euler angles and Davenport angles, consecutive axes must
be are orthogonal (axis2 is orthogonal to both axis1 and
axis3). For Euler angles, there is an additional relationship
between axis1 or axis3, with two possibilities:
axis1 and axis3 are also orthogonal (asymmetric sequence)
axis1==axis3 (symmetric sequence)
For Davenport angles, this last relationship is relaxed [1]_, and only
the consecutive orthogonal axes requirement is maintained.
A slightly modified version of the algorithm from [2]_ has been used to
calculate Davenport angles for the rotation about a given sequence of
axes.
Davenport angles, just like Euler angles, suffer from the problem of
gimbal lock [3]_, where the representation loses a degree of freedom
and it is not possible to determine the first and third angles
uniquely. In this case, a warning is raised (unless the
suppress_warnings option is used), and the third angle is set
to zero. Note however that the returned angles still represent the
correct rotation.
Parameters:
axes (array_like, shape (..., [1 or 2 or 3], 3) or (..., 3)) – Axis of rotation, if one dimensional. If N dimensional, describes the
sequence of axes for rotations, where each axes[…, i, :] is the ith
axis. If more than one axis is given, then the second axis must be
orthogonal to both the first and third axes.
order (string) – If it belongs to the set {‘e’, ‘extrinsic’}, the sequence will be
extrinsic. If it belongs to the set {‘i’, ‘intrinsic’}, sequence
will be treated as intrinsic.
degrees (boolean, optional) – Returned angles are in degrees if this flag is True, else they are
in radians. Default is False.
suppress_warnings (boolean, optional) – Disable warnings about gimbal lock. Default is False.
Returns:
angles – Shape depends on shape of inputs used to initialize object.
The returned angles are in the range:
First angle belongs to [-180, 180] degrees (both inclusive)
Third angle belongs to [-180, 180] degrees (both inclusive)
Second angle belongs to a set of size 180 degrees,
given by: [-abs(lambda),180-abs(lambda)], where lambda
is the angle between the first and third axes.
as_davenport has experimental support for Python Array API Standard compatible
backends in addition to NumPy. Please consider testing these features
by setting an environment variable SCIPY_ARRAY_API=1 and providing
CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following
combinations of backend and device (or other capability) are supported.
Any orientation can be expressed as a composition of 3 elementary
rotations. Once the axis sequence has been chosen, Euler angles define
the angle of rotation around each respective axis [1]_.
The algorithm from [2]_ has been used to calculate Euler angles for the
rotation about a given sequence of axes.
Euler angles suffer from the problem of gimbal lock [3]_, where the
representation loses a degree of freedom and it is not possible to
determine the first and third angles uniquely. In this case,
a warning is raised (unless the suppress_warnings option is used),
and the third angle is set to zero. Note however that the returned
angles still represent the correct rotation.
Parameters:
seq (string, length 3) – 3 characters belonging to the set {‘X’, ‘Y’, ‘Z’} for intrinsic
rotations, or {‘x’, ‘y’, ‘z’} for extrinsic rotations [1]_.
Adjacent axes cannot be the same.
Extrinsic and intrinsic rotations cannot be mixed in one function
call.
degrees (boolean, optional) – Returned angles are in degrees if this flag is True, else they are
in radians. Default is False.
suppress_warnings (boolean, optional) – Disable warnings about gimbal lock. Default is False.
Returns:
angles – Shape depends on shape of inputs used to initialize object.
The returned angles are in the range:
First angle belongs to [-180, 180] degrees (both inclusive)
Third angle belongs to [-180, 180] degrees (both inclusive)
Second angle belongs to:
[-90, 90] degrees if all axes are different (like xyz)
[0, 180] degrees if first and third axes are the same
(like zxz)
as_euler has experimental support for Python Array API Standard compatible
backends in addition to NumPy. Please consider testing these features
by setting an environment variable SCIPY_ARRAY_API=1 and providing
CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following
combinations of backend and device (or other capability) are supported.
as_matrix has experimental support for Python Array API Standard compatible
backends in addition to NumPy. Please consider testing these features
by setting an environment variable SCIPY_ARRAY_API=1 and providing
CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following
combinations of backend and device (or other capability) are supported.
Represent as Modified Rodrigues Parameters (MRPs).
MRPs are a 3 dimensional vector co-directional to the axis of rotation and whose
magnitude is equal to tan(theta/4), where theta is the angle of
rotation (in radians) [1]_.
MRPs have a singularity at 360 degrees which can be avoided by ensuring the
angle of rotation does not exceed 180 degrees, i.e. switching the direction of
the rotation when it is past 180 degrees. This function will always return MRPs
corresponding to a rotation of less than or equal to 180 degrees.
Returns:
mrps – Shape depends on shape of inputs used for initialization.
as_mrp has experimental support for Python Array API Standard compatible
backends in addition to NumPy. Please consider testing these features
by setting an environment variable SCIPY_ARRAY_API=1 and providing
CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following
combinations of backend and device (or other capability) are supported.
Rotations in 3 dimensions can be represented using unit norm
quaternions [1]_.
The 4 components of a quaternion are divided into a scalar part w
and a vector part (x,y,z) and can be expressed from the angle
theta and the axis n of a rotation as follows:
There are 2 conventions to order the components in a quaternion:
scalar-first order – (w,x,y,z)
scalar-last order – (x,y,z,w)
The choice is controlled by scalar_first argument.
By default, it is False and the scalar-last order is used.
The mapping from quaternions to rotations is
two-to-one, i.e. quaternions q and -q, where -q simply
reverses the sign of each component, represent the same spatial
rotation.
Parameters:
canonical (bool, default False) – Whether to map the redundant double cover of rotation space to a
unique “canonical” single cover. If True, then the quaternion is
chosen from {q, -q} such that the w term is positive. If the w term
is 0, then the quaternion is chosen such that the first nonzero
term of the x, y, and z terms is positive.
scalar_first (bool, optional) – Whether the scalar component goes first or last.
Default is False, i.e. the scalar-last order is used.
Returns:
quat – Shape depends on shape of inputs used for initialization.
Return type:
numpy.ndarray, shape (…, 4)
Notes
Array API Standard Support
as_quat has experimental support for Python Array API Standard compatible
backends in addition to NumPy. Please consider testing these features
by setting an environment variable SCIPY_ARRAY_API=1 and providing
CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following
combinations of backend and device (or other capability) are supported.
The resulting shape of the quaternion is always the shape of the Rotation
object with an added last dimension of size 4. E.g. when the Rotation object
contains an N-dimensional array (N, M, K) of rotations, the result will be a
4-dimensional array:
as_rotvec has experimental support for Python Array API Standard compatible
backends in addition to NumPy. Please consider testing these features
by setting an environment variable SCIPY_ARRAY_API=1 and providing
CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following
combinations of backend and device (or other capability) are supported.
Composition of a rotation with its inverse results in an identity
transformation.
Returns:
inverse – Object containing inverse of the rotations in the current instance.
Return type:
Rotation instance
Notes
Array API Standard Support
inv has experimental support for Python Array API Standard compatible
backends in addition to NumPy. Please consider testing these features
by setting an environment variable SCIPY_ARRAY_API=1 and providing
CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following
combinations of backend and device (or other capability) are supported.
magnitude – Angle(s) in radians, float if object contains a single rotation
and ndarray if object contains ND rotations. The magnitude
will always be in the range [0, pi].
Return type:
ndarray or float
Notes
Array API Standard Support
magnitude has experimental support for Python Array API Standard compatible
backends in addition to NumPy. Please consider testing these features
by setting an environment variable SCIPY_ARRAY_API=1 and providing
CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following
combinations of backend and device (or other capability) are supported.
The mean used is the chordal L2 mean (also called the projected or
induced arithmetic mean) [1]_. If A is a set of rotation matrices,
then the mean M is the rotation matrix that minimizes the
following loss function:
where \(w_i\)’s are the weights corresponding to each matrix.
Parameters:
weights (array_like shape (..., N), optional) – Weights describing the relative importance of the rotations. If
None (default), then all values in weights are assumed to be
equal. If given, the shape of weights must be broadcastable to
the rotation shape. Weights must be non-negative.
axis (None, int, or tuple of ints, optional) – Axis or axes along which the means are computed. The default is to
compute the mean of all rotations.
Returns:
mean – Single rotation containing the mean of the rotations in the
current instance.
Return type:
Rotation instance
Notes
Array API Standard Support
mean has experimental support for Python Array API Standard compatible
backends in addition to NumPy. Please consider testing these features
by setting an environment variable SCIPY_ARRAY_API=1 and providing
CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following
combinations of backend and device (or other capability) are supported.
Reduce this rotation with the provided rotation groups.
Reduction of a rotation p is a transformation of the form
q=l*p*r, where l and r are chosen from left and
right respectively, such that rotation q has the smallest
magnitude.
If left and right are rotation groups representing symmetries of
two objects rotated by p, then q is the rotation of the
smallest magnitude to align these objects considering their symmetries.
Parameters:
left (Rotation instance, optional) – Object containing the left rotation(s). Default value (None)
corresponds to the identity rotation.
right (Rotation instance, optional) – Object containing the right rotation(s). Default value (None)
corresponds to the identity rotation.
return_indices (bool, optional) – Whether to return the indices of the rotations from left and
right used for reduction.
left_best, right_best (integer ndarray) – Indices of elements from left and right used for reduction.
Notes
Array API Standard Support
reduce has experimental support for Python Array API Standard compatible
backends in addition to NumPy. Please consider testing these features
by setting an environment variable SCIPY_ARRAY_API=1 and providing
CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following
combinations of backend and device (or other capability) are supported.
A sequence of time-tagged rotations, enabling interpolation between them.
Uses scipy.spatial.transform.Slerp for interpolation.
Parameters:
rot (Rotation | list of Rotation) – A scipy Rotation object containing multiple rotations, or a list of such objects.
If a list is provided, all elements must be scipy Rotation objects.
time (Time) – A Time object with time instances corresponding to each rotation.
Must be the same length as the number of rotations and strictly increasing.
backend (BackendArg, optional) – Array backend to use (numpy, jax, etc.). Defaults to numpy.
>>> interp_rot=rot_seq.interp(... Time.from_datetime(datetime(2021,1,1,12,30,0,tzinfo=timezone.utc))... )# Interpolate to halfway between first and second rotation>>> interp_rot.as_euler(... "xyz",degrees=True... )# Get interpolated rotation as Euler anglesarray([[45., 0., 0.]])
Velocity vector(s) in ECEF coordinates (vx, vy, vz) in m/s.
Associated with a Time object for the time instances of the velocities.
Internal use only, typically created from Path objects.
No data validation is performed.
Parameters:
vec (Array) – Velocity vectors in ECEF coordinates (vx, vy, vz) in m/s. Shape (n, 3).
time (Time) – Time object associated with the velocities. Length must match number of velocity vectors.
backend (BackendArg, optional) – Array backend to use (numpy, jax, etc.). Defaults to numpy.
_xp (Any)
Examples
Velocity objects are typically created from Path objects.