# Sequential 3D transformations

I have a function s[x,y,z] that assumes a reference of centered at the origin and pointed along the positive z axis. Given two points, I want to rotate and translate that function such that its center is now at the midpoint of the two points and it is rotated to point toward the second of the points. I can do it sequentially with two operators like so:

rot[p1_,p2_]@f_:=f@@RotationTransform[{Normalize[p2-p1],{0,0,1}}][{x,y,z}]
rs[x_,y_,z_]=rot[point1,point2]@s
trans[p1_,p2_]@f_:=f@@TranslationTransform[-(p2+p1)/2][{x,y,z}]
trs[x_,y_,z_]=trans[point1,point2]@rs


However, I cannot seem to write an operator that does both correctly. This seems like it should work, and yet does not.

move[p1_,p2_]@f_:=f@@(Composition[TranslationTransform[-(p2+p1)/2],
RotationTransform[{Normalize[p1-p2],{0,0,1}}]][{x, y, z}])


The rotation seems fine, but the translation is off. Help?

Edited to add: Here is a test function and some initial points (midpoint at origin, displaced equally along z axis).

Here is some code showing the starting conditions:

Here is some code showing the desired outcome (the two points that will be passed, the vector for the direction I want it pointing, and the midpoint where I want the origin translated to).

When I use the two individual operators in sequence, I get the correct output:

But when I try to use the composite operator, I get this:

• does move[p1_, p2_]@ f_ := (Composition[f @@ TranslationTransform[-(p2 + p1)/2], f @@ RotationTransform[{Normalize[p1 - p2], {0, 0, 1}}]][{x, y, z}]) work? – kglr Nov 2 '18 at 21:43
• Doesn't seem to. In fact that version doesn't seem to operate on s at all. I am modifying my original post to include a test function. – Kevin Ausman Nov 2 '18 at 21:59
• move[point1, point2]@s gives s[1/2 (-point1 - point2)][ s[{(point1 - point2)/Norm[point1 - point2], {0, 0, 1}}][{x, y, z}]] – kglr Nov 2 '18 at 22:01
• Yes, and if I have a function defined for s and plug in actual values for the points, your version gives me: s[{{1., 0, 0, 0.6405}, {0, 1., 0, 0.6325}, {0, 0, 1., 1.796}, {0, 0, 0, 1.}}] s[{{0.910166, 0.0403062, -0.412279, 0.}, {0.0403062, 0.981916, 0.184979, 0.}, {0.412279, -0.184979, 0.892081, 0.}, {0., 0., 0., 1.}}][x, y, z]] – Kevin Ausman Nov 2 '18 at 22:18
• ah i see , thanks – kglr Nov 2 '18 at 22:20

move3[p1_, p2_]@f_ := Block[{tmp, pt},