Giter VIP home page Giter VIP logo

aquaternion's Introduction

aquaternion

This package includes classes that can be used for calculating 3-dimensional translation and rotation using Quaternion algebra.

Installation

Clone this repository and run the following command:

python setup.py install

How to use

Creating a quaternion:

from aquaternion import *

Q([0, 1, 2, 3])
# The four numbers correspond to the w, x, y, and z components respectively.

# Creating a quaternion with only three numbers will assign the values to the x, y, and z (imaginary) components,
# and leave w with the default value of 0
Q([1, 2, 3])

How to perform calculations:

q1 = Q([-7, 2, 9])
q2 = Q([4, -1, -5])

print(q1 + q2)
print(q1 * q2)
print(Q([0, 3, 4]).norm)

Output:

(0.000 -3.000i +1.000j +4.000k)
(75.000 -1.000i +1.000j -1.000k)
5.0

Linear Algebra

The morphed method is equivalent to replacing the unit vectors of a Quaternion. The unmorphed method is the inverse of morphed. Thus:

q = Q([1, 2, 3])

# This coordinate system is rotated tau/3 radians around the Q([1, 1, 1]) axis, compared to the standard i, j, k unit vectors.
new_unit_vectors = UnitVectors([qj, qk, qi])

# This will be equal to Q([3, 1, 2])
q_prime = q.morphed(*new_unit_vectors)

# This will create an unmorphed q_prime, and will be equal to q, Q([1, 2, 3])
original_q = q_prime.unmorphed(*new_unit_vectors)

morph/unmorph/rotate/normalize will change an instance whereas morphed/unmorphed/rotated/normalized will create a new one.

aquaternion's People

Contributors

anton083 avatar periareion avatar

Stargazers

 avatar Ioannis avatar

Watchers

 avatar Forbidden Forge avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.