numpy-quaternion

2024.0.13 · active · verified Sat Apr 11

numpy-quaternion extends NumPy by adding a quaternion dtype, enabling efficient array operations and mathematical functions for handling quaternions. This library is crucial for applications involving 3D rotations, such as animation, robotics, and aerospace. It is actively maintained with frequent releases, with the current version being 2024.0.13.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a quaternion, represent a 3D point as a pure-imaginary quaternion, and apply a rotation using quaternion multiplication.

import numpy as np
import quaternion

# Create a quaternion
q_rot = np.quaternion(0.92388, 0, 0.38268, 0) # Example: 45-degree rotation around Y-axis

# Represent a 3D point as a pure-imaginary quaternion
point = np.quaternion(0, 1, 0, 0) # Represents point (1, 0, 0)

# Rotate the point using quaternion multiplication
rotated_point = q_rot * point * q_rot.conjugate()

print(f"Original point: ({point.x}, {point.y}, {point.z})")
print(f"Rotation quaternion: {q_rot}")
print(f"Rotated point: ({rotated_point.x:.3f}, {rotated_point.y:.3f}, {rotated_point.z:.3f})")

view raw JSON →