How to move object a from in front of object b to in front of object c and transfer orientation?

Learning vector arithmetic…
I have two fixed cubes in my scene. Each cube has a different position and orientation ( Rotation ).
I have a cylinder a certain distance from the center of the first cube’s front Z axis face.

I would like to place the cylinder in front of the second cube’s Z axis at the same distance and with the same orientation that it currently has in front of the first cube.

For a more visual for example, let’s say I have my left hand palm up with a marble floating 3 inches above the center of the palm.
I placed my right hand 1 foot from my head with the palm facing my face. I’m looking for the calculation that would move the marble from my left hand to my right hand so that the marble is between my right palm and my face 3 inches from the palm.

Obviously something like:

`Cylinder.transform.position=Cylinder.transform.position - CubeA.transform.position + CubeB.transform.position;

Won’t to do the trick…

Some examples or pointers to resources would be appreciated.

@doublemax


Here’s a two dimensional version. I change the object shapes for clarity (cylinder into a half cylinder and the cube into a shape square).
The objective is to move the cylinder on the left and position it where the cylinder on the right is relative to cubeA and CubeB.
Of course I need it to all work in three dimensions.
I think by working with transform.rotation and transform.position it can be done, unfortunately I’m having difficulty coming up with an approach. I was sort of hoping there was a built in function that would do it for me since the parent and child relationships depend upon this type of manipulation

PS: whenever I signe into my account, both the forom and answer websites breaks with a “too much recursion error”. I did not think anything was being posted until I received a notification email from your post.
My apologies if anything is getting duplicated or I don’t see a response. I’m not sure how to fix the issue.