Class and mathematical functions for quaternion numbers.

Overview

Quaternions

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 pow 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)
You might also like...
A calculator to test numbers against the collatz conjecture

The Collatz Calculator This is an algorithm custom built by Kyle Dickey, used to test numbers against the simple rules of the Collatz Conjecture.

A check numbers python module

Made with Python3 (C) @FayasNoushad Copyright permission under MIT License License - https://github.com/FayasNoushad/Numbers/blob/main/LICENSE Deplo

A numbers check python package

A numbers check python package

A numbers extract from string python package

Made with Python3 (C) @FayasNoushad Copyright permission under MIT License License - https://github.com/FayasNoushad/Numbers-Extract/blob/main/LICENS

Validate UC alumni identifier numbers with Python 3.

UC number validator Validate UC alumni identifier numbers with Python 3. Getting started Install the library with: pip install -U ucnumber Usage from

A python library what works with numbers.

pynum A python library what works with numbers. Prime Prime class have everithing you want about prime numbers. check_prime The check_prime method is

My sister is a GR of her class. She had to mark attendance of students from screenshots of teams meeting on an excel sheet. I resolved her problem by reading names from screenshots using PyTesseract and marking them present on the excel using Pandas in Python. It took me 1hr to write the code and it is saving half an hour everyday.
MiniJVM is simple java virtual machine written by python language, it can load class file from file system and run it.

MiniJVM MiniJVM是一款使用python编写的简易JVM,能够从本地加载class文件并且执行绝大多数指令。 支持的功能 1.从本地磁盘加载class并解析 2.支持绝大多数指令集的执行 3.支持虚拟机内存分区以及对象的创建 4.支持方法的调用和参数传递 5.支持静态代码块的初始化 不支

Python meta class and abstract method library with restrictions.

abcmeta Python meta class and abstract method library with restrictions. This library provides a restricted way to validate abstract methods. The Pyth

Releases(1.1.3)
  • 1.1.3(Jul 23, 2022)

    Quaternions v1.1.3 Release

    Install

    You can install the module with pip:

    pip install quaternions-for-python
    

    If you have a previous version installed, upgrade to the latest version:

    pip install --upgrade quaternions-for-python
    
    Source code(tar.gz)
    Source code(zip)
  • v1.1.1(May 5, 2022)

    Quaternions v1.1.1 Release

    Install

    You can install the module with pip:

    pip install quaternions-for-python
    

    If you have a previous version installed, upgrade to the latest version:

    pip install --upgrade quaternions-for-python
    

    What's new

    • A Read the Docs site for Quaternions is now live! Read through the documentation here: https://quaternions-for-python.readthedocs.io/
    • Added comments to source code to explain functions and algorithms.
    • Rewrote some code to be more efficient/readable.
    • Reformatted/fixed typos in docstrings.
    • Miscellaneous changes.
    Source code(tar.gz)
    Source code(zip)
  • v1.1.0(Aug 20, 2021)

    Quaternions v1.1.0 Release

    What's new

    • qmath.rotate_Euler function that allows yaw, pitch, and roll rotations.
    • qmath has cross_product and dot_product functions which use quaternions on the backend to calculate vector products.
    • Quaternion class has properties angle_in_radians and angle_in_degrees.

    Bug fixes

    • Fixed bug in the qmath.log function where a variable was called without assignment.
    • Removed NotImplemented from magic methods where they were used inappropriately.

    Docstring changes

    Docstrings are being changed for Sphinx compatibilty. A ReadTheDocs page coming soon!

    Source code(tar.gz)
    Source code(zip)
  • v1.0.0(Aug 15, 2021)

Number calculator application.

Number calculator application.

Michael J Bailey 3 Oct 08, 2021
This repository contains all the data analytics projects that I've worked on in python.

93_Python_Data_Analytics_Projects This repository contains all the data analytics projects that I've worked on in python. No. Name 01 001_Cervical_Can

Milaan Parmar / Милан пармар / _米兰 帕尔马 267 Jan 06, 2023
A cookiecutter to start a Python package with flawless practices and a magical workflow 🧙🏼‍♂️

PyPackage Cookiecutter This repository is a cookiecutter to quickly start a Python package. It contains a ton of very useful features 🐳 : Package man

Daniel Leal 16 Dec 13, 2021
Whole-day timezone comparison

Timezone Converter Compare a full day of your local timezone with foreign ones $ timezone-converter tijuana --zone $ timezone-converter tijuana new_yo

Iago Alonso 12 Nov 24, 2022
This is a repository built by the community for the community.

Nutshell Machine Learning Machines can see, hear and learn. Welcome to the future 🌍 The repository was built with a tree-like structure in mind, it c

Edem Gold 82 Nov 18, 2022
Repo created for the purpose of adding any kind of programs and projects

Programs and Project Repository A repository for adding programs and projects of any kind starting from beginners level to expert ones Contributing to

Unicorn Dev Community 3 Nov 02, 2022
Simple script to match riders with drivers.

theBestPooler Simple script to match riders with drivers. It's a greedy, unoptimised search, so no guarantees that it works. It just seems to work (ve

Devansh 1 Nov 22, 2021
1st Online Python Editor With Live Syntax Checking and Execution

PythonBuddy 🖊️ 🐍 Online Python 3 Programming with Live Pylint Syntax Checking! Usage Fetch from repo: git clone https://github.com/ethanchewy/Python

Ethan Chiu 255 Dec 23, 2022
Project Interface For nextcord-ext

Project Interface For nextcord-ext

nextcord-ext 1 Nov 13, 2021
Telegram bot to search quotes from brainyquote.com

Brainy Quote Bot @BrainQuoteBot A star ⭐ from you means a lot to us! Telegram bot to search quotes from brainyquote.com Usage Deploy to Heroku Tap on

21 Nov 24, 2022
Sync SiYuanNote & Yuque.

SiyuanYuque Sync SiYuanNote & Yuque. Install Use pip to install. pip install SiyuanYuque Execute like this: python -m SiyuanYuque Remember to create a

Clouder 23 Nov 25, 2022
A web-based analysis toolkit for the System Usability Scale providing calculation, plotting, interpretation and contextualization utility

System Usability Scale Analysis Toolkit The System Usability Scale (SUS) Analysis Toolkit is a web-based python application that provides a compilatio

Jonas Blattgerste 3 Oct 27, 2022
python DroneCAN code generation, interface and utilities

UAVCAN v0 stack in Python Python implementation of the UAVCAN v0 protocol stack. UAVCAN is a lightweight protocol designed for reliable communication

DroneCAN 11 Dec 12, 2022
NExT-Ford-aula4 - NExT Ford aula4

Questão 1: vocês deveram fazer o passo a passo de como ficará as pilhas(Stack) e

Gerson 1 Jan 06, 2022
Coderslab Workshop Projects

Workshop Coderslab workshop projects that include: Guessing Game Lotto simulator Guessing Game vol.2 Guessing Game vol.3 Dice 2001 Game Technologies P

Szymon Połczyński 1 Nov 06, 2021
Sudoku-Solver

Sudoku-Solver This is a personal project, that put all my today knowledges to the test, is a project that im developing alone with a lot of effort and

Carlos Ismael Gitto Bernales 5 Nov 08, 2021
A small Blender addon for changing an object's local orientation while in edit mode

A small Blender addon for changing an object's local orientation while in edit mode.

Jonathan Lampel 50 Jan 06, 2023
This is a a CSMA/CA simulator written in Python based on simulator of the same type

This is a a CSMA/CA simulator written in Python based on simulator of the same type found the link https://github.com/StevenSLXie/CSMA-Simulator with

M. Ismail 4 Nov 22, 2022
Display your data in an attractive way in your notebook!

Bloxs Bloxs is a simple python package that helps you display information in an attractive way (formed in blocks). Perfect for building dashboards, re

MLJAR 192 Dec 28, 2022
Protocol Buffers for the Rest of Us

Protocol Buffers for the Rest of Us Motivation protoletariat has one goal: fixing the broken imports for the Python code generated by protoc. Usage He

Phillip Cloud 76 Jan 04, 2023