Skip to main content

Homogeneous Transformation Matrices and Quaternions

Project description

Transformations is a Python library for calculating 4x4 matrices for translating, rotating, reflecting, scaling, shearing, projecting, orthogonalizing, and superimposing arrays of 3D homogeneous coordinates as well as for converting between rotation matrices, Euler angles, and quaternions. Also includes an Arcball control object and functions to decompose transformation matrices.

Author:

Christoph Gohlke

Organization:

Laboratory for Fluorescence Dynamics. University of California, Irvine

License:

3-clause BSD

Version:

2019.4.22

Requirements

Revisions

2019.4.22

Fix setup requirements.

2019.1.1

Update copyright year.

Notes

Transformations.py is no longer actively developed and has a few known issues and numerical instabilities. The module is mostly superseded by other modules for 3D transformations and quaternions:

The API is not stable yet and is expected to change between revisions.

Python 2.7 and 3.4 are deprecated.

This Python code is not optimized for speed. Refer to the transformations.c module for a faster implementation of some functions.

Documentation in HTML format can be generated with epydoc.

Matrices (M) can be inverted using numpy.linalg.inv(M), be concatenated using numpy.dot(M0, M1), or transform homogeneous coordinate arrays (v) using numpy.dot(M, v) for shape (4, *) column vectors, respectively numpy.dot(v, M.T) for shape (*, 4) row vectors (“array of points”).

This module follows the “column vectors on the right” and “row major storage” (C contiguous) conventions. The translation components are in the right column of the transformation matrix, i.e. M[:3, 3]. The transpose of the transformation matrices may have to be used to interface with other graphics systems, e.g. OpenGL’s glMultMatrixd(). See also [16].

Calculations are carried out with numpy.float64 precision.

Vector, point, quaternion, and matrix function arguments are expected to be “array like”, i.e. tuple, list, or numpy arrays.

Return types are numpy arrays unless specified otherwise.

Angles are in radians unless specified otherwise.

Quaternions w+ix+jy+kz are represented as [w, x, y, z].

A triple of Euler angles can be applied/interpreted in 24 ways, which can be specified using a 4 character string or encoded 4-tuple:

Axes 4-string: e.g. ‘sxyz’ or ‘ryxy’

  • first character : rotations are applied to ‘s’tatic or ‘r’otating frame

  • remaining characters : successive rotation axis ‘x’, ‘y’, or ‘z’

Axes 4-tuple: e.g. (0, 0, 0, 0) or (1, 1, 1, 1)

  • inner axis: code of axis (‘x’:0, ‘y’:1, ‘z’:2) of rightmost matrix.

  • parity : even (0) if inner axis ‘x’ is followed by ‘y’, ‘y’ is followed by ‘z’, or ‘z’ is followed by ‘x’. Otherwise odd (1).

  • repetition : first and last axis are same (1) or different (0).

  • frame : rotations are applied to static (0) or rotating (1) frame.

References

  1. Matrices and transformations. Ronald Goldman. In “Graphics Gems I”, pp 472-475. Morgan Kaufmann, 1990.

  2. More matrices and transformations: shear and pseudo-perspective. Ronald Goldman. In “Graphics Gems II”, pp 320-323. Morgan Kaufmann, 1991.

  3. Decomposing a matrix into simple transformations. Spencer Thomas. In “Graphics Gems II”, pp 320-323. Morgan Kaufmann, 1991.

  4. Recovering the data from the transformation matrix. Ronald Goldman. In “Graphics Gems II”, pp 324-331. Morgan Kaufmann, 1991.

  5. Euler angle conversion. Ken Shoemake. In “Graphics Gems IV”, pp 222-229. Morgan Kaufmann, 1994.

  6. Arcball rotation control. Ken Shoemake. In “Graphics Gems IV”, pp 175-192. Morgan Kaufmann, 1994.

  7. Representing attitude: Euler angles, unit quaternions, and rotation vectors. James Diebel. 2006.

  8. A discussion of the solution for the best rotation to relate two sets of vectors. W Kabsch. Acta Cryst. 1978. A34, 827-828.

  9. Closed-form solution of absolute orientation using unit quaternions. BKP Horn. J Opt Soc Am A. 1987. 4(4):629-642.

  10. Quaternions. Ken Shoemake. http://www.sfu.ca/~jwa3/cmpt461/files/quatut.pdf

  11. From quaternion to matrix and back. JMP van Waveren. 2005. http://www.intel.com/cd/ids/developer/asmo-na/eng/293748.htm

  12. Uniform random rotations. Ken Shoemake. In “Graphics Gems III”, pp 124-132. Morgan Kaufmann, 1992.

  13. Quaternion in molecular modeling. CFF Karney. J Mol Graph Mod, 25(5):595-604

  14. New method for extracting the quaternion from a rotation matrix. Itzhack Y Bar-Itzhack, J Guid Contr Dynam. 2000. 23(6): 1085-1087.

  15. Multiple View Geometry in Computer Vision. Hartley and Zissermann. Cambridge University Press; 2nd Ed. 2004. Chapter 4, Algorithm 4.7, p 130.

  16. Column Vectors vs. Row Vectors. http://steve.hollasch.net/cgindex/math/matrix/column-vec.html

Examples

>>> alpha, beta, gamma = 0.123, -1.234, 2.345
>>> origin, xaxis, yaxis, zaxis = [0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1]
>>> I = identity_matrix()
>>> Rx = rotation_matrix(alpha, xaxis)
>>> Ry = rotation_matrix(beta, yaxis)
>>> Rz = rotation_matrix(gamma, zaxis)
>>> R = concatenate_matrices(Rx, Ry, Rz)
>>> euler = euler_from_matrix(R, 'rxyz')
>>> numpy.allclose([alpha, beta, gamma], euler)
True
>>> Re = euler_matrix(alpha, beta, gamma, 'rxyz')
>>> is_same_transform(R, Re)
True
>>> al, be, ga = euler_from_matrix(Re, 'rxyz')
>>> is_same_transform(Re, euler_matrix(al, be, ga, 'rxyz'))
True
>>> qx = quaternion_about_axis(alpha, xaxis)
>>> qy = quaternion_about_axis(beta, yaxis)
>>> qz = quaternion_about_axis(gamma, zaxis)
>>> q = quaternion_multiply(qx, qy)
>>> q = quaternion_multiply(q, qz)
>>> Rq = quaternion_matrix(q)
>>> is_same_transform(R, Rq)
True
>>> S = scale_matrix(1.23, origin)
>>> T = translation_matrix([1, 2, 3])
>>> Z = shear_matrix(beta, xaxis, origin, zaxis)
>>> R = random_rotation_matrix(numpy.random.rand(3))
>>> M = concatenate_matrices(T, R, Z, S)
>>> scale, shear, angles, trans, persp = decompose_matrix(M)
>>> numpy.allclose(scale, 1.23)
True
>>> numpy.allclose(trans, [1, 2, 3])
True
>>> numpy.allclose(shear, [0, math.tan(beta), 0])
True
>>> is_same_transform(R, euler_matrix(axes='sxyz', *angles))
True
>>> M1 = compose_matrix(scale, shear, angles, trans, persp)
>>> is_same_transform(M, M1)
True
>>> v0, v1 = random_vector(3), random_vector(3)
>>> M = rotation_matrix(angle_between_vectors(v0, v1), vector_product(v0, v1))
>>> v2 = numpy.dot(v0, M[:3,:3].T)
>>> numpy.allclose(unit_vector(v1), unit_vector(v2))
True

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

transformations-2019.4.22.tar.gz (45.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

transformations-2019.4.22-cp38-cp38-win_amd64.whl (56.8 kB view details)

Uploaded CPython 3.8Windows x86-64

transformations-2019.4.22-cp38-cp38-win32.whl (51.2 kB view details)

Uploaded CPython 3.8Windows x86

transformations-2019.4.22-cp37-cp37m-win_amd64.whl (56.5 kB view details)

Uploaded CPython 3.7mWindows x86-64

transformations-2019.4.22-cp37-cp37m-win32.whl (50.9 kB view details)

Uploaded CPython 3.7mWindows x86

transformations-2019.4.22-cp36-cp36m-win_amd64.whl (56.0 kB view details)

Uploaded CPython 3.6mWindows x86-64

transformations-2019.4.22-cp36-cp36m-win32.whl (50.3 kB view details)

Uploaded CPython 3.6mWindows x86

transformations-2019.4.22-cp35-cp35m-win_amd64.whl (56.0 kB view details)

Uploaded CPython 3.5mWindows x86-64

transformations-2019.4.22-cp35-cp35m-win32.whl (50.3 kB view details)

Uploaded CPython 3.5mWindows x86

transformations-2019.4.22-cp27-cp27m-win_amd64.whl (54.0 kB view details)

Uploaded CPython 2.7mWindows x86-64

transformations-2019.4.22-cp27-cp27m-win32.whl (48.1 kB view details)

Uploaded CPython 2.7mWindows x86

File details

Details for the file transformations-2019.4.22.tar.gz.

File metadata

  • Download URL: transformations-2019.4.22.tar.gz
  • Upload date:
  • Size: 45.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for transformations-2019.4.22.tar.gz
Algorithm Hash digest
SHA256 032ea124e2f0ba99481f977b21e546f3444dffa17616b7be0dd7f4eb6e57ae27
MD5 0735d79249adab3a024d95fed95ec238
BLAKE2b-256 5c2cd8cdf93d6dd61e899500ad2798d5633eb4124eca42186aa92559323a1cd6

See more details on using hashes here.

File details

Details for the file transformations-2019.4.22-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: transformations-2019.4.22-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 56.8 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for transformations-2019.4.22-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 3595e9f012bb52a9503cd3dc2e898a89da67c0619680875af7a8cb5106d6941a
MD5 ac6e04e493879066eeaf343eb9884b9e
BLAKE2b-256 48026ef696f84034c36ab38ee8ebe775a3efbc9c3ed7df63a76924b921b0fec1

See more details on using hashes here.

File details

Details for the file transformations-2019.4.22-cp38-cp38-win32.whl.

File metadata

  • Download URL: transformations-2019.4.22-cp38-cp38-win32.whl
  • Upload date:
  • Size: 51.2 kB
  • Tags: CPython 3.8, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for transformations-2019.4.22-cp38-cp38-win32.whl
Algorithm Hash digest
SHA256 7f61ef29c7c2f080de7a61c8c2645817005cfd21d0423ea63f2b18e6e7f3f1c5
MD5 b96a12c0f8ed1e44b8917a014a035bc6
BLAKE2b-256 ec6dbc24c569e4bb756ca3530daad4b957f4e4b4b208fc0098a01b7b9f9d59ed

See more details on using hashes here.

File details

Details for the file transformations-2019.4.22-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: transformations-2019.4.22-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 56.5 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for transformations-2019.4.22-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 5677151ba88ada2a812f7781e2447115bf94db5a545f12ed611f545712635b5d
MD5 ad9c9974fe181d41f06128b839b29d52
BLAKE2b-256 3761e3e811258bcf298dedf78dfa53092aa6ce799d4b34fa127c4ebf516b352c

See more details on using hashes here.

File details

Details for the file transformations-2019.4.22-cp37-cp37m-win32.whl.

File metadata

  • Download URL: transformations-2019.4.22-cp37-cp37m-win32.whl
  • Upload date:
  • Size: 50.9 kB
  • Tags: CPython 3.7m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for transformations-2019.4.22-cp37-cp37m-win32.whl
Algorithm Hash digest
SHA256 30b2f99e74bc221c05c63b611f2e8d22ba7609fe2985c03bb9c9aced0c7d4c5b
MD5 20e54730570a6df7441ecc3c480c1816
BLAKE2b-256 c213ffe05f47acde5e27413ab05f6fa99e628429734394ceca76dc71b190281b

See more details on using hashes here.

File details

Details for the file transformations-2019.4.22-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: transformations-2019.4.22-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 56.0 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for transformations-2019.4.22-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 f608ddeedadd6181406c1982835bb4ae57ce382c97775db685f07f4297ce4b29
MD5 99fafe055ed2eeb131717f8ed9cb3be8
BLAKE2b-256 d42559eb190370a1197133683c8fd85584f4cda1ba49fa1db65feeb450972b26

See more details on using hashes here.

File details

Details for the file transformations-2019.4.22-cp36-cp36m-win32.whl.

File metadata

  • Download URL: transformations-2019.4.22-cp36-cp36m-win32.whl
  • Upload date:
  • Size: 50.3 kB
  • Tags: CPython 3.6m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for transformations-2019.4.22-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 8bdc0849b17d12c2a146128c6335e5c6e2e64edaa1a7251bb0aa430c04431c91
MD5 c16178a580db90995a2bbdd7674e1535
BLAKE2b-256 2e4bdcb1511dc329c258cedec77966a2087274a619f27fa6a011716a722923aa

See more details on using hashes here.

File details

Details for the file transformations-2019.4.22-cp35-cp35m-win_amd64.whl.

File metadata

  • Download URL: transformations-2019.4.22-cp35-cp35m-win_amd64.whl
  • Upload date:
  • Size: 56.0 kB
  • Tags: CPython 3.5m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for transformations-2019.4.22-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 0a2d63c6c15dfc956a0691f1988bcc435c543235b5bf54105a751689f8e42baf
MD5 930c342f0a6ddc7f44b4bac47a3172c8
BLAKE2b-256 ec27e93d46bc982144885829d6e62eb4ede63bdc72f43293ecc70255ce93e6c0

See more details on using hashes here.

File details

Details for the file transformations-2019.4.22-cp35-cp35m-win32.whl.

File metadata

  • Download URL: transformations-2019.4.22-cp35-cp35m-win32.whl
  • Upload date:
  • Size: 50.3 kB
  • Tags: CPython 3.5m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for transformations-2019.4.22-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 28d211c724d616330186802e6d569ec11b2cec254b59243ba21ddb060e7047fa
MD5 04308de50d1fd7b5f32dcd868e3ffa12
BLAKE2b-256 d74ef1a9b83195b86660b8d2fd16b8ed5209270f97a77c47d6d5d801b7ef30ff

See more details on using hashes here.

File details

Details for the file transformations-2019.4.22-cp27-cp27m-win_amd64.whl.

File metadata

  • Download URL: transformations-2019.4.22-cp27-cp27m-win_amd64.whl
  • Upload date:
  • Size: 54.0 kB
  • Tags: CPython 2.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for transformations-2019.4.22-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 0d89daec22e816aafbfb2a15df768bd88062ce1e0ea5e9e335b9088f9dfc75de
MD5 e804ee92640163e14310c736f7f086bc
BLAKE2b-256 8075b4db873f42b18cd811ca71f6d71a278600672aad6cdf4f65bc2fdeb5143c

See more details on using hashes here.

File details

Details for the file transformations-2019.4.22-cp27-cp27m-win32.whl.

File metadata

  • Download URL: transformations-2019.4.22-cp27-cp27m-win32.whl
  • Upload date:
  • Size: 48.1 kB
  • Tags: CPython 2.7m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for transformations-2019.4.22-cp27-cp27m-win32.whl
Algorithm Hash digest
SHA256 757c4fe2d279cf5cc7ea4c470e3b2ade637c57a481ce62f87709dde9ccb7ede6
MD5 b3c0ddc8985c5dd6b8c3f0569077891f
BLAKE2b-256 5ac0afb68453e961797c8459fc3624d2b4e4026a9b1c8d4aa640413f3bd11dd1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page