Quaternion to matrix rotation only one axis

梦想的初衷 提交于 2020-03-05 05:17:42

问题


I have a quaternion that contains the rotation of the three axes (x, y, z) at the same time.

I want to convert this quaternion to a rotation matrix but only the rotation on the Y axis of the quaternion or of any of the other axes, without all three at the same time.


回答1:


A possible route:

  • Transform unit vectors X=(1,0,0) and Z=(0,0,1) by the quaternion
  • Call these rotated vectors (x0,x1,x2) and (z0,z1,z2)
  • If the rotation would have been purely around Y, we would have:
    • (x0,x1,x2) = (cos(theta), 0, sin(theta))
    • (z0,z1,z2) = (-sin(theta), 0, cos(theta))
    • not used is (y0,y1,y2) = (0, 1, 0)
  • so, calculate
    • c = (x0+z2) / 2
    • and s = (x2-z0) / 2
  • then normalize to get c2 + s2 equal to 1
    • norm = sqrt(c * c + s * s)
    • if norm != 0:
      • c = c / norm
      • s = s / norm
      • (if the norm would be zero, there is not much we can do)
  • the angle would be atan2(c, s)
  • the rotation matrix would be [[c,0,-s],[0,1,0],[s,0,c]]


来源:https://stackoverflow.com/questions/58946202/quaternion-to-matrix-rotation-only-one-axis

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!