This is a library for dealing with quaternions in Python in a unified way.
Project description
Quaternions library
===================
This is a library for dealing with quaternions in python in a unified way.
To install it:
```bash
$ pip install satellogic_quaternions
```
Examples of code:
```python
In [1]: from quaternions import Quaternion
In [2]: q1 = Quaternion(1, 2, 3, 4)
In [3]: q2 = Quaternion(2, 3, 5, 8)
In [4]: q1 + q2
Out[4]: Quaternion(3, 5, 8, 12)
In [5]: q1 * q2
Out[5]: Quaternion(-51, 3, 15, 15)
In [6]: q1 / q2
Out[6]: Quaternion(0.53921568627450989, 0.049019607843137247, -0.029411764705882353, 0.0098039215686274439)
In [7]: print(q1)
(1+2i+3j+4k)
```
~~Most of~~ all the quaternions we use are unitary (not like the example above)
```python
In [8]: q1.is_unitary()
Out[8]: False
In [9]: q1 / q1.norm()
Out[9]: Quaternion(0.18257418583505536, 0.36514837167011072, 0.54772255750516607, 0.73029674334022143)
In [10]: q1 /= q1.norm()
In [11]: q1.is_unitary()
Out[11]: True
```
Usually, quaternions are used for rotating vectors. This is done with `numpy`:
```python
In [12]: q1.matrix
Out[12]:
array([[-0.66666667, 0.66666667, 0.33333333],
[ 0.13333333, -0.33333333, 0.93333333],
[ 0.73333333, 0.66666667, 0.13333333]])
In [14]: q1.matrix.dot([2, 3, -4])
Out[14]: array([-0.66666667, -4.46666667, 2.93333333])
In [16]: q1.matrix.dot([1, 0, 0])
Out[16]: array([-0.66666667, 0.13333333, 0.73333333])
```
A unitary quaternion matrix is unitary. The inverse is the transpose and it is also the
matrix of the inverse quaternion. And the inverse quaternion of a unitary quaternion is
the conjugate:
```python
In [17]: q1.conjugate()
Out[17]: Quaternion(0.18257418583505536, -0.36514837167011072, -0.54772255750516607, -0.73029674334022143)
In [18]: q1
Out[18]: Quaternion(0.18257418583505536, 0.36514837167011072, 0.54772255750516607, 0.73029674334022143)
In [19]: q1 * q1.conjugate()
Out[19]: Quaternion(0.99999999999999978, 0.0, 0.0, 0.0)
In [20]: q1.conjugate().matrix
Out[20]:
array([[-0.66666667, 0.13333333, 0.73333333],
[ 0.66666667, -0.33333333, 0.66666667],
[ 0.33333333, 0.93333333, 0.13333333]])
```
License
=======
quaternions is Satellogic SA Copyright 2017. All our code is GPLv3 licensed.
===================
This is a library for dealing with quaternions in python in a unified way.
To install it:
```bash
$ pip install satellogic_quaternions
```
Examples of code:
```python
In [1]: from quaternions import Quaternion
In [2]: q1 = Quaternion(1, 2, 3, 4)
In [3]: q2 = Quaternion(2, 3, 5, 8)
In [4]: q1 + q2
Out[4]: Quaternion(3, 5, 8, 12)
In [5]: q1 * q2
Out[5]: Quaternion(-51, 3, 15, 15)
In [6]: q1 / q2
Out[6]: Quaternion(0.53921568627450989, 0.049019607843137247, -0.029411764705882353, 0.0098039215686274439)
In [7]: print(q1)
(1+2i+3j+4k)
```
~~Most of~~ all the quaternions we use are unitary (not like the example above)
```python
In [8]: q1.is_unitary()
Out[8]: False
In [9]: q1 / q1.norm()
Out[9]: Quaternion(0.18257418583505536, 0.36514837167011072, 0.54772255750516607, 0.73029674334022143)
In [10]: q1 /= q1.norm()
In [11]: q1.is_unitary()
Out[11]: True
```
Usually, quaternions are used for rotating vectors. This is done with `numpy`:
```python
In [12]: q1.matrix
Out[12]:
array([[-0.66666667, 0.66666667, 0.33333333],
[ 0.13333333, -0.33333333, 0.93333333],
[ 0.73333333, 0.66666667, 0.13333333]])
In [14]: q1.matrix.dot([2, 3, -4])
Out[14]: array([-0.66666667, -4.46666667, 2.93333333])
In [16]: q1.matrix.dot([1, 0, 0])
Out[16]: array([-0.66666667, 0.13333333, 0.73333333])
```
A unitary quaternion matrix is unitary. The inverse is the transpose and it is also the
matrix of the inverse quaternion. And the inverse quaternion of a unitary quaternion is
the conjugate:
```python
In [17]: q1.conjugate()
Out[17]: Quaternion(0.18257418583505536, -0.36514837167011072, -0.54772255750516607, -0.73029674334022143)
In [18]: q1
Out[18]: Quaternion(0.18257418583505536, 0.36514837167011072, 0.54772255750516607, 0.73029674334022143)
In [19]: q1 * q1.conjugate()
Out[19]: Quaternion(0.99999999999999978, 0.0, 0.0, 0.0)
In [20]: q1.conjugate().matrix
Out[20]:
array([[-0.66666667, 0.13333333, 0.73333333],
[ 0.66666667, -0.33333333, 0.66666667],
[ 0.33333333, 0.93333333, 0.13333333]])
```
License
=======
quaternions is Satellogic SA Copyright 2017. All our code is GPLv3 licensed.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for satellogic_quaternions-0.1.3.dev0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f525aa28cd88f1e90b4e8a7415d7e3072d3f49188d9a053764af0d0a7dd61c5 |
|
MD5 | c49505a812578cfae5252587d8dc09f1 |
|
BLAKE2b-256 | 10678a3dbb5d0b89e5d154805ee96a9b76bd406e91f30c9b3392354911ff546f |
Close
Hashes for satellogic_quaternions-0.1.3.dev0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd0bb88721424cc10375d9af66f0d20d8481c5b56413ec2c4c6236c194ad3558 |
|
MD5 | 54fe574673525e6ab67fa5252d343838 |
|
BLAKE2b-256 | 2e73364a9e642718619be4bb06db14c6cab62fa75685d376d11196438c39c463 |