# Rotating Vectors in space

I have two sets of vectors,

(* SET_1:  *)

A0 = {-23.645, 8.761, 19.186};
A1 = {8.909, 11.977, -26.572};
A2 = { 6.098, 8.537, 31.834};
A3 = {9.866, -32.131, -24.569};

(* SET_2:  *)

B0 = {-13.9469, 28.7731, -3.21699};
B1 = {-13.8077, -27.3636, 0.329735};
B2 = {2.94231, 23.5992, 23.8511};
B3 = {24.8123, -25.0087, -20.9639};


These two sets are such that A0 = B0, A1=B1, A2=B2, and A3=B3 (Let's say within experimental error) but only rotated in 3d space. Now is there any way to know the rotation axis and angle of this transformation so that I can use this information for future use.

• Sorry, I didn't get the question: Are you looking for the rotationmatrix R which maps  A[i]->B[i]: B[i]=R.A[i]? – Ulrich Neumann Jun 8 '18 at 9:56
• @Ulrich..Yes I am looking for single rotation matrix which can transform Set A[i]->B[i] – Bikash Jun 8 '18 at 10:05
• By the way, the map you are looking for seems to be a reflection, not a rotation. – Ulrich Neumann Jun 11 '18 at 8:41
• It seems like that when we only use TransformationClass -> "Rigid". But if you add Method -> "FindFit", then it looks like in a rotating frame. – Bikash Jun 11 '18 at 9:00
• No it's another point: The determinant of the transformation matrix equals -1 which indicates that the transformation is no rotation! – Ulrich Neumann Jun 11 '18 at 9:10

I think you want a single transformation function for all points, rather than one for each point independently as kglr's answer currently shows.

set1 = {A0, A1, A2, A3};
set2 = {B0, B1, B2, B3};

tF2 = FindGeometricTransform[
set1, set2
, TransformationClass -> "Rigid"
, Method -> "FindFit"
][];

Graphics3D[{
{Red, PointSize[Large], Point[set1]},
{Opacity[.15, Blue], Sphere[tF2@set2, 2]}
}] • Thanks...you got my point!! – Bikash Jun 8 '18 at 10:55
• Just one remark: FindGeometricTransformation is a nonlinear map. You have to use the option TransformationClass -> "Rigid" to get correct results – Ulrich Neumann Jun 8 '18 at 11:04
• Hi..I was working with this transformation, I guess one should use TransformationClass -> "Similarity"...any comment? – Bikash Jun 8 '18 at 13:39
• TransformationClass -> "Similarity" includes scaling beside translation and rotation! – Ulrich Neumann Jun 8 '18 at 13:56
• @Ulrich Thank you, I will amend this answer. – Mr.Wizard Jun 9 '18 at 8:21

If you are looking for a map R.A[i]~B[i] ,i,0,1,2,3 : First you have to define the rotationmatrix R

 ϕ = {{0, -φ3, φ2}, {φ3,0,-φ1}, {-φ2, φ1, 0}};
φ = Simplify[Sqrt[Tr[-ϕ.ϕ/2]]]
R = IdentityMatrix + Sin[φ]/φ ϕ + (1 - Cos[φ])/φ^2 ϕ.ϕ ;


which depends on φ1, φ2, φ3

Now you can calculate the optimal rotation parameters φ1, φ2, φ3

 J = Total@MapThread[(R.#1 - #2 ).(R.#1 - #2 ) &, {{A0, A1, A2, A3},{B0, B1, B2, B3}}]
sol=NMinimize[J, {φ1, φ2, φ3}]
(* {2061.5, {φ1 -> -1.01538, φ2 ->1.45343, φ3 -> 1.3975}} *)


The optimal rotationmatrix is

Ropt=R /.sol[]
(*{{-0.303462, -0.951876, 0.0429177},
{0.00554758, 0.043276,0.999048},
{-0.952827, 0.303411, -0.007852}} *)

Ropt.Transpose[Ropt] (*test:  should be identitymatrix *)

• Thank you very much!! – Bikash Jun 8 '18 at 11:24

You can use FindGeometricTransform:

tFs = MapThread[FindGeometricTransform[{#}, {#2}][] &,
{{A0, A1, A2, A3}, {B0, B1, B2, B3}}];

Graphics3D[{Red, PointSize[Large], Point[{A0, A1, A2, A3}], Opacity[.15, Blue],
MapThread[Sphere[#@#2, 2] &, {tFs, {B0, B1, B2, B3}}]}] • I interpret this differently; CW below. – Mr.Wizard Jun 8 '18 at 10:11
• @Mr.Wizard, good point. That possibility didn't occur to me. – kglr Jun 8 '18 at 10:18
• Thank you very much guys – Bikash Jun 8 '18 at 11:22