Skip to main content

Python package for computations of rotations in 3D-space.

Reason this release was yanked:

Import error

Project description

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])

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

karlternion-1.0.9.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

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

karlternion-1.0.9-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file karlternion-1.0.9.tar.gz.

File metadata

  • Download URL: karlternion-1.0.9.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for karlternion-1.0.9.tar.gz
Algorithm Hash digest
SHA256 ab6615467f80daf2911625cb648ef52b228bd9b45e9de00120095328555fefa3
MD5 e6e132dc1b207ec36a943311001bfe30
BLAKE2b-256 57bf9268d2dcbc37aae82c1a1210ca5e33764a4f3615d4bf169c10fcd6d9c31c

See more details on using hashes here.

File details

Details for the file karlternion-1.0.9-py3-none-any.whl.

File metadata

  • Download URL: karlternion-1.0.9-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for karlternion-1.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 e16afccc8ad127774df72dba6e2fdb09e45e71abce7d37516389e7c65776a9b5
MD5 529d5f924fc6d263fc219b3705a20d23
BLAKE2b-256 da7b1b75744e9296234ee7b6edf977ea91486ed66c8a6a9abc983f52079fdbce

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