0

What is the best way to convert the orientation from

pybullet.getBasePositionAndOrientation

to a vector in xyz axis representation in python? I could only find limited documentation so far on this issue, thanks for any insight.

WhooNo
  • 911
  • 2
  • 12
  • 28
Silicon
  • 21
  • 2

1 Answers1

0

SciPy has a Rotation class which I find very convenient when working with orientations/rotations. Among some other things, it makes conversion between different representations pretty easy.

PyBullet returns the orientation as a quaternion. I assume with "xyz axis representation" you mean what in SciPy is called a "rotation vector" (i.e. "a 3 dimensional vector which is co-directional to the axis of rotation and whose norm gives the angle of rotation"). Given this, the code for converting would look as follows:

from scipy.spatial.transform import Rotation

_, pybullet_orientation = pybullet.getBasePositionAndOrientation(...)

rot = Rotation.from_quat(pybullet_orientation)
rotvec = rot.as_rotvec()
luator
  • 4,769
  • 3
  • 30
  • 51