Quaternion
beignet.apply_quaternion
apply_quaternion(input, rotation, inverse=False)
Rotates vectors in three-dimensional space using rotation quaternions.
Note
This function interprets the rotation of the original frame to the final frame as either a projection, where it maps the components of vectors from the final frame to the original frame, or as a physical rotation, integrating the vectors into the original frame during the rotation process. Consequently, the vector components are maintained in the original frame’s perspective both before and after the rotation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input
|
(Tensor, shape(..., 3))
|
Each vector represents a vector in three-dimensional space. The number of rotation quaternions and number of vectors must follow standard broadcasting rules: either one of them equals unity or they both equal each other. |
required |
rotation
|
(Tensor, shape(..., 4))
|
Rotation quaternions. Rotation quaternions are normalized to unit norm. |
required |
inverse
|
bool
|
If |
False
|
Returns:
Name | Type | Description |
---|---|---|
output |
(Tensor, shape(..., 3))
|
Rotated vectors. |
Source code in src/beignet/_apply_quaternion.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
|
beignet.compose_quaternion
compose_quaternion(input, other, canonical=False)
Compose rotation quaternions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input
|
Tensor, shape=(..., 4)
|
Rotation quaternions. Rotation quaternions are normalized to unit norm. |
required |
other
|
Tensor, shape=(..., 4)
|
Rotation quaternions. Rotation quaternions are normalized to unit norm. |
required |
canonical
|
bool
|
Whether to map the redundant double cover of rotation space to a unique
canonical single cover. If |
False
|
Returns:
Name | Type | Description |
---|---|---|
output |
Tensor, shape=(..., 4)
|
Composed rotation quaternions. |
Source code in src/beignet/_compose_quaternion.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
|
beignet.invert_quaternion
invert_quaternion(input, canonical=False)
Invert rotation quaternions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input
|
(Tensor, shape(..., 4))
|
Rotation quaternions. Rotation quaternions are normalized to unit norm. |
required |
canonical
|
bool
|
Whether to map the redundant double cover of rotation space to a unique
canonical single cover. If |
False
|
Returns:
Name | Type | Description |
---|---|---|
inverted_quaternions |
(Tensor, shape(..., 4))
|
Inverted rotation quaternions. |
Source code in src/beignet/_invert_quaternion.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
beignet.quaternion_identity
quaternion_identity(size, canonical=False, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False)
Identity rotation quaternions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
size
|
int
|
Output size. |
required |
canonical
|
bool
|
Whether to map the redundant double cover of rotation space to a unique
canonical single cover. If |
False
|
out
|
Tensor
|
Output tensor. Default, |
None
|
dtype
|
dtype
|
Type of the returned tensor. Default, global default. |
None
|
layout
|
layout
|
Layout of the returned tensor. Default, |
strided
|
device
|
device
|
Device of the returned tensor. Default, current device for the default tensor type. |
None
|
requires_grad
|
bool
|
Whether autograd records operations on the returned tensor. Default,
|
False
|
Returns:
Name | Type | Description |
---|---|---|
identity_quaternions |
(Tensor, shape(size, 4))
|
Identity rotation quaternions. |
Source code in src/beignet/_quaternion_identity.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
|
beignet.quaternion_magnitude
quaternion_magnitude(input, canonical=False)
Rotation quaternion magnitudes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input
|
Tensor, shape=(..., 4)
|
Rotation quaternions. |
required |
Returns:
Name | Type | Description |
---|---|---|
output |
Tensor, shape=(...)
|
Angles in radians. Magnitudes will be in the range :math: |
Source code in src/beignet/_quaternion_magnitude.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|
beignet.quaternion_mean
quaternion_mean(input, weight=None)
Mean rotation quaternions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input
|
Tensor, shape=(..., 4)
|
Rotation quaternions. Rotation quaternions are normalized to unit norm. |
required |
weight
|
Tensor, shape=(..., 4)
|
Relative importance of rotation quaternions. |
None
|
Returns:
Name | Type | Description |
---|---|---|
output |
Tensor, shape=(..., 4)
|
Rotation quaternions mean. |
Source code in src/beignet/_quaternion_mean.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
|
beignet.quaternion_slerp
quaternion_slerp(input, time, rotation)
Interpolate between two or more points on a sphere.
Unlike linear interpolation, which can result in changes in speed when interpolating between orientations or positions on a sphere, spherical linear interpolation ensures that the interpolation occurs at a constant rate and follows the shortest path on the surface of the sphere. The process is useful for rotations and orientation interpolation in three-dimensional spaces, smoothly transitioning between different orientations.
Mathematically, spherical linear interpolation interpolates between two points on a sphere using a parameter \(t\), where \(t = 0\) represents the start point and \(t = n\) represents the end point. For two rotation quaternions \(q_{1}\) and \(q_{2}\) representing the start and end orientations:
where \(\theta\) is the angle between \(q_{1}\) and \(q_{2}\), and is computed using the dot product of \(q_{1}\) and \(q_{2}\). This formula ensures that the interpolation moves along the shortest path on the four-dimensional sphere of rotation quaternions, resulting in a smooth and constant-speed rotation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input
|
(Tensor, shape(..., N))
|
Times. |
required |
time
|
(Tensor, shape(..., N))
|
Times of the known rotations. At least 2 times must be specified. |
required |
rotation
|
(Tensor, shape(..., N, 4))
|
Rotation quaternions. Rotation quaternions are normalized to unit norm. |
required |
Source code in src/beignet/_quaternion_slerp.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
|
beignet.quaternion_to_euler_angle
quaternion_to_euler_angle(input, axes, degrees=False)
Convert rotation quaternions to Euler angles.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input
|
Tensor, shape=(..., 4)
|
Rotation quaternions. Rotation quaternions are normalized to unit norm. |
required |
axes
|
str
|
Axes. 1-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. |
required |
degrees
|
bool
|
If |
False
|
Returns:
Name | Type | Description |
---|---|---|
output |
Tensor, shape=(..., 3)
|
Euler angles. The returned Euler angles are in the range:
|
Source code in src/beignet/_quaternion_to_euler_angle.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
|
beignet.quaternion_to_rotation_matrix
quaternion_to_rotation_matrix(input)
Convert rotation quaternions to rotation matrices.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input
|
Tensor, shape=(..., 4)
|
Rotation quaternions. Rotation quaternions are normalized to unit norm. |
required |
Returns:
Name | Type | Description |
---|---|---|
output |
Tensor, shape=(..., 3, 3)
|
Rotation matrices. |
Source code in src/beignet/_quaternion_to_rotation_matrix.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
|
beignet.quaternion_to_rotation_vector
quaternion_to_rotation_vector(input, degrees=False)
Convert rotation quaternions to rotation vectors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input
|
Tensor, shape=(..., 4)
|
Rotation quaternions. Rotation quaternions are normalized to unit norm. |
required |
degrees
|
bool
|
|
False
|
Returns:
Name | Type | Description |
---|---|---|
output |
Tensor, shape=(..., 3)
|
Rotation vectors. |
Source code in src/beignet/_quaternion_to_rotation_vector.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
beignet.random_quaternion
random_quaternion(size, canonical=False, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False)
Generate random rotation quaternions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
size
|
int
|
Output size. |
required |
canonical
|
bool
|
Whether to map the redundant double cover of rotation space to a unique
canonical single cover. If |
False
|
generator
|
Generator
|
Psuedo-random number generator. Default, |
None
|
out
|
Tensor
|
Output tensor. Default, |
None
|
dtype
|
dtype
|
Type of the returned tensor. Default, global default. |
None
|
layout
|
layout
|
Layout of the returned tensor. Default, |
strided
|
device
|
device
|
Device of the returned tensor. Default, current device for the default tensor type. |
None
|
requires_grad
|
bool
|
Whether autograd records operations on the returned tensor. Default,
|
False
|
pin_memory
|
bool
|
If |
False
|
Returns:
Name | Type | Description |
---|---|---|
random_quaternions |
(Tensor, shape(..., 4))
|
Random rotation quaternions. |
Source code in src/beignet/_random_quaternion.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
|