Skip to main content

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)

Release files for mgen 1.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mgen 1.2.1
File Size Uploaded
mgen-1.2.1.tar.gz 14.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mgen 1.2.1
File Interpreter ABI Platform
mgen-1.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 22.4 kB

Release files / mgen-1.2.1.tar.gz

Download URL mgen-1.2.1.tar.gz
Size 14.3 kB
Tags Source
SHA-256 checksum
How to use checksums
3caa56fc85ee71250cc55f484832af52d48c0cb84c945e1a32859b458a85ab39
BLAKE2b-256 checksum
How to use checksums
70fcbfc86ce96aab74cb61ed26b8242897a2b87c88dddca673e75c229d2511a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.3

Release files / mgen-1.2.1-py3-none-any.whl

Download URL mgen-1.2.1-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3aff2ae91c2317b94fd9ea3993078f20593414fce80e56d68497b039d9555823
BLAKE2b-256 checksum
How to use checksums
02986c4071d3589dcdf0d70c884b66b806ce7d24b57fddfe46a488660e8a35c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.3

Release history Release notifications | RSS feed

This release

1.2.1 This release

2 release files

1.2.0

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page