Giter Club home page Giter Club logo

mgen's Introduction

test coverage Documentation Status pypi PyPI - Python Version license codacy

MGen: Convenient matrix generation functions

Python and its most popular packages do not offer out-of-the-box convenient functions to generate rotation matrices. While there are other projects that offer rotation and vector classes, or offer rotations via the use of quaternions, if you simply want a rotation matrix, for example if other packages require them as an input, or you do not wish to change your current data structure to use special rotation classes, the common suggestion is to implement them yourself (see for example this discussion on SE: https://stackoverflow.com/questions/6802577/rotation-of-3d-vector). However, everybody implementing their own version of the same thing can hardly be seen as ideal.

Therefore, this package provides simple functions to generate rotation matrices in 2d for a given angle or in 3d for a given axis and angle, or for three given angles (proper Euler angles or Tait-Bryan angles).

Additionally, n-dimensional rotations can be generated using an angle and two orthogonal vectors that span the plane of rotation.

Trivial example usage

Below you see examples of how to use mgen to generate rotation matrices. For further documentation please have a look here: https://mgen.readthedocs.io

import numpy as np
np.set_printoptions(suppress=True)

from mgen import rotation_around_axis
from mgen import rotation_from_angles
from mgen import rotation_around_x
from mgen import rotation_from_angle_and_plane
from mgen import rotation_from_angle
from mgen import random_matrix

# 2D example
matrix = rotation_from_angle(np.pi/2)
matrix.dot([1, 0])
# array([0., 1.])

#3D examples
matrix = rotation_from_angles([np.pi/2, 0, 0], 'XYX')
matrix.dot([0, 1, 0])
# array([0., 0., 1.])

matrix = rotation_around_axis([1, 0, 0], np.pi/2)
matrix.dot([0, 1, 0])
# array([0., 0., 1.])

matrix = rotation_around_x(np.pi/2)
matrix.dot([0, 1, 0])
# array([0., 0., 1.])

# n-dimensional example
matrix = rotation_from_angle_and_plane(np.pi/2, (0, 1, 0, 0), (0, 0, 1, 0))
matrix.dot([0, 1, 0, 0])
# array([0., 0., 1., 0.])

# n-dimensional random matrix O(n), e.g. n=27
matrix = random_matrix(27)

mgen's People

Contributors

beneit avatar nohs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

mgen's Issues

nD rotation around axis

I don't know the application, but it could also be useful to generalize the function rotation_around_axis to nD.

Maybe there is a cleverer way, but it would be at least possible by creating two orthogonal vectors to a given axis and using the existing rotation_from_angle_and_plane with those vectors.

Also a side note:
in the docs in

(3D) Give an angle and a base axis around which to rotate (x, y, z)

I would call it "euclidean coordinate axis" or simply "euclidean axis"

More general nD rotations

The docs say (stress is mine)

(nD) Give an angle and a pair of orthogonal vectors that span a plane

It seems to me that, since orthogonality is checked anyways, the nD vectors could be orthogonalized if necessary. This would generalize the function rotation_from_angle_and_plane a little. The remaining requirement would be that the two vectors not be parallel.

Improve documentation and readme

The documentation currently does not properly use syntax highlighting for the code examples. Furthermore, the readme could be structured a bit clearer.

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.