Forum

Author Topic: Calculate 4*4 transformation matrix from rotation and translation  (Read 969 times)

Yoann Courtois

  • Sr. Member
  • ****
  • Posts: 315
  • Engineer in Geodesy, Cartography and Surveying
    • View Profile
Hey !

Based on previous topic (https://www.agisoft.com/forum/index.php?topic=11167.msg50189#msg50189), we found how we can get 3*3 rotation matrix and then yaw/pitch/roll values from 4*4 transformation matrix of an aligned images.
Using same function but with .translation() instead of .rotation(), we can easily get 3*1 translation matrix and so X,Y,Z coordinates.

But now for special test we would like to invert the process :
Based on 3*3 rotation and 3*1 translation matrix, we would like to get the 4*4 transformation matrix in metashape system.

Translation part is easy as X, Y and Z can be directly put in the 4*4 matrix like this :
Code: [Select]
[[*, *, *, X],
 [*, *, *, Y],
 [*, *, *, Z],
 [0, 0, 0, 1]]

But for the rotation part, it looks .rotation() apply a calculation from the "star part" on the above matrix ([[*,  *, ...]]) to the 3*3 rotation matrix.
So we would like to invert this function to create our own 4*4 matrix based on 3*3 rotation and 3*1 translation matrix.

Note : We get our 3*3 rotation matrix from yaw/pitch/roll values using ypr2mat() function

Hope it's clear enough  ::)

Regards
--
Yoann COURTOIS
R&D Engineer in photogrammetric process and mobile application
Lyon, FRANCE
--

Paulo

  • Hero Member
  • *****
  • Posts: 1076
    • View Profile
Re: Calculate 4*4 transformation matrix from rotation and translation
« Reply #1 on: December 16, 2021, 03:15:21 PM »
Hello Yoann,

given a 3*3 rotation matrix R, to get the 4*4 equivalent you just do:

Metashape.Matrix.Rotation(R) see p. 70 of API document

given the 3*1 translation vector T, to get the 4*4 equicalenet, just do:

Metashape.Matrix.Translation(T)

Hope this is helpful,
Best Regards,

Paul Pelletier,
Surveyor

Yoann Courtois

  • Sr. Member
  • ****
  • Posts: 315
  • Engineer in Geodesy, Cartography and Surveying
    • View Profile
Re: Calculate 4*4 transformation matrix from rotation and translation
« Reply #2 on: December 17, 2021, 02:12:12 PM »
Hello Paul,

Indeed, you are right ! But ...

We have worked a whole day on the problem that in some cases, 3*3 rotation matrix is not equal to (Metashape.Matrix.Rotation(R)).rotation().
Finally we found that they are equivalent, because they describe the same yaw/pitch/roll angles, but looking at each value of both matrix, they are different...

We have then been able to apply angle corrections to our images as needed.

Thank you.
--
Yoann COURTOIS
R&D Engineer in photogrammetric process and mobile application
Lyon, FRANCE
--

Paulo

  • Hero Member
  • *****
  • Posts: 1076
    • View Profile
Re: Calculate 4*4 transformation matrix from rotation and translation
« Reply #3 on: December 17, 2021, 06:18:15 PM »
Yoann, bien de savoir que cela a fonctionné,

Bonne continuation!
Best Regards,

Paul Pelletier,
Surveyor