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.
The transformations library is no longer actively developed.
- Author:
- License:
BSD 3-Clause
- Version:
2024.5.24
Quickstart
Install the transformations package and all dependencies from the Python Package Index:
python -m pip install -U transformations
See Examples for using the programming interface.
Source code and support are available on GitHub.
Requirements
This revision was tested with the following requirements and dependencies (other versions may work):
Revisions
2024.5.24
Fix docstring examples not correctly rendered on GitHub.
2024.4.24
Support NumPy 2.
2024.1.6
Remove support for Python 3.8 and numpy 1.22 (NEP 29).
2022.9.26
Add dimension check on superimposition_matrix (#2).
2022.8.26
Update metadata
Remove support for Python 3.7 (NEP 29).
2021.6.6
Remove support for Python 3.6 (NEP 29).
2020.1.1
Remove support for Python 2.7 and 3.5.
2019.4.22
Fix setup requirements.
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:
Transforms3d (includes most code of this module)
The API is not stable yet and is expected to change between revisions.
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, -1) column vectors, respectively numpy.dot(v, M.T) for shape (-1, 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
Matrices and transformations. Ronald Goldman. In “Graphics Gems I”, pp 472-475. Morgan Kaufmann, 1990.
More matrices and transformations: shear and pseudo-perspective. Ronald Goldman. In “Graphics Gems II”, pp 320-323. Morgan Kaufmann, 1991.
Decomposing a matrix into simple transformations. Spencer Thomas. In “Graphics Gems II”, pp 320-323. Morgan Kaufmann, 1991.
Recovering the data from the transformation matrix. Ronald Goldman. In “Graphics Gems II”, pp 324-331. Morgan Kaufmann, 1991.
Euler angle conversion. Ken Shoemake. In “Graphics Gems IV”, pp 222-229. Morgan Kaufmann, 1994.
Arcball rotation control. Ken Shoemake. In “Graphics Gems IV”, pp 175-192. Morgan Kaufmann, 1994.
Representing attitude: Euler angles, unit quaternions, and rotation vectors. James Diebel. 2006.
A discussion of the solution for the best rotation to relate two sets of vectors. W Kabsch. Acta Cryst. 1978. A34, 827-828.
Closed-form solution of absolute orientation using unit quaternions. BKP Horn. J Opt Soc Am A. 1987. 4(4):629-642.
Quaternions. Ken Shoemake. http://www.sfu.ca/~jwa3/cmpt461/files/quatut.pdf
From quaternion to matrix and back. JMP van Waveren. 2005. http://www.intel.com/cd/ids/developer/asmo-na/eng/293748.htm
Uniform random rotations. Ken Shoemake. In “Graphics Gems III”, pp 124-132. Morgan Kaufmann, 1992.
Quaternion in molecular modeling. CFF Karney. J Mol Graph Mod, 25(5):595-604
New method for extracting the quaternion from a rotation matrix. Itzhack Y Bar-Itzhack, J Guid Contr Dynam. 2000. 23(6): 1085-1087.
Multiple View Geometry in Computer Vision. Hartley and Zissermann. Cambridge University Press; 2nd Ed. 2004. Chapter 4, Algorithm 4.7, p 130.
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for transformations-2024.5.24.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 960328ce2f5e1dad8025b1b82c8588afbc57644c609899c5b9508af965cd7bc0 |
|
MD5 | 4c5350c7a495faf117ca7e88075f3193 |
|
BLAKE2b-256 | f3bd13cf3d21afdd64ed3f6dcdf0d0a70329549c5fb8759a634a35e27905b74a |
Hashes for transformations-2024.5.24-cp312-cp312-win_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bbb74d4701be2fc7852c80493e2b92cd52485d4712ce8bfc03c92fb7bdd365c5 |
|
MD5 | f6df647b50fa3e12b69ad602808036bb |
|
BLAKE2b-256 | 12850df8620f942e4beaa1cd2560cfd0d7a5444c38e41efb0aa13a0c11a24675 |
Hashes for transformations-2024.5.24-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d81ed1df5dbdd204cd447728cc5b44d4bf1ccd4af5401ee61032477f5de5788b |
|
MD5 | 4d58ef873a43600e50497d7864cd9607 |
|
BLAKE2b-256 | 85e6d7e412940e3640891e165634765ad705677685c285c53d1627c02cd76777 |
Hashes for transformations-2024.5.24-cp312-cp312-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f713ac891a46abfd98158c8a72166a1f92ebaba1644dc8aa59b5357391d6d9e0 |
|
MD5 | 8e56be5d2e3abfc9f4ccefb239db381a |
|
BLAKE2b-256 | 1e1cd7abfdfbbe46a99cfff8840e79da4b503f6d4c9e84f86c9ec16f34f781cb |
Hashes for transformations-2024.5.24-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f87541e8bb87337b8bc1839188d07ad922124f23ce1eca1ce4c6f5bcf5f1e4f |
|
MD5 | 60a04b51da1bb9d8f0bfcde6f5709d31 |
|
BLAKE2b-256 | 4e22b8bdbb6388364ca2720f45a91fae8c7f03e8cbed28902b1fdc2961e253ad |
Hashes for transformations-2024.5.24-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a655966a893ade762f12946c02e3ffa5cd826cf0866e9587e46f812d494ad56e |
|
MD5 | c0fa28cf36d546eb2920258b6a598901 |
|
BLAKE2b-256 | 53a6ff7e1e17978c794c73cfc19fe78b376260ffe7c4d7328a7ae46de593a97c |
Hashes for transformations-2024.5.24-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf0a5f141dcf84a7b5efb27747c2b852d1f9cc8d621d3bdc17fb2f9ac37eaee3 |
|
MD5 | 51f301c41767fa351404fd5b5c56ef8b |
|
BLAKE2b-256 | d71f68ff4a6369eb5fad8df4f1c54149ecaed8819a45376cf8d160b43a6e52e6 |
Hashes for transformations-2024.5.24-cp311-cp311-win_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | be69c3055aa341db7bd231d979ebaae1e64417246a6792c1d03631193edde442 |
|
MD5 | 4ee6d569c88e7cda393536634e421452 |
|
BLAKE2b-256 | de94479a93a9cb3a556fb632bb3eab801a27a04b46d3b5670138819c560fca5d |
Hashes for transformations-2024.5.24-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22fd2283b4aa51609ce3d6929add2fef656f049c5cfa291cc6abfdae2a329f7f |
|
MD5 | 6467087958efa5beaeb0d77c63d40ee0 |
|
BLAKE2b-256 | 8dfb9ec0af1e316a87b3213c299ab10623530a033a5deee297a00771acaedec2 |
Hashes for transformations-2024.5.24-cp311-cp311-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c76e772b77d4665440dac82b36485565e0e0d4ef3679b48ef4449b73935e44fb |
|
MD5 | d52b253932486c57b5b120d36b2822a3 |
|
BLAKE2b-256 | 6c95d0534e51c78efd66291fbcd8fc10c2a8939a8c61a6d4be1e233d612f39f7 |
Hashes for transformations-2024.5.24-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fba5109b455836829ce6476ba53c16f6e72187340084d004dcfac9bf11a2bfd7 |
|
MD5 | 57614b8d0685acf6be9564ca2870637b |
|
BLAKE2b-256 | 745a31ad7b50c36aef716eecbcade4cba064ce876f497d94f096a607c7a6837d |
Hashes for transformations-2024.5.24-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 575d0b5d8c2c92931da46fc55568f17f7b306334ba25fa6091ac5708808bfbfc |
|
MD5 | 38070475226fdfbca988fcf40ed8dd9a |
|
BLAKE2b-256 | bac98e63672087e2836636bdd80b6d97f44075be64325ec7e3048bfb54511940 |
Hashes for transformations-2024.5.24-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1290cdcb65067809cd8dd4b3c3ab552fb6b50e99c015c1678618de2b67913b72 |
|
MD5 | 4e8bd8ae0df4ec24522f2855a98a1075 |
|
BLAKE2b-256 | b7e99f00108679b17b4684fdd7e7f03e2530cae7e157f035acdb3ec1aaf5053e |
Hashes for transformations-2024.5.24-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c599f0140f18f590c50992f5011593ce08e4b893ff26fde4bf7bf5e0db1d9c60 |
|
MD5 | 68669191ec9dcd7dded8af2a8898c13f |
|
BLAKE2b-256 | c688702aeb0fe435ba764350d49ba58b73797aa489c819204d1aaa821fed1029 |
Hashes for transformations-2024.5.24-cp310-cp310-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ddcec2e35a05a3f81a318c4d7184a4c347b85030cdbc36fdad92c7eb2ba70d4 |
|
MD5 | 01a2464f59beb16ce93112e45fbe4e39 |
|
BLAKE2b-256 | b3156b70b648740e6edc0965c467fb4bd6cf8f3f622a33a248fc9d33207e45b9 |
Hashes for transformations-2024.5.24-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc36351fed3d7bc2d413bab358828870f02a41d71723033032d08e2e75361892 |
|
MD5 | 8114e62987158e59d5e3e304bc49213b |
|
BLAKE2b-256 | 16770277da84815bc7868d439d3c97cf15d074b4d5e4ff6a4ad7c2c3e78a7bef |
Hashes for transformations-2024.5.24-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c3c6b07e1d0d9714f3ccd163785845ff780df26ab094ed125b11d0922c4fee7 |
|
MD5 | f7d0b9480ad2b8f77e73a15cbce65598 |
|
BLAKE2b-256 | 52137eef15dfc6f53d545860a0c9ae68e3f2627e34146b8bf0261db463b80f6a |
Hashes for transformations-2024.5.24-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b538ec7fc815c4ab6f427e339eb1a4eddd46860fff306f8f7c6eb80167d08d28 |
|
MD5 | 91c2f97c5c96001d7a3c6b960bf58f75 |
|
BLAKE2b-256 | 5a68ac72909a1fb191ffbe5a3c300fe264238b22ffeeae5b3f8dad58643d2a16 |
Hashes for transformations-2024.5.24-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dda37a7683acb10068c491b6d33bdbdbfb1a1ea4a3291639b23ee4a0af42138c |
|
MD5 | fc0a950f5c8b32f9c050f12c88eef7c4 |
|
BLAKE2b-256 | eb65e230ca6e7ba00cccd3d69d2fbf8429e0853cc2134e8b051f27a398bdbd90 |
Hashes for transformations-2024.5.24-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 873a7d09a428ccf0156949b1541eae93ee954771c7b431e7d15a79ab2c32d5e4 |
|
MD5 | 1f38e3e04e5b31ca464986b7c2eea49a |
|
BLAKE2b-256 | 949496df2cf765e8e0bf90be6e56473f09a2ee2c4910597c7ed8e6c160e0eaa0 |
Hashes for transformations-2024.5.24-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00b20a57cfe4b5f5fadf957bff68c40a86437f85e75b2ed655b87beb45d62940 |
|
MD5 | 6e5117014a2813c6a5be70c6f0aa035f |
|
BLAKE2b-256 | f41b64b3a2d70f0c3c876246dd3a6cc7d1e6a240e77e318657284df3769e82d3 |
Hashes for transformations-2024.5.24-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29f4ebee83c2fb6857f7dbb15917e39bc6bed1f309179452a0dfeda37e2d4d0d |
|
MD5 | 03ea34a69ca8dbeab0540f92d42de5ee |
|
BLAKE2b-256 | 4cb40571239989e1836d6d2cc6886223e33de386e8d33cbff479e7f9a9d184ca |
Hashes for transformations-2024.5.24-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d70a175f7baff6cc70236f74d51c5adb14a3cc3d89fc2e108c1f086f9a834e88 |
|
MD5 | bc03257cdf41cb550a4e30c544b21e5e |
|
BLAKE2b-256 | 4835cdcf7179ad5466608b42b9ba7475665e8540da50fab98a3b7d9433119587 |