Search code examples
c++eigencoordinate-transformation

Convert a transformation matrix from world-space to camera-space using Eigen


I have a transformation matrix, in world space. I need to convert it to local(camera) space.

I have done the reverse of this (Local - to - world) using:

    Eigen::Matrix3f R0; //rotation matrix
    Eigen::Vector3f T0; // xyz translation values
    Eigen::Vector3f C0; //result

    R0.transposeInPlace();  //invert rotation matrix

    C0 = -R0 * T0;   //return world-space coordinate

Can I simply run this exact same thing to invert it the other way? Or is it a different equation?

Thank you.


Solution

  • Definitely look into studying linear algebra if you wish to continue to work with matrices.

    In your case, you should be able to solve for T0 if you left-multiply by the matrix inverse on both sides:

    C0 = -R0 * T0

    -R1 * C0 = -R1 * -R0 * T0 (R1 is the inverse of R0)

    -R1 * C0 = T0

    So to get T0 from C0, you'd negate and left-multiply C0 by the inverse of R0, which would be the matrix you started with before you called R0.transposeInPlace();