1

I have to convert poses (coordiantes + quaternion for rotation) from two different APIs I'm using. More specifically I get coordinates of objects relative to the camera's local position.

My detection library (for detecting those objects) has the coordinate system of the camera oriented with Z in the direction the camera is looking, X to the right of the camera, and Y down from the camera (if you look from the perspective of the camera itself). I will use ACII Art here to show what I mean:

Symbols:

+------+
|      | = camera from the back
+------+

+--+
|  +-+
|    |   = camera from the right side (imagine the front part as the lens)
|  +-+
+--+

Detection Coordinate System from the back of the camera

+--------> x
|
|      +------+
|      |      |
V y    +------+
Detection Coordinate System from the right side of the camera

+--------> z
|     +--+
|     |  +-+
|     |    |
V y   |  +-+
      +--+

The library where I use the object poses however has X in the same direction, but Y and Z are both inverted. So Z is pointing opposite the looking direction of the camera and Y is pointing straight up. More ASCII sketches:

Usage Coordinate System from the back of the camera

^ y    +------+
|      |      |
|      +------+
|
+--------> x
Usage Coordinate System from the right side of the camera

+--+
|  +-+         ^ y
|    |         |
|  +-+         |
+--+           |
    z <--------+

So now I get object poses (including rotation) in the detection coordinate system but want to use them in the usage coordinate system. I know I can transform the coordinates by just inverting the values for y and z, but how do I convert the quaternions for the rotation? I tried a few combinations but none seem to work.

Miki
  • 40,887
  • 13
  • 123
  • 202
Emil S.
  • 412
  • 4
  • 20
  • 1
    I think this [Is there a way to calculate 3D rotation on X and Y axis from a 4x4 matrix](https://stackoverflow.com/a/56950130/2521214) might help with (if not fully solve) your problem – Spektre Nov 11 '20 at 11:26
  • Hmm, I'm not working with transformation matrices here, but with coordinate-quaternion pairs. Do you suggest converting them to transform matrices, converting the coordinate systems, and then converting back to coordinate-quaternion pairs? I'm not sure if that is an efficient route and since I have to do these transformations multiple times per frame it would also be quite costly for the framerate. – Emil S. Nov 11 '20 at 12:06
  • I am not sure if you can convert in between quaternion rotations otherwise ... But I can be wrong as I do not use quaternions – Spektre Nov 11 '20 at 12:23
  • 1
    Okay, see the accepted answer for the solution using just quaternions. No conversions required. – Emil S. Nov 16 '20 at 11:31

1 Answers1

1

In this case your change of basis are just permutations of the axes, so to convert from one to the other you just have to replicate the same permutation in the imaginary vector in the quaternion.

i.e. if your quaternion is (w,x,y,z) and the basis permutation is (z,y,x) your new quaternion is (w,z,y,x).

Makogan
  • 8,208
  • 7
  • 44
  • 112
  • So in this case I just go from (w,x,y,z) to (w,x,-y,-z)? – Emil S. Nov 12 '20 at 12:04
  • I think so (i didn't keep track of the transformations too much) – Makogan Nov 12 '20 at 14:50
  • Alright, seems like it actually was this easy. Thank you for your help. – Emil S. Nov 16 '20 at 11:30
  • For the future, just remember. All a basis is, is a set of coordinates. So what matters is just to replicate the changes to the basis to the coordinates. If the axes switch, so do the coordinates. – Makogan Nov 16 '20 at 17:42