1

I have two identical mesh objects, but their positions and rotation directions are different; I know the position information of the two mesh vertices, how can I get the relative transformation matrix between them

enter image description here

Spektre
  • 49,595
  • 11
  • 110
  • 380
bimPaoHui
  • 11
  • 2
  • Welcome to SO bimPaoHui, Please read [ask] and take a [tour] about SO. When asking a question here, its always good to provide a bit more information such as minimal reproducible inputs and an expected output. – Akshay Sehgal Feb 05 '21 at 09:31

1 Answers1

1
  1. obtain or construct homogenuous transform matrix for each object

    lets call them a,b corresponding to meshes A,B

  2. compute the difference matrix d

    for example you want to go from A to B then its just matter of solving:

               a*d = b
    Inverse(a)*a*d = Inverse(a)*b
                 d = Inverse(a)*b
    

    Beware in case you use different notations (like reverse order of multiplication and or inverse matrices instead of direct ones the equation might get inverted and or transposed)

Also here another example:

Spektre
  • 49,595
  • 11
  • 110
  • 380
  • The situation you mentioned is that the rotation displacement exists in the conversion matrix, but the two mesh conversion matrices are actually identity matrices, and the angle and position information are in the geometric structure information. – bimPaoHui Mar 18 '21 at 10:05
  • 《Problem superimposing and aligning 3D triangles》 This looks similar to my question, I will try it, thank you – bimPaoHui Mar 18 '21 at 10:10
  • @bimPaoHui if the topology of the mesh is the same (I mean order of point is the same in both meshes so i-th point corresponds to the same point on both meshes) than just pic 3 points not on single line (for example 3 points form first face) construct matrices and compute the difference between them. However if the meshes have different topology you first have to match them (for example use [3D OBB](https://stackoverflow.com/a/62284464/2521214) ... or search for specific feature) – Spektre Mar 18 '21 at 10:52
  • for (m=lroty(ma,float(-0.5*M_PI)),b=0;b – bimPaoHui Apr 28 '21 at 02:04
  • @bimPaoHui yes `mat4` is 4 element array of `vec4` and `.xyz` is accessing just `vec3` from `vec4` just like in GLSL (its the same syntax, took me a while to code `?mat?,?vec?` classes so its the same behavior and syntax) – Spektre Apr 28 '21 at 06:17
  • I've got it, thank you, but it didn't work very well; When the object is rotated, the point and coordinate system obtained by calculating OBB have errors compared with the actual transformation matrix of the object – bimPaoHui Apr 30 '21 at 02:01
  • @bimPaoHui OBB is usable only of your object is not too symmetric or round ... Its precision also depends on how you compute it ... If you used my approximation approach then you need to recursively increase its accuracy... Another option is use OBB to identify vertexes in mesh and use them... you know find closest vertex to each face of OBB ... again with symmetrical objects or some shapes this might be a problem as there might be more than one such point or the OBB might have more rotations possible for the same object just look at the animation in the 3D OBB how the OBB jumps and rotates. – Spektre Apr 30 '21 at 07:12