xiaozongpeng 发表于 2021-11-23 08:44

matlab-unreal联合仿真中左手坐标系与右手坐标系中的位姿 ...

matlab具有强大便利的运算仿真能力,支持有效仿真控制算法。unreal引擎能提供真实程度高的环境信息,支持有效仿真环境感知算法。通过matlab-unreal联合仿真,能够极大限度地针对无人机、自动驾驶汽车等应用场景,对系统进行快速高效地验证。
matlab-unreal联合仿真时,matlab中的控制算法与SLAM算法所依赖的程序库(不限于OpenGL、3D Max)均是右手系,unreal中则是左手系(除unreal外,Unity、 Direct3D均是左手系)。本次用线性变换的思路,对位姿在左右手坐标系下表达形式的相互转换进行说明。
<hr/>位姿分为平移与旋转,两者相互独立。平移可用向量表示,旋转可使用矩阵表示。在后续的表达中,向量与矩阵使用黑体正体英文字母表示,向量与矩阵的右下脚标表示左手系或右手系,如 https://www.zhihu.com/equation?tex=%5Ctextbf%7BP%7D_%7Bl%7D 表示左手系中的一个向量。
向量在左右手系中的转换最简单,只需要将某一个轴分量取反。以Z轴取反为例,右手系中的向量 https://www.zhihu.com/equation?tex=%5Cbold%7BP%7D_%7Br%7D%28x%2C+y%2C+z%29 在左手系中转换为点 https://www.zhihu.com/equation?tex=%5Cbold%7BP%7D_%7Bl%7D%28x%2C+y%2C+z%29 ,用矩阵表示为:

https://www.zhihu.com/equation?tex=%5Cbold%7BP%7D_%7Bl%7D%3D%5Cleft%5B%5Cbegin%7Barray%7D%7Bc%7D+x+%5C%5C+y+%5C%5C+-z+%5Cend%7Barray%7D%5Cright%5D%3D%5Cleft%5B%5Cbegin%7Barray%7D%7Bccc%7D+1+%26+0+%26+0+%5C%5C+0+%26+1+%26+0+%5C%5C+0+%26+0+%26+-1+%5Cend%7Barray%7D%5Cright%5D%5Cleft%5B%5Cbegin%7Barray%7D%7Bl%7D+x+%5C%5C+y+%5C%5C+z+%5Cend%7Barray%7D%5Cright%5D%3D%5Cbold%7BS%7D_%7BT%7D+%5Cbold%7BP%7D_%7Br%7D (1)
向量从右手系到左手系的转换矩阵为:

https://www.zhihu.com/equation?tex=%5Cbold%7BS%7D_%7BT%7D%3D%5Cleft%5B%5Cbegin%7Barray%7D%7Bccc%7D+1+%26+0+%26+0+%5C%5C+0+%26+1+%26+0+%5C%5C+0+%26+0+%26+-1+%5Cend%7Barray%7D%5Cright%5D (2)
<hr/>在一组坐标系(基)下,旋转对一个向量进行线性变换变为另外一个向量。
在右手系下,一个旋转矩阵可定义为:

https://www.zhihu.com/equation?tex=%5Cbold%7BR%7D_%7Br%7D%3D%5Cleft%5B%5Cbegin%7Barray%7D%7Blll%7D+r_%7B00%7D+%26+r_%7B01%7D+%26+r_%7B02%7D+%5C%5C+r_%7B10%7D+%26+r_%7B11%7D+%26+r_%7B12%7D+%5C%5C+r_%7B20%7D+%26+r_%7B21%7D+%26+r_%7B22%7D+%5Cend%7Barray%7D%5Cright%5D (3)
右手系下的向量 https://www.zhihu.com/equation?tex=%5Cbold%7BP%7D_%7Br%7D 经过旋转变换为 https://www.zhihu.com/equation?tex=%5Cbold%7BP%7D_%7Br%7D%5E%7B%5Cprime%7D :

https://www.zhihu.com/equation?tex=%5Cbold%7BP%7D_%7Br%7D%5E%7B%5Cprime%7D%3D%5Cleft%5B%5Cbegin%7Barray%7D%7Bl%7D+x%5E%7B%5Cprime%7D+%5C%5C+y%5E%7B%5Cprime%7D+%5C%5C+z%5E%7B%5Cprime%7D+%5Cend%7Barray%7D%5Cright%5D%3D%5Cleft%5B%5Cbegin%7Barray%7D%7Blll%7D+r_%7B00%7D+%26+r_%7B01%7D+%26+r_%7B02%7D+%5C%5C+r_%7B10%7D+%26+r_%7B11%7D+%26+r_%7B12%7D+%5C%5C+r_%7B20%7D+%26+r_%7B21%7D+%26+r_%7B22%7D+%5Cend%7Barray%7D%5Cright%5D%5Cleft%5B%5Cbegin%7Barray%7D%7Bl%7D+x+%5C%5C+y+%5C%5C+z+%5Cend%7Barray%7D%5Cright%5D%3D%5Cbold%7BR%7D_%7Br%7D+%5Cbold%7BP%7D_%7Br%7D

https://www.zhihu.com/equation?tex=x%5E%7B%5Cprime%7D+%EF%BC%8C+y%5E%7B%5Cprime%7D+%EF%BC%8C+z%5E%7B%5Cprime%7D%EF%BC%8Cx+%EF%BC%8C+y+%EF%BC%8C+z 均为常数。求解旋转在左右手系下的表达形式,可表达为右手系下的旋转与左手系下的旋转 https://www.zhihu.com/equation?tex=%5Cbold%7BR%7D_%7Bl%7D 的相互转换。由式(1)可知, https://www.zhihu.com/equation?tex=%5Cbold%7BP%7D_%7Bl%7D%5E%7B%5Cprime%7D%EF%BC%8C%5Cbold%7BP%7D_%7Bl%7D 可由下式算出:

https://www.zhihu.com/equation?tex=%5Cbold%7BP%7D_%7Bl%7D%3D%28x%2C+y%2C-z%29+

https://www.zhihu.com/equation?tex=%5Cbold%7BP%7D_%7Bl%7D%5E%7B%5Cprime%7D%3D%5Cleft%28x%5E%7B%5Cprime%7D%2C+y%5E%7B%5Cprime%7D%2C-z%5E%7B%5Cprime%7D%5Cright%29
又由式(1)可知:

https://www.zhihu.com/equation?tex=%5Cbold%7BP%7D_%7Bl%7D%5E%7B%5Cprime%7D%3D%5Cbold%7BS%7D_%7BT%7D+%5Cbold%7BP%7D_%7Br%7D%5E%7B%5Cprime%7D%3D%5Cbold%7BS%7D_%7BT%7D+%5Cbold%7BR%7D_%7Br%7D+%5Cbold%7BP%7D_%7Br%7D%3D%5Cbold%7BS%7D_%7BT%7D+%5Cbold%7BR%7D_%7Br%7D+%5Cbold%7BS%7D_%7BT%7D+%5Cbold%7BP%7D_%7Bl%7D
定义左手系下的旋转为:

https://www.zhihu.com/equation?tex=%5Cbold%7BR%7D_%7Bl%7D%3D%5Cbold%7BS%7D_%7BT%7D+%5Cbold%7BR%7D_%7Br%7D+%5Cbold%7BS%7D_%7BT%7D (4)
左手系中旋转的通俗的理解如下:

[*]将左手系中的点变换到右手系中
[*]根据右手系中的旋转矩阵进行旋转
[*]将旋转后的点变换到左手系中
因此式(3)所示的右手系手中的旋转,可计算为:

https://www.zhihu.com/equation?tex=%5Cbold%7BR%7D_%7Bl%7D%3D%5Cleft%5B%5Cbegin%7Barray%7D%7Bccc%7D+r_%7B00%7D+%26+r_%7B01%7D+%26+-r_%7B02%7D+%5C%5C+r_%7B10%7D+%26+r_%7B11%7D+%26+-r_%7B12%7D+%5C%5C+-r_%7B20%7D+%26+-r_%7B21%7D+%26+r_%7B22%7D+%5Cend%7Barray%7D%5Cright%5D
实际上旋转的表示方法不限于旋转矩阵,还有轴角表示法、四元数表示法、欧拉角表示法。欧拉角表示法直观,在程序调试时很有用,但存在严重的万向锁问题。实际的计算机运算中大量使用四元数。以上述的对z轴取反为例,左右手系中旋转向量 https://www.zhihu.com/equation?tex=%5Cbold%7BR%7D 与四元数 https://www.zhihu.com/equation?tex=%5Cbold%7Bq%7D%28w%2Cx%2Cy%2Cz%29 , https://www.zhihu.com/equation?tex=w 为实部,的转换关系如下:

https://www.zhihu.com/equation?tex=%5Cbegin%7Bgathered%7D+%5Cbold%7Bq%7D_%7Bl%7D%28w%29%3D%5Cfrac%7B%5Csqrt%7B1%2B%5Coperatorname%7Btr%7D%5Cleft%28R_%7Bl%7D%5Cright%29%7D%7D%7B2%7D%3D%5Cbold%7Bq%7D_%7Br%7D%28w%29+%5C%5C+%5Cbold%7Bq%7D_%7Bl%7D%28x%29%3D%5Cfrac%7B-r_%7B12%7D-%5Cleft%28-r_%7B21%7D%5Cright%29%7D%7B4+q_%7B0%7D%7D%3D-%5Cfrac%7Br_%7B12%7D-r_%7B21%7D%7D%7B4+q_%7B0%7D%7D%3D-%5Cbold%7Bq%7D_%7Br%7D%28x%29+%5C%5C+%5Cbold%7Bq%7D_%7Bl%7D%28y%29%3D%5Cfrac%7B-r_%7B20%7D-%5Cleft%28-r_%7B02%7D%5Cright%29%7D%7B4+q_%7B0%7D%7D%3D-%5Cfrac%7Br_%7B20%7D-r_%7B02%7D%7D%7B4+q_%7B0%7D%7D%3D-%5Cbold%7Bq%7D_%7Br%7D%28y%29+%5C%5C+%5Cbold%7Bq%7D_%7Bl%7D%28z%29%3D%5Cfrac%7Br_%7B01%7D-r_%7B10%7D%7D%7B4+q_%7B0%7D%7D%3D%5Cbold%7Bq%7D_%7Br%7D%28z%29+%5Cend%7Bgathered%7D
页: [1]
查看完整版本: matlab-unreal联合仿真中左手坐标系与右手坐标系中的位姿 ...