3D刚体平移和旋转的python实现 [英] python implementation of 3D rigid body translation and rotation

查看:825
本文介绍了3D刚体平移和旋转的python实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试找出如何使用python解决以下问题:

I've been trying to work out how to solve the following problem using python:

  1. 我们有点a,b,c,d构成了刚体
  2. 某些未知的 3D 平移和旋转应用于刚体
  3. 我们现在知道a,b,c的坐标
  4. 我们要计算d的坐标
  1. We have points a, b, c, d which form a rigid body
  2. Some unknown 3D translation and rotation is applied to the rigid body
  3. We now know the coordinates for a, b, c
  4. We want to calculate coordinates for d

到目前为止我所知道的:

What I know so far:

  • 由于云台锁定等原因,尝试通过直截了当"的欧拉角计算来做到这一点似乎是个坏主意.
  • 因此,第4步将涉及一个转换矩阵,一旦您知道旋转和平移矩阵,使用以下方法之一就很容易完成此步骤:

  • Trying to do this with "straightforward" Euler angle calculations seems like a bad idea due to gimbal lock etc.
  • Step 4 will therefore involve a transformation matrix, and once you know the rotation and translation matrix it looks like this step is easy using one of these:

  • http://www.lfd.uci.edu/~gohlke/code/transformations.py.html
  • https://pypi.python.org/pypi/euclid/0.01

我无法解决的是如何在给定a,b,c的新"坐标的情况下计算旋转和平移矩阵.

What I can't work out is how I can calculate the rotation and translation matrices given the "new" coordinates of a, b, c.

我可以看到,在一般情况下(非刚体),旋转部分是 Wahba问题,但是我认为对于刚体,应该有一些更快的方法,可以通过使用这些点算出一组正交单位矢量来直接计算它.

I can see that in the general case (non-rigid body) the rotation part of this is Wahba's problem, but I think that for rigid bodies there should be some faster way of calculating it directly by working out a set of orthogonal unit vectors using the points.

推荐答案

对于您要匹配的一组对应点(可能存在扰动),我使用了SVD(奇异值分解),它似乎已经存在在numpy中.

For a set of corresponding points that you're trying to match (with possible perturbation) I've used SVD (singular value decomposition), which appears to exist in numpy.

可以在找到此处的情况下使用这种技术(甚至在Python中),但是我还没有' t对它的正确性进行了评估.

An example of this technique (in Python even) can be found here, but I haven't evaluated it for correctness.

您要使用的是基本变换"或基础变更",将其表示为变换矩阵.假设您的3个已知点不是共线的,则可以通过以下方式创建初始基础:

What you're going for is a "basis transform" or "change of basis" which will be represented as a transformation matrix. Assuming your 3 known points are not collinear, you can create your initial basis by:

  1. 计算向量:x =(b-a)和y =(c-a)
  2. 归一化x(x = x/幅度(x))
  3. 将y投影到x(proj_y = x DOT y * x)
  4. 从y减去投影(y = y-proj_y)
  5. 标准化y
  6. 计算z = x交叉y

这将为您提供初始x,y,z坐标基础A.对新点进行相同操作,您将获得第二基础B.现在,您要查找将在A中得到一个点并将其转换的变换T到B(基准的改变).这部分很容易.您可以反转A将点转换回法线基础,然后使用B转换成第二点.由于A是正交的,因此您可以对A进行转置以获得逆.因此,新d"等于d * inverse(A)*B.(尽管取决于您的表示形式,您可能需要使用B * inverse(A)* d.)

That gives you an initial x,y,z coordinate basis A. Do the same for your new points, and you get a second basis B. Now you want to find transform T which will take a point in A and convert it to B (change of basis). That part is easy. You can invert A to transform the points back to the Normal basis, then use B to transform into the second one. Since A is orthonormal, you can just transpose A to get the inverse. So the "new d" is equal to d * inverse(A) * B. (Though depending on your representation, you may need to use B * inverse(A) * d.)

您需要对矩阵有所了解才能获得所有这些.向量和矩阵的表示形式将告知您将矩阵相乘以得到T的顺序(T是逆(A)* B或B *逆(A)).

You need to have some familiarity with matrices to get all that. Your representation of vectors and matrices will inform you as to which order to multiply the matrices to get T (T is either inverse(A)*B or B*inverse(A)).

要根据向量x =(x1,x2,x3),y =(y1,y2,y3),z =(z1,z2,z3)计算基矩阵,请将其填充为:

To compute your basis matrix from your vectors x=(x1,x2,x3), y=(y1,y2,y3), z=(z1,z2,z3) you populate it as:

| x1 y1 z1 |
| x2 y2 z2 |
| x3 y3 z3 |

这篇关于3D刚体平移和旋转的python实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆