Calculating translation and rotation of object based on another object

3dtrigonometry

My knowledge of trigonometry is very limited and prevents me from even reasoning about the problem I'm about to describe.

First I believe it'll help to consider the diagrams below. Please note that in each of the diagrams, the objects are in 3D space.

Object I       Object II  
     ^              ^       
     |              |     
   xx|              |     
   o xxx          xoooo   
---o-P-o--->   ---x P o--->
   o   o          xoooo   
   ooooo            |     
     |              |     

The two diagrams above refer to two separate objects in 3D space.

P refers to origin and is meant to show that each object is centered on origin in their respective local space.
x denotes a plane (a quad) that is a special connector element allowing for additional objects to be chained together. You can assume that these planes are identical on each object.
o is simply a non-connector element that is part of the object.

Intended result in world space
        ^
        |                 
        |o                
        / o               
       x 2 o              
      xxx /               
      o xxx               
------o-P-o------>
      o   o               
      ooooo               
        |                 
        |       
      

This diagram illustrates what I'm trying to achieve. Essentially I'd like to draw two separate objects in 3D space and make it look like they are linked/chained together.

To this end I need to calculate object II's rotation and translation in such a way that one of its connector quads (denoted by x in the diagrams) exactly touches Object I's own connector quad.

What are the mathematical operations that I would need to carry out?

Best Answer

What you are looking for is parent - chain transformations.

Create a $4\times4 $ transformation matrix (it will be homogenous as well as have the ability to be invertible) to transform your two objects in relation to a universal (world) origin

*Having the objects relation to the same origin will make your job easier (this is done through the matrix). A transformation matrix will consist of the object's rotation, translation and scale (if you want).

Here is what transformation matrix looks like:

$\begin{bmatrix} S_xR_{00} & R_{01} & R_{02} & T_x \\ R_{10} & S_yR_{11} & R_{12} & T_y \\ R_{20} & R_{21} & S_zR_{22} & T_z \\ 0 & 0 & 0 & 1 \\ \end{bmatrix}$

where R = rotation, S = scale respective, T = translation respective

If a object2 is connected to another object1, object2 is influenced by the transformation (ie. translation, rotation) of object 1. Therefore, the transformation matrix can be chained, by multiplying object1's transformation matrix to object2's transformation matrix to get the overall transformation for object 2.