A set of functions to manipulate quaternions.
Project description
Python Quaternions (quatpy)
A lightweight Python package for handling quaternions. This package provides efficient tools for working with quaternions, including conversions between different rotation representations (Euler angles, rotation matrices) and common quaternion operations.
Quick Examples
1. Basic Quaternion Operations
pip install https://github.com/jchar32/quaternions.git
or
pip install quatpy
Verify installation:
import quaternions
print(quaternions.__version__)
import numpy as np
from quaternions import normalize, product
# Create two quaternions (scalar-first format)
q1 = np.array([1, 0, 1, 0]) # [w, x, y, z]
q2 = np.array([0, 1, 0, 1])
# Normalize and multiply quaternions
q1_norm = normalize(q1)
q2_norm = normalize(q2)
result = product(q1_norm, q2_norm)
2. Rotating Vectors
from quaternions import from_angles, quat_rotate
# Create rotation quaternion from Euler angles (in radians)
angles = np.array([np.pi/4, 0, 0]) # 45° rotation around x-axis
q = from_angles(angles)
# Rotate a vector
vector = np.array([0, 0, 1])
rotated_vector = quat_rotate(q, vector)
3. Converting Between Representations
from quaternions import from_rotmat, to_angles
# Create rotation matrix
R = np.array([[0, -1, 0],
[1, 0, 0],
[0, 0, 1]])
# Convert to quaternion and then to Euler angles
q = from_rotmat(R)
euler_angles = to_angles(q, order='xyz')
print(f"Euler angles (degrees): {np.degrees(euler_angles)}")
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file quatpy-2025.1.1.tar.gz.
File metadata
- Download URL: quatpy-2025.1.1.tar.gz
- Upload date:
- Size: 80.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
412a2dc8b1f08fa7bbf4c341c86bf6f826330b1b49e30efe56de4915c031db73
|
|
| MD5 |
873ca26f05b24810fcb2dbd9cd2d522f
|
|
| BLAKE2b-256 |
642a090633e8b2dff6c768250642a85e1ae422a9809d2d32dd84199f9bb4dc59
|
File details
Details for the file quatpy-2025.1.1-py3-none-any.whl.
File metadata
- Download URL: quatpy-2025.1.1-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
055cda24e652c2f9159328cc95f69cb42fc96829a3e04c7add62903c1f13ead0
|
|
| MD5 |
96da2b345a8bc0a95fc711f6b7096d2d
|
|
| BLAKE2b-256 |
f696d9e5c1db3cd6ae90983e4985d5c7ebceaf60f88a3bcf87270c9ef73eb543
|