The Coordinate System - How to convert between different coordinate system

1 minute read

Coordinate System

system image System hand Rotation hand Camera Order
OpenGL 20211116000556 RH RH (0,0,-1) XYZ
Unity 20211116000556 LH LH (0,0,1) YXZ(local) zxy(global)
pytorch3d 20211116000556 RH LH (0,0,1) XYZ
OpenCV、Open3D、Matterport3D、Colmap 20211117163530 RH RH (0,0,1) XYZ
scipy   RH LH   XYZ xyz
blender 20211116000556 RH RH    

Docs

  • scipy
  • unity
    • rotation
      • local rotation: intrinsic rotations, YXZ
      • global rotation: extrinsic rotations, zxy
    • order: YXZ
  • math
    • Rodrigues: $r_{vert} = [x,y,z]$, $ r_{vert} 2$表示旋转角度, $r{vert}$表示旋转向量
    • 四元数与空间旋转
  • cv2
    • Rodrigues
      • cv2.Rodrigues(rotvec)[0]: 旋转向量到旋转矩阵
      • cv2.Rodrigues(rotmatrix)[0]: 旋转矩阵到旋转向量

Conversion

c r c t o r obj t obj scale status comment
9.3,153.1,106.7 -43.2,99.3,83.8 0 0 0,-1,0 c r = inv(mat)zxy,xyz=[-,-,+], t = xyz[+,+,-]
9.3,153.1,106.7 0 0 43.2,-99.3,-83.8 0,-1,0 c r = inv(mat)zxy,xyz=[-,-,+],o t = xyz[-,-,+]

From unity to pytorch3d

  • unity$(t=(x,y,z),r=(\theta_x,\theta_y,\theta_z))$
  • pytorch3d$(t=(-x,y,z)),r=(-\theta_x,\theta_y,\theta_z)$
  • code
    • equivalence transformation
    • euler to euler
     verts *= [-1,1,1]
     theta_x, theta_y, theta_z = angles
     rotation=R.from_euler("yxz", [theta_y, theta_x, theta_z], degrees=True).as_matrix()
     trans *= [-1,1,1]
    
    • unity.quat to scipy.euler
     # quat from unity [10,-120,70]
     quat = [0.459144592,0.731702268,-0.347525775,-0.364724457]
     euler = R.from_quat(quat).as_euler('zxy')
     euler *= [1,-1,1]
     rotation = R.from_euler('yxz', euler[[2,1,0]]).as_matrix()
    

Reference

Categories:

Updated: