-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
75 changed files
with
4,446 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
repos: | ||
- hooks: | ||
- id: "check-toml" | ||
- id: "check-yaml" | ||
repo: "https://github.com/pre-commit/pre-commit-hooks" | ||
rev: "v4.5.0" | ||
- hooks: | ||
- args: | ||
- "--fix" | ||
id: "ruff" | ||
- id: "ruff-format" | ||
repo: "https://github.com/astral-sh/ruff-pre-commit" | ||
rev: "v0.3.5" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from torch import Tensor | ||
|
||
from ._apply_rotation_matrix import apply_rotation_matrix | ||
from ._euler_angle_to_rotation_matrix import euler_angle_to_rotation_matrix | ||
|
||
|
||
def apply_euler_angle( | ||
input: Tensor, | ||
rotation: Tensor, | ||
axes: str, | ||
degrees: bool = False, | ||
inverse: bool = False, | ||
) -> Tensor: | ||
r""" | ||
Rotates vectors in three-dimensional space using Euler angles. | ||
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 | ||
---------- | ||
input : Tensor | ||
Vectors in three-dimensional space with the shape $(\ldots \times 3)$. | ||
Euler angles and vectors must conform to PyTorch broadcasting rules. | ||
rotation : Tensor | ||
Euler angles with the shape $(\ldots \times 3)$, specifying the | ||
rotation in three-dimensional space. | ||
axes : str | ||
Specifies the sequence of axes for the rotations, using one to three | ||
characters from the set ${X, Y, Z}$ for intrinsic rotations, or | ||
${x, y, z}$ for extrinsic rotations. Mixing extrinsic and intrinsic | ||
rotations raises a `ValueError`. | ||
degrees : bool, optional | ||
Indicates whether the Euler angles are provided in degrees. If `False`, | ||
angles are assumed to be in radians. Default, `False`. | ||
inverse : bool, optional | ||
If `True`, applies the inverse rotation using the Euler angles to the | ||
input vectors. Default, `False`. | ||
Returns | ||
------- | ||
rotated_vectors : Tensor | ||
A tensor of the same shape as `input`, containing the rotated vectors. | ||
""" | ||
return apply_rotation_matrix( | ||
input, | ||
euler_angle_to_rotation_matrix( | ||
rotation, | ||
axes, | ||
degrees, | ||
), | ||
inverse, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import torch | ||
from torch import Tensor | ||
|
||
|
||
def apply_rotation_matrix( | ||
input: Tensor, | ||
rotation: Tensor, | ||
inverse: bool | None = False, | ||
) -> Tensor: | ||
r""" | ||
Rotates vectors in three-dimensional space using rotation matrices. | ||
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 | ||
---------- | ||
input : Tensor, shape (..., 3) | ||
Each vector represents a vector in three-dimensional space. The number | ||
of rotation matrices and number of vectors must follow standard | ||
broadcasting rules: either one of them equals unity or they both equal | ||
each other. | ||
rotation : Tensor, shape (..., 3, 3) | ||
Rotation matrices. | ||
inverse : bool, optional | ||
If `True` the inverse of the rotation matrices are applied to the input | ||
vectors. Default, `False`. | ||
Returns | ||
------- | ||
rotated_vectors : Tensor, shape (..., 3) | ||
Rotated vectors. | ||
""" | ||
if inverse: | ||
return torch.einsum("ikj, ik -> ij", rotation, input) | ||
|
||
return torch.einsum("ijk, ik -> ij", rotation, input) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import torch | ||
from torch import Tensor | ||
|
||
from ._rotation_quaternion_to_rotation_matrix import ( | ||
rotation_quaternion_to_rotation_matrix, | ||
) | ||
|
||
|
||
def apply_rotation_quaternion( | ||
input: Tensor, | ||
rotation: Tensor, | ||
inverse: bool | None = False, | ||
) -> Tensor: | ||
r""" | ||
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 | ||
---------- | ||
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. | ||
rotation : Tensor, shape (..., 4) | ||
Rotation quaternions. Rotation quaternions are normalized to unit norm. | ||
inverse : bool, optional | ||
If `True` the inverse of the rotation quaternions are applied to the | ||
input vectors. Default, `False`. | ||
Returns | ||
------- | ||
output : Tensor, shape (..., 3) | ||
Rotated vectors. | ||
""" | ||
if inverse: | ||
output = torch.einsum( | ||
"ikj, ik -> ij", | ||
rotation_quaternion_to_rotation_matrix( | ||
rotation, | ||
), | ||
input, | ||
) | ||
else: | ||
output = torch.einsum( | ||
"ijk, ik -> ij", | ||
rotation_quaternion_to_rotation_matrix( | ||
rotation, | ||
), | ||
input, | ||
) | ||
|
||
return output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from torch import Tensor | ||
|
||
from ._apply_rotation_matrix import apply_rotation_matrix | ||
from ._rotation_vector_to_rotation_matrix import ( | ||
rotation_vector_to_rotation_matrix, | ||
) | ||
|
||
|
||
def apply_rotation_vector( | ||
input: Tensor, | ||
rotation: Tensor, | ||
degrees: bool | None = False, | ||
inverse: bool | None = False, | ||
) -> Tensor: | ||
r""" | ||
Rotates vectors in three-dimensional space using rotation vectors. | ||
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 | ||
---------- | ||
input : Tensor, shape (..., 3) | ||
Each vector represents a vector in three-dimensional space. The number | ||
of rotation vectors and number of vectors must follow standard | ||
broadcasting rules: either one of them equals unity or they both equal | ||
each other. | ||
rotation : Tensor, shape (..., 4) | ||
Rotation vectors. | ||
degrees : bool, optional | ||
If `True`, rotation vector magnitudes are assumed to be in degrees. | ||
Default, `False`. | ||
inverse : bool, optional | ||
If `True` the inverse of the rotation vectors are applied to the input | ||
vectors. Default, `False`. | ||
Returns | ||
------- | ||
rotated_vectors : Tensor, shape (..., 3) | ||
Rotated vectors. | ||
""" | ||
return apply_rotation_matrix( | ||
input, | ||
rotation_vector_to_rotation_matrix( | ||
rotation, | ||
degrees, | ||
), | ||
inverse, | ||
) |
Oops, something went wrong.