https://github.com/risteon/tf_quat2rot
:triangular_ruler: Numerically stable conversion between quaternion and rotation matrices in tensorflow.
https://github.com/risteon/tf_quat2rot
hacktoberfest quaternion-calculation quaternions rotation-matrices tensorflow tensorflow2
Last synced: about 1 month ago
JSON representation
:triangular_ruler: Numerically stable conversion between quaternion and rotation matrices in tensorflow.
- Host: GitHub
- URL: https://github.com/risteon/tf_quat2rot
- Owner: risteon
- License: mit
- Created: 2019-06-14T20:33:36.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2020-10-04T14:08:04.000Z (over 5 years ago)
- Last Synced: 2025-09-04T06:40:05.178Z (10 months ago)
- Topics: hacktoberfest, quaternion-calculation, quaternions, rotation-matrices, tensorflow, tensorflow2
- Language: Python
- Homepage:
- Size: 26.4 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tf_quat2rot
[](https://travis-ci.org/risteon/tf_quat2rot)
[](https://pypi.org/project/tf-quat2rot/)
[](https://pypi.org/project/tf-quat2rot/)
Convert between quaternion and rotation matrices in tensorflow.
Implements the method from Soheil Sarabandi and Federico Thomas to compute rotation matrices
from quaternions.
This method is numerically stable.
Written in pure tensorflow.
## Installation
Python Versions from 3.5+ are supported. Install from PyPi with `pip install tf_quat2rot`.
`tf_quat2rot` requires TensorFlow (versions 1.x and 2.x work). If you want it to be installed when installing `tf_quat2rot` choose between the CPU and GPU version with `pip install tf_quat2rot[tf-cpu]` or `pip install tf_quat2rot[tf-gpu]` respectively.
## Definitions and sample usage
Quaternions are defined as `w-x-y-z`. `w` is defined as positive. Usage is straightforward:
```python3
>>> import tensorflow as tf
>>> if int(tf.__version__.split('.')[0]) < 2:
>>> tf.enable_eager_execution()
>>> from tf_quat2rot import quaternion_to_rotation_matrix, rotation_matrix_to_quaternion
>>> r = quaternion_to_rotation_matrix(tf.constant([1.0, 0.0, 0.0, 0.0]))
>>> print(r)
tf.Tensor(
[[1. 0. 0.]
[0. 1. 0.]
[0. 0. 1.]], shape=(3, 3), dtype=float32)
>>> q = rotation_matrix_to_quaternion(tf.eye(3))
>>> print(q)
tf.Tensor([ 1. -0. -0. -0.], shape=(4,), dtype=float32)
```
Quaternion and rotation matrix tensors can hold arbitrary leading dimensions which will
be preserved.
Use `random_uniform_quaternion` to generate quaternions uniformly from SO(3).
## References
Sarabandi, S., & Thomas, F. (2019). Accurate Computation of Quaternions from Rotation Matrices.
Advances in Robot Kinematics 2018, 39–46. https://doi.org/10.1007/978-3-319-93188-3_5
Steven M LaValle. Generating a random element of SO(3). http://planning.cs.uiuc.edu/node198.html