Skip to main content

Quaternion

Class for quaternion calculations in python.

Installation

Download from pypi using pip install karlternion

Example of use

To rotate a vector around and axis

>>> import numpy as np
>>> from karlternion import Quaternion
>>> # Make a rotation around [0, 0, 1] by 45 degree.
>>> q = Quaternion.from_axis_rotation(np.array([0, 0, 1]), np.deg2rad(45))
>>> v = np.array([1, 1, 0]) # Vector to rotate.
>>> q * v # Rotate vector.
array([0.0,  1.41421356e,  0.0])

To make a sequence of rotations, quaternions can be multiplied. Consider a system where you have two rotation axes. The first is Omega, which rotates around [0, 0, 1]. Then another axis, kappa, is mounted on the omega stage (i.e., when omega rotates, so will the kappa axis). When omega is at its origin, the kappa axis is [1, 1, 1].

>>> import numpy as np
>>> from karlternion import Quaternion
>>> omega = Quaternion.from_axis_rotation(np.array([0, 0, 1]), np.deg2rad(20))
>>> kappa = Quaternion.from_axis_rotation(np.array([1, 1, 1]), np.deg2rad(30))
>>> v = np.array([1, 0, 0])
>>> kappa * omega * v
array([ 0.77230395,  0.62470301, -0.1152942 ])

Can also convert to Euler angles,

>>> np.rad2deg((kappa * omega).to_euler())
array([23.53771943,  6.62059431, 38.96878306])

and rotation matrix,

>>> (kappa * omega).to_rotation_matrix()
array([[ 0.77230395, -0.54077305,  0.33333333],
       [ 0.62470301,  0.74175595, -0.24401694],
       [-0.1152942 ,  0.39668958,  0.9106836 ]])

Furthermore, it is also possible to do spherical interpolation, either between two quaternions (Quaternion.slerp) or two vectors.

>>> v1 = np.array([0, 0, 1])
>>> v2 = np.array([0, 1, 0])
>>> Quaternion.slerp_vector(v1, v2, 0.5)
array([0.        , 0.70710678, 0.70710678])

Metadata

Release files for karlternion 1.0.8

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

Source distribution (sdist)

Source distribution for karlternion 1.0.8
File Size Uploaded Provenance Actions
karlternion-1.0.8.tar.gz 7.2 kB Without provenance Details for karlternion-1.0.8.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for karlternion 1.0.8
File Interpreter ABI Platform Actions
karlternion-1.0.8-py3-none-any.whl Python 3 none any Details for karlternion-1.0.8-py3-none-any.whl

Total release size: 16.8 kB

Release files / karlternion-1.0.8.tar.gz

Download URL karlternion-1.0.8.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
7c34df1783ae98b1bfbe8704c590927a5d4d655f871003b097d8f272df9cf7c1
BLAKE2b-256 checksum
How to use checksums
4cfab5a90db371b242dc43ed9b667f3df75d60ddcf6d810b513064fb5e32e663
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / karlternion-1.0.8-py3-none-any.whl

Download URL karlternion-1.0.8-py3-none-any.whl
Size 9.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3d390a8c0b0950a8c88b253f25e84c3bd675021296bf0b17ff9965745160a3bb
BLAKE2b-256 checksum
How to use checksums
1cb63da7486e4ac4ab297d03015169a63df7a7b39ef9be44aa09715aaeaa4e7c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Security for karlternion 1.0.8

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.0.8 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