0

I am trying to convert a transformation matrix from one coordinate system to another. The first coordinate system looks like this in a pybullet simulation:

pybullet simulation

I'm assuming this coordinate system would be:

  • X = Forward

  • Y = Away From Camera

  • Z = Up

Though I'm not sure about the orientation of the XY plane.

The second coordinate system looks like this:

enter image description here

I'm assuming this coordinate system would be:

  • X = Forward

  • Y= Up

  • Z = Toward The Camera

Though I'm not sure about the orientation of the XZ plane.

The coordinate conversion should then be something like this:

(X,Y,Z)->(X,-Z,Y)

This is the following code I wrote to achieve the transformation:

def transform_matrix(self,transformation_matrix):
    #X maps to X (1,0,0)
    #Y maps to -Z (0,0,-1)
    #Z maps to -Y (0,-1,0)
        

    C = np.matrix([
        [1, 0, 0, 0],
        [0, 0, -1,0],
        [0, -1, 0, 0],
        [0, 0, 0, 1]])

    C_prime = np.transpose(C)

    return C @ transformation_matrix @ C_prime 

Which I derived from here

This code, however, isn't working. I'm not sure if it's because the code itself is incorrect, or if my mapping is incorrect. Any help would be appreciated!

Sergio
  • 33
  • 1
  • 4
  • why not just swaping the columns? – Pablo C May 26 '23 at 16:21
  • @PabloC do you mean making the y column equal to the -z column? I've tried that as well. – Sergio May 26 '23 at 16:28
  • Why does the comment say Y maps to -Z? In the pictures both Y and Z go up? – Joooeey May 26 '23 at 17:40
  • I took the same logic that was specified in the link I provided, but Y maps to -Z because in the original coordinate system, Y goes away from the camera; whereas, Z goes towards the camera – Sergio May 26 '23 at 17:57

2 Answers2

1

So @JamesParrott was correct in that you do have a mathematical error. The concept that you are missing is not that you are mapping coordinates simply applying a sign change or such. I think we need more context here. Are you applying a rotation matrix (as link indicated)

Also the link you provided is a discussion around a 4D rotation matrix (x,y,z,w) - I am guessing your application would be a 3x3 Matrix.

Furthermore, I am gonna link here - don't kill this post, haha. https://en.wikipedia.org/wiki/Rotation_matrix

That link is on Rotation Matrices - a standard mathematical concept you can find any number of links on.

If you are simply wanting to map the space (X,Y,Z) to (X, -Z, -Y), then your matrix should be [[1 0 0], [0, 0, -1], [0, -1, 0]]

To understand why this works, do the following matrix multiplication (I recommend using Wolfram Alpha for simple understandings like this)

Transformation

John Aven
  • 36
  • 3
0

Is there a simple sign error? In the link, the middle two non-zero entries are +1 and -1. Your matrix has both equal to -1.

4x4 matrix from the link

JamesParrott
  • 91
  • 1
  • 3
  • 1
    Sorry, I should have been more clear with the link. The only portion I derived from the link is the equation M_{new} = C * M * C^-1, which yields the transformation matrix in the new coordinate space. My coordinate systems are not the same from the link, however. – Sergio May 26 '23 at 17:44
  • Ah sorry. Which error are you getting, and what transformation_matrix are you calling it with? – JamesParrott May 26 '23 at 18:19
  • So some answers I need help with are, is my transform_matrix function mathematically correct in terms of changing a transformation matrix from one coordinate system to another? Additionally, how should I interpret the pictures of the coordinate systems I provided? I don't know how to tell what is left, right, forward, or back. – Sergio May 26 '23 at 18:34
  • The equation ought to be C^-1 M C, but it should make no difference in your case as your C matrix satisfies C = C' = C^-1 https://en.wikipedia.org/wiki/Change_of_basis#Endomorphisms – JamesParrott May 26 '23 at 19:03