# Finding optimal rotation matrix

I have vectors E1 = {22.607, 3.495, -30.795}; and R1 = { 4.74061, 21.7549, 30.6501};. This vectors are conneted by a 3D rotation such that R1 = Rot. E1 Rot is the roation matrix (there can be some error due to measurment). How to find the optimal rotation matrix so that it can be applied to another set of vectors which goes through same transformation. PS. the other set is let's say E2 = {-13.236, 25.903, 13.937}; and R2 = {-17.5342, -26.6773, -0.10567};. Now we know only R2

• @MichaelE2 you mean FindGeometricTransform. – rhermans Jun 25 '18 at 12:44
• Note that with just E1 and R1, the answer is ambiguous. Given a rotation that takes E1 to R1, you may follow it with any rotation about the R1 axis and still have a correct result. Which result will take E2 to R2 is unpredictable without an additional constraint. – John Doty Jun 25 '18 at 12:45
• @John Exactly this is the point I was wondering. Could you please something more about the constrains? – Xavier Jun 25 '18 at 12:52
• @rhermans So much for going from memory. Thx. – Michael E2 Jun 25 '18 at 12:57
• @Xavier Please edit your question to explain what do you mean by "Optimal" and explain in detail what you really need. Please don't make us guess. – rhermans Jun 25 '18 at 13:17

## RotationMatrix

rotm = With[
{
e1 = {22.607, 3.495, -30.795},
r1 = {4.74061, 21.7549, 30.6501}
}
, (Norm[r1]/Norm[e1]) RotationMatrix[{e1, r1}]
];

MatrixForm[rotm]


rotm.{22.607, 3.495, -30.795}
(* {4.74061, 21.7549, 30.6501} *)


## TransformationFunction

transfunc = With[
{
e1 = {22.607, 3.495, -30.795},
r1 = {4.74061, 21.7549, 30.6501}
},
Last@FindGeometricTransform[{r1}, {e1}]
]

transfunc[{22.607, 3.495, -30.795}]
(* {4.74061, 21.7549, 30.6501} *)