Skip to main content
Yanked

This release has been yanked by its maintainers, and will be ignored by installers, except when explicitly specified.
Reason given by maintainers: Wrong name

Quaternions

Documentation Status

Class and mathematical functions for quaternion numbers.

Installation

Python

This is a Python 3 module. If you don’t have Python installed, get the latest version here.

The Quaternions module

Install with pip:

pip install quaternions-for-python

If you want to build from source, you can clone the repository with the following terminal command:

git clone https://github.com/zachartrand/Quaternions.git

How to use

Using the quaternions module

The quaternions module is designed to be imported to use quaternion numbers just like complex numbers in Python. The rest of this file assumes you import the class like this:

>>> from quaternions import Quaternion

To create a quaternion, simply type

>>> Quaternion(a, b, c, d)

where a, b, c, and d correspond to a quaternion of the form a + bi + cj + dk. For example, creating the quaternion 1 - 2i - 3j + 4k looks like this in the Python interpreter:

>>> q1 = Quaternion(1, -2, -3, 4)
>>> q1
Quaternion(1.0, -2.0, -3.0, 4.0)
>>> print(q1)
(1 - 2i - 3j + 4k)

Quaternions have mathematical functionality built in. Adding or multipling two quaternions together uses the same syntax as ints and floats:

>>> q1, q2 = Quaternion(1, -2, -3, 4), Quaternion(1, 4, -3, -2)
>>> print(q1)
(1 - 2i - 3j + 4k)
>>> print(q2)
(1 + 4i - 3j - 2k)
>>> print(q1+q2)
(2 + 2i - 6j + 2k)
>>> print(q1-q2)
(-6i + 0j + 6k)
>>> print(q2-q1)
(6i + 0j - 6k)
>>> print(q1*q2)
(8 + 20i + 6j + 20k)
>>> print(q2*q1)
(8 - 16i - 18j - 16k)
>>> print(q1/q2)
(-0.19999999999999996 - 0.8i - 0.4j - 0.4k)
>>> print(1/q2 * q1)
(-0.19999999999999996 + 0.4i + 0.4j + 0.8k)
>>> print(q2/q1)
(-0.19999999999999996 + 0.8i + 0.4j + 0.4k)

Check the documentation for other useful methods of the Quaternion class.

Using the qmath module

The qmath module contains some functions that are compatible with quaternions, similarly to how the cmath module works. These include the exponential function, the natural logarithm, and the square root function. It also includes a function, rotate3d(), that takes an iterable of coordinates and rotates them a given angle around a given axis (the z-axis by default). Here is an example rotating the point (1, 0, 0) around the z-axis:

>>> from quaternions import qmath
>>>
>>> p = (1, 0, 0)
>>>
>>> p = qmath.rotate3d(p, 90); print(p)
(0.0, 1.0, 0.0)
>>> p = qmath.rotate3d(p, 90); print(p)
(-1.0, 0.0, 0.0)
>>> p = qmath.rotate3d(p, 90); print(p)
(0.0, -1.0, 0.0)
>>> p = qmath.rotate3d(p, 90); print(p)
(1.0, 0.0, 0.0)

Metadata

Release files for quaternions-for-python-zachartrand 1.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for quaternions-for-python-zachartrand 1.1.2
File Size Uploaded Provenance Actions
quaternions-for-python_zachartrand-1.1.2.tar.gz 16.4 kB Without provenance Details for quaternions-for-python_zachartrand-1.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for quaternions-for-python-zachartrand 1.1.2
File Interpreter ABI Platform Actions
quaternions_for_python_zachartrand-1.1.2-py3-none-any.whl Python 3 none any Details for quaternions_for_python_zachartrand-1.1.2-py3-none-any.whl

Total release size: 32.4 kB

Release files / quaternions-for-python_zachartrand-1.1.2.tar.gz

Download URL quaternions-for-python_zachartrand-1.1.2.tar.gz
Size 16.4 kB
Tags Source
SHA-256 checksum
How to use checksums
04f15250ce395a67fd7016f51f466ab65024f5b6bc14cb8e39529bfebec46164
BLAKE2b-256 checksum
How to use checksums
eca5dd11ef3176a95e19cdd873be529b53a4ddfa4802848aa1368a0069c82469
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.5

Release files / quaternions_for_python_zachartrand-1.1.2-py3-none-any.whl

Download URL quaternions_for_python_zachartrand-1.1.2-py3-none-any.whl
Size 15.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6a25e56ecb3a319dad5e0fef324f76bbfa28ab4b6d77efd8c6147cbfbffa5f58
BLAKE2b-256 checksum
How to use checksums
0d19cdb6f2cc1ef32ea163c12ea2e9716414a6d1ac5d4a03691359639ea24d55
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.5

Security for quaternions-for-python-zachartrand 1.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.1.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page