齐次变换矩阵与四元数
transformations的Python项目详细描述
transformations是一个python库,用于计算 平移、旋转、反射、缩放、剪切、投影, 三维齐次坐标系的正交和叠置 以及旋转矩阵,欧拉角之间的转换, 四元数。还包括一个arcball控件对象和 分解变换矩阵的函数。
Author: | Christoph Gohlke |
---|---|
Organization: | Laboratory for Fluorescence Dynamics. University of California, Irvine |
License: | 3-clause BSD |
Version: | 2019.4.22 |
要求
- CPython 2.7 or 3.5+
- Numpy 1.11.3
- 与python distutils兼容的c编译器(编译)
修订版
- 2019.4.22
- 修复设置要求。
- 2019.1.1
- 更新版权年。
注释
transformations.py不再是积极开发的,它有一些已知的问题 以及数值不稳定性。该模块大部分被其他模块取代 对于三维变换和四元数:
api还不稳定,预计会在不同的版本之间发生变化。
不推荐使用Python2.7和3.4。
此python代码没有针对速度进行优化。参考转换.c 一些功能的快速实现。
可以使用epydoc生成html格式的文档。
矩阵(m)可以使用numpy.linalg.inv(m)反转,可以使用 numpy.dot(m0,m1)或使用 numpy.dot(m,v)分别表示形状(4,*)列向量 numpy.dot(v,m.t)表示形状(*,4)行向量(“点数组”)。
此模块遵循“右边的列向量”和“行主存储器” (c)公约。翻译组件在右栏中 变换矩阵,即m[:3,3]。 转换矩阵的转置可能必须用于接口 使用其他图形系统,例如OpenGL的glmultMatrixd()。另见[16]。
计算采用numpy.float64精度。
向量、点、四元数和矩阵函数参数应为 “类数组”,即元组、列表或numpy数组。
除非另有说明,否则返回类型是numpy数组。
除非另有规定,否则角度以弧度为单位。
四元数w+ix+jy+kz表示为[w,x,y,z]。
三个欧拉角可以24种方式应用/解释,这可以 使用4字符字符串或编码的4元组指定:
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.
参考文献
- 矩阵和变换。罗纳德·戈德曼。 在“图形宝石I”,第472-475页。摩根考夫曼,1990年。
- 更多矩阵和变换:剪切和伪透视。 罗纳德·戈德曼。在“图形宝石II”,第320-323页。摩根考夫曼,1991年。
- 将矩阵分解为简单的变换。斯宾塞·托马斯。 在“图形宝石II”,第320-323页。摩根考夫曼,1991年。
- 从转换矩阵中恢复数据。罗纳德·戈德曼。 在“图形宝石II”中,第324-331页。摩根考夫曼,1991年。
- 欧拉角转换。肯鞋匠。 在“图形宝石四”,第222-229页。摩根·考夫曼,1994年。
- 弧形球旋转控制。肯鞋匠。 在“图形宝石四”,第175-192页。摩根·考夫曼,1994年。
- 表示姿态:欧拉角、单位四元数和旋转 向量。詹姆斯·迪贝尔。2006年。
- 关于两个集合最佳旋转解的讨论 矢量的。W卡布希。水晶行动。1978年。A34827-828航班。
- 用单位四元数求绝对定向的闭式解。 黑色喇叭。J Opt Soc AM A.1987年。4(4):629-642。
- 四元数。肯鞋匠。 http://www.sfu.ca/~jwa3/cmpt461/files/quatut.pdf
- 从四元数到矩阵再到矩阵。范·韦弗伦。2005年。 http://www.intel.com/cd/ids/developer/asmo-na/eng/293748.htm
- 均匀随机旋转。肯鞋匠。 在“Graphics Gems III”中,第124-132页。摩根·考夫曼,1992年。
- 分子模拟中的四元数. 卡尼中锋。 J分子图模型,25(5):595-604
- 从旋转矩阵中提取四元数的新方法。 伊兹哈克酒吧伊兹哈克,吉德控制发电机。2000年。23(6):1085-1087。
- 计算机视觉中的多视图几何。哈特利和齐瑟曼。 剑桥大学出版社;2004年第2版。第4章,算法4.7,第130页。
- 列向量与行向量。 http://steve.hollasch.net/cgindex/math/matrix/column-vec.html
示例
>>> 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