Skip to main content

yet another library for quaternions

Project description

pyquatlib

Just another library for quaternions. With focus on usability.

Installation

Assuming you use pip to manage your python installation, you can install this package simply as

pip install pyquatlib

In order to install a virtual environment, change to the code directory, and run

make init

Basic usage

The full documentation can be generated with

make docs

The following are mostly for the purposes of example.

There are several ways to create a Quaternion:

>>> from quaternions import Quaternion
>>> import numpy as np

>>> Quaternion(np.array([1, -2, 3]))
Quaternion: ((0, array([ 1, -2,  3])))
>>> Quaternion((0, np.array([1, 2, 3])))
Quaternion: ((0, array([1, 2, 3])))

Left and right operations with compatible data structures are supported.

>>> data = np.full((4,3), [1,2,3])
>>> data
array([[1, 2, 3],
       [1, 2, 3],
       [1, 2, 3],
       [1, 2, 3]])

>>> data - Quaternion([2, 1, 1, 1])
[Quaternion: ((-2, array([0, 1, 2]))),
 Quaternion: ((-2, array([0, 1, 2]))),
 Quaternion: ((-2, array([0, 1, 2]))),
 Quaternion: ((-2, array([0, 1, 2])))]

>>>  Quaternion([1, 0 , -1, 0]) + data
[Quaternion: ((1, array([1, 1, 3]))),
 Quaternion: ((1, array([1, 1, 3]))),
 Quaternion: ((1, array([1, 1, 3]))),
 Quaternion: ((1, array([1, 1, 3])))]

>>> data * Quaternion(np.array([1, 2, 3, 4]))
[Quaternion: ((-20, array([0, 4, 2]))),
 Quaternion: ((-20, array([0, 4, 2]))),
 Quaternion: ((-20, array([0, 4, 2]))),
 Quaternion: ((-20, array([0, 4, 2])))]

>>> Quaternion([0, 1 , -1, -1]) / data
[Quaternion: ((-0.2857142857142857, array([ 0.07142857,  0.28571429, -0.21428571]))),
 Quaternion: ((-0.2857142857142857, array([ 0.07142857,  0.28571429, -0.21428571]))),
 Quaternion: ((-0.2857142857142857, array([ 0.07142857,  0.28571429, -0.21428571]))),
 Quaternion: ((-0.2857142857142857, array([ 0.07142857,  0.28571429, -0.21428571])))]

Several conversion functions from compatible data structures are also included. For example, to convert an (n,3) array to a list of Quaternions, use to_quaternion:

>>> vectors = np.random.rand(100, 3)
>>> vectors
array([[0.02219696, 0.61847575, 0.68714365],
       [0.56104393, 0.3529833 , 0.8188565 ],
       ...
       [0.38190174, 0.59151826, 0.37396559]])

>>> Quaternion.to_quaternion(vectors)
[Quaternion: ((0.0, array([0.02219696, 0.61847575, 0.68714365]))),
 Quaternion: ((0.0, array([0.56104393, 0.3529833 , 0.8188565 ]))),
 Quaternion: ((0.0, array([0.84834741, 0.02304604, 0.33619428]))),
 ...
 Quaternion: ((0.0, array([0.38190174, 0.59151826, 0.37396559])))]

Bug reports and feature requests

Bug reports and feature requests are entirely welcome. The best way to do this is to open an issue on this code's github page. For bug reports, please try to include a minimal working example demonstrating the problem.

Pull requests are also entirely welcome, of course, if you have an idea where the code is going wrong, or have an idea for a new feature that you know how to implement.

This code is routinely tested on recent versions of Python 3.* Test coverage is quite complete.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyquatlib-1.0.0.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyquatlib-1.0.0-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file pyquatlib-1.0.0.tar.gz.

File metadata

  • Download URL: pyquatlib-1.0.0.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.3

File hashes

Hashes for pyquatlib-1.0.0.tar.gz
Algorithm Hash digest
SHA256 454a03e56afa37e560a77c92812c5bf94c39a176382c72f01fa6348c75bda011
MD5 9a1336a4a8a9e255765d44bd869e0a35
BLAKE2b-256 f5aefa5a700a34c5551dee301aae92bb076897ade95a8dd3a3a0b6dc550b8b78

See more details on using hashes here.

File details

Details for the file pyquatlib-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pyquatlib-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.3

File hashes

Hashes for pyquatlib-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bebae58c7dfe876cbe52da514b6a18007759c58e3f55bc8e9c76e7d669faf341
MD5 a10ded4284fccfb9f2183d89cc5bfff0
BLAKE2b-256 d98e018b09638ef1c326a22799d982cf67dc0e0c1b8d601833df2435da1091d2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page