4
$\begingroup$

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.

$\endgroup$
1
  • 3
    $\begingroup$ Your vectors are colinear, so do not define a unique rotation axis. $\endgroup$ – mikado Jul 22 at 5:47
6
$\begingroup$

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)}}

$\endgroup$
4
  • 1
    $\begingroup$ 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. $\endgroup$ – Chris Guo Jul 22 at 3:39
  • 1
    $\begingroup$ @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 $\endgroup$ – cvgmt Jul 22 at 3:47
  • 1
    $\begingroup$ 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)? $\endgroup$ – Chris Guo Jul 22 at 3:52
  • 1
    $\begingroup$ Thanks for the answer, after reading the post in here: link, I think maybe your method is a good workaround for this problem. $\endgroup$ – Chris Guo Jul 22 at 6:04
3
$\begingroup$

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}}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.