# a puzzling thing happened to a simple problem on the rotation matrix

I have a simple problem which might be a bit off topic because I'm not sure if it is a problem of my coding or my formulation, but I can't solve it for days, so I decide to ask for some help: I have two unit vectors $a$ and $b$, which are normal to each other, then when $b$ is rotated by a rotation matrix $Q$, $a$ and $b$ becomes parallel to each other, and I'd like to find the condition on $Q$. I represented $Q$ with the Euler Rodrigues parameters, below is my code:

a = {1, 0, 0};
b0 = {0, Sqrt/2, -Sqrt/2};(*the initial position vector of b*)
(*Next,the rotation is given by the ERP parameters,vector r given as {x,y,z}*)
r = {x, y, z};
r0 = Sqrt[1 - x^2 - y^2 - z^2];
R = {{0, -r[], r[]}, {r[], 0, -r[]}, {-r[], r[],
0}};(*The cross product matrix of the axis*)
Q = Simplify[(r0^2 - Dot[r, r])*IdentityMatrix + 2*r0*R + 2*{{x}, {y}, {z}}.{{x, y, z}}];
MatrixForm[Q]
b = Simplify[Dot[Q, b0]]
product = Dot[a, b]
c1 = ContourPlot3D[product == 1, {x, -1, 1}, {y, -1, 1}, {z, -1, 1}]


Turns out the plot does not show anything, which means that this condition is not feasible, which is clearly not true. For example, according to a rough analysis, this condtion can be obtained at least via the following three rotations: firstly vector $b$ can be rotated about the direction $b_0$ for an arbitrary value; then, we rotate $b$ from $b0$ to $a$ via a rotation of 90 about the direction $Cross[b0,a]$, then, another rotation about $a$ for an arbitrary value. I have tried this which shows to have some solution; moreover, the intermediate rotation can be about other directions, as long as it can rotate $b$ from $b0$ to $a$.

So it is confusing to me why mathematica does not produce any plot. I tried to solve the constraint in terms of $x$, and found it gave me some complex number, which does not make sense. Could someone help? Thanks a lot!

Update I

no longer necessary, deleted.

Update II

after a long time of analysis, I finally found out why it does not plot. The condition above yields the two solutions of x in terms of y and z:

{{(y - z - I Abs[y - 2 y^3 + z - 2 y^2 z - 2 y z^2 - 2 z^3])/(  2 Sqrt (y^2 + z^2))}, {(  y - z + I Abs[y - 2 y^3 + z - 2 y^2 z - 2 y z^2 - 2 z^3])/(  2 Sqrt (y^2 + z^2))}}


which are two complex numbers (The above condition is essentially a quadratic equation), making me feel that there are no real solutions. But now I found that there can be real solutions, which happens when the discriminant vanishes, and in that case, I will get a curve instead of a surface.

so my remaining question is:

1. the ContourPlot3d can not handle curves? but somehow it plots some curves if b0 is assigned to $[0,1,0]$, which is contradictory to this conclusion.

2. I need to find the real part and complex part of these two solutions. But even if I have set the global assumption

$Assumptions = _Symbol [Element] Reals; at the beginning, the evaluation of$RE$does not work properly, as if it does not that$x,y,z$are real numbers. I wonder how to cope with this? Thanks a lot! • I'm a bit confused with your formulation, but RotationMatrix[{{0, Sqrt/2, -Sqrt/2}, {1, 0, 0}}] will yield the matrix that rotates {0, Sqrt/2, -Sqrt/2} to point to the same direction as {1, 0, 0}. If you want to generate the axis-angle representation of that, see this. – J. M.'s torpor Jan 31 '17 at 20:45 • @J.M., hi, thanks for your suggestion, but seems the code you offered only gives one specific rotation matrix, while what I need is all the possible rotations. Moreover, it seems that Mathematica has some trouble with the RotationMatrix[phi,axis] command when axis is symbolic, which returns a complex expression. I have tried the axis and angle representation of$Q\$ as well, but still it plots nothing. – larry Jan 31 '17 at 21:07
• @J.M. If you are interesting in knowing more about the rotation matrix, belong are two links: en.wikipedia.org/wiki/Euler%E2%80%93Rodrigues_formula and en.wikipedia.org/wiki/Axis%E2%80%93angle_representation – larry Jan 31 '17 at 21:11
• I'm actually aware of those (and I gave you a link to implementations of axis-angle conversion); so, if you have already fixed the source and target vector, then there is only one matrix that will rotate one to the other, no? Or were you looking for something like RotationMatrix[{{x, y, z}, {1, 0, 0}}] for variable x,y,z? As for complex expressions: that is due to the fact that Mathematica assumes everything is complex unless told otherwise; use Simplify[] + Assuming[] if you know your variables are real. – J. M.'s torpor Jan 31 '17 at 21:18
• @J.M. even though the source and target vectors are fixed, there can be infinitely many rotations that do the job. For example, the rotation can be obtained as the product of three matrices, mentioned in the problem statement. I will try to look at it again and thanks for your help. – larry Jan 31 '17 at 21:35

## 1 Answer

there are solutions, visualize like this:

ListPointPlot3D[{x, y, z} /.
FindInstance[product == 1, {x, y, z}, Reals, 200] // N,
PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}}] I'm not sure whats up with ContourPlot3D. Increasing PlotPoints doesn't seem to help.

• "I'm not sure what's up with ContourPlot3D" - I'd wager it's because ContourPlot3D[] was designed to render surfaces and not curves. – J. M.'s torpor Jan 31 '17 at 21:43