5

The following code:

RotationMatrix[{{0, 1, 0}, {0, -1, 0}}]

Gives an assertion message:

RotationMatrix::spln: Vectors {0,1,0} and {0,-1,0} do not define a plane.

Why can I define a RotationMatrix in this way?

Edit I found the reason in here: Calculate Rotation Matrix to align Vector A to Vector B, this is caused by the dot product of two vectors is -1,then the equation is divided by 0.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Chris Guo
  • 149
  • 8

2 Answers2

7

Edit

Another way is use perturbation.

u = {0, 1, 0};
v = {0, -1, 0};
m = Limit[RotationMatrix[{u, v + t*RandomInteger[20, 3]}], t -> 0]

{{0, 0, -1}, {0, -1, 0}, {-1, 0, 0}}

{{-(87/425), 0, -(416/425)}, {0, -1, 0}, {-(416/425), 0, 87/425}}

etc.

Original

We can find an orthogonal matrix satisfied $m^{T}\bullet m=\mathrm{Id},\mathrm{Det}(m)=1$ which transform $(0,1,0)$ to $(0,-1,0)$

m = Array[a, {3, 3}];
sol = Solve[{Transpose[m] . m == IdentityMatrix[3], 
     Det[m] == 1, {0, 1, 0} . m == {0, -1, 0}}][[1]];
m /. sol
({0, 1, 0} . m /. sol) == {0, -1, 0}

{{a[1, 1], 0, -Sqrt[1 - a[1, 1]^2]}, {0, -1, 0}, {-Sqrt[1 - a[1, 1]^2], 0, -a[1, 1]}}

True

For example we can set a[1,1]->1/2

{{1/2, 0, -(Sqrt[3]/2)}, {0, -1, 0}, {-(Sqrt[3]/2), 0, -(1/2)}}

cvgmt
  • 72,231
  • 4
  • 75
  • 133
  • 1
    Thanks. It doesn't look like a generic method(maybe I missed your point). e.g. If I want to rotate from{1, 0, 0} to {0, 1, 0} then your method failed. – Chris Guo Jul 22 '21 at 03:39
  • 1
    @ChrisGuo It also work. m = Array[a, {3, 3}]; u = {1, 0, 0}; v = {0, 1, 0}; sol = Solve[{Transpose[m] . m == IdentityMatrix[3], Det[m] == 1, u . m == v}][[1]]; u . (m /. sol ) == v – cvgmt Jul 22 '21 at 03:47
  • 1
    I still confused. If transforming from {x1,y1,z1} to {x2,y2,z2}, how could you solve the equations for m(it has 9 variables)? – Chris Guo Jul 22 '21 at 03:52
  • 1
    Thanks for the answer, after reading the post in here: link, I think maybe your method is a good workaround for this problem. – Chris Guo Jul 22 '21 at 06:04
4

This situation is another reason why I wrote the vectorRotate[] function in this answer, which implements the method of Möller and Hughes:

vectorRotate[{0, 1, 0}, {0, -1, 0}]
   {{-1, 0, 0}, {0, -1, 0}, {0, 0, 1}}
J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574