Created
June 17, 2017 16:42
-
-
Save quantumelixir/7152258eb86645577b5054d8282a402b to your computer and use it in GitHub Desktop.
Rotation Matrix in 3D
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In[79]:= Rz[x_] := ( { | |
{Cos[x], -Sin[x], 0}, | |
{Sin[x], Cos[x], 0}, | |
{0, 0, 1} | |
} ); | |
Ry[x_] := ( { | |
{Cos[x], 0, Sin[x]}, | |
{0, 1, 0}, | |
{-Sin[x], 0, Cos[x]} | |
} ); | |
R[a_, b_, c_, \[Theta]_] := | |
Rz[-Subscript[\[Theta], 1]].Ry[-Subscript[\[Theta], | |
2]].Rz[\[Theta]].Ry[Subscript[\[Theta], 2]].Rz[ | |
Subscript[\[Theta], 1]] /. {Subscript[\[Theta], 1] -> | |
ArcSin[b/Sqrt[1 - c^2]], | |
Subscript[\[Theta], 2] -> ArcSin[Sqrt[1 - c^2]]}; | |
Assuming[Element[Subscript[u, x], Reals] && | |
Element[Subscript[u, y], Reals] && Element[Subscript[u, z], Reals], | |
FullSimplify[ | |
R[Subscript[u, x], Subscript[u, y], Subscript[u, | |
z], \[Theta]]]] // MatrixForm | |
Out[82]//MatrixForm= \!\( | |
TagBox[ | |
RowBox[{"(", "", GridBox[{ | |
{ | |
RowBox[{"1", "+", | |
RowBox[{ | |
RowBox[{"(", | |
RowBox[{ | |
RowBox[{"-", "1"}], "+", | |
RowBox[{"Cos", "[", "\[Theta]", "]"}]}], ")"}], " ", | |
SubsuperscriptBox["u", "y", "2"]}], "+", | |
RowBox[{ | |
RowBox[{"(", | |
RowBox[{ | |
RowBox[{"-", "1"}], "+", | |
RowBox[{"Cos", "[", "\[Theta]", "]"}]}], ")"}], " ", | |
SubsuperscriptBox["u", "z", "2"]}]}], | |
RowBox[{ | |
RowBox[{"-", "2"}], " ", | |
RowBox[{"Sin", "[", | |
FractionBox["\[Theta]", "2"], "]"}], " ", | |
RowBox[{"(", | |
RowBox[{ | |
RowBox[{ | |
RowBox[{"Abs", "[", | |
SubscriptBox["u", "z"], "]"}], " ", | |
RowBox[{"Cos", "[", | |
FractionBox["\[Theta]", "2"], "]"}]}], "+", | |
RowBox[{ | |
RowBox[{"Sin", "[", | |
FractionBox["\[Theta]", "2"], "]"}], " ", | |
SubscriptBox["u", "y"], " ", | |
SqrtBox[ | |
RowBox[{"1", "-", | |
SubsuperscriptBox["u", "z", "2"]}]], " ", | |
SqrtBox[ | |
FractionBox[ | |
RowBox[{ | |
RowBox[{"-", "1"}], "+", | |
SubsuperscriptBox["u", "y", "2"], "+", | |
SubsuperscriptBox["u", "z", "2"]}], | |
RowBox[{ | |
RowBox[{"-", "1"}], "+", | |
SubsuperscriptBox["u", "z", "2"]}]]]}]}], ")"}]}], | |
RowBox[{"2", " ", | |
RowBox[{"Sin", "[", | |
FractionBox["\[Theta]", "2"], "]"}], " ", | |
RowBox[{"(", | |
RowBox[{ | |
RowBox[{ | |
RowBox[{"Cos", "[", | |
FractionBox["\[Theta]", "2"], "]"}], " ", | |
SubscriptBox["u", "y"]}], "-", | |
RowBox[{ | |
RowBox[{"Abs", "[", | |
SubscriptBox["u", "z"], "]"}], " ", | |
RowBox[{"Sin", "[", | |
FractionBox["\[Theta]", "2"], "]"}], " ", | |
SqrtBox[ | |
RowBox[{"1", "-", | |
SubsuperscriptBox["u", "z", "2"]}]], " ", | |
SqrtBox[ | |
FractionBox[ | |
RowBox[{ | |
RowBox[{"-", "1"}], "+", | |
SubsuperscriptBox["u", "y", "2"], "+", | |
SubsuperscriptBox["u", "z", "2"]}], | |
RowBox[{ | |
RowBox[{"-", "1"}], "+", | |
SubsuperscriptBox["u", "z", "2"]}]]]}]}], ")"}]}]}, | |
{ | |
RowBox[{"2", " ", | |
RowBox[{"Sin", "[", | |
FractionBox["\[Theta]", "2"], "]"}], " ", | |
RowBox[{"(", | |
RowBox[{ | |
RowBox[{ | |
RowBox[{"Abs", "[", | |
SubscriptBox["u", "z"], "]"}], " ", | |
RowBox[{"Cos", "[", | |
FractionBox["\[Theta]", "2"], "]"}]}], "-", | |
RowBox[{ | |
RowBox[{"Sin", "[", | |
FractionBox["\[Theta]", "2"], "]"}], " ", | |
SubscriptBox["u", "y"], " ", | |
SqrtBox[ | |
RowBox[{"1", "-", | |
SubsuperscriptBox["u", "z", "2"]}]], " ", | |
SqrtBox[ | |
FractionBox[ | |
RowBox[{ | |
RowBox[{"-", "1"}], "+", | |
SubsuperscriptBox["u", "y", "2"], "+", | |
SubsuperscriptBox["u", "z", "2"]}], | |
RowBox[{ | |
RowBox[{"-", "1"}], "+", | |
SubsuperscriptBox["u", "z", "2"]}]]]}]}], ")"}]}], | |
RowBox[{ | |
RowBox[{"Cos", "[", "\[Theta]", "]"}], "-", | |
RowBox[{ | |
RowBox[{"(", | |
RowBox[{ | |
RowBox[{"-", "1"}], "+", | |
RowBox[{"Cos", "[", "\[Theta]", "]"}]}], ")"}], " ", | |
SubsuperscriptBox["u", "y", "2"]}]}], | |
RowBox[{ | |
RowBox[{ | |
RowBox[{"-", | |
RowBox[{"Abs", "[", | |
SubscriptBox["u", "z"], "]"}]}], " ", | |
RowBox[{"(", | |
RowBox[{ | |
RowBox[{"-", "1"}], "+", | |
RowBox[{"Cos", "[", "\[Theta]", "]"}]}], ")"}], " ", | |
SubscriptBox["u", "y"]}], "+", | |
RowBox[{ | |
RowBox[{"Sin", "[", "\[Theta]", "]"}], " ", | |
SqrtBox[ | |
RowBox[{"1", "-", | |
SubsuperscriptBox["u", "z", "2"]}]], " ", | |
SqrtBox[ | |
FractionBox[ | |
RowBox[{ | |
RowBox[{"-", "1"}], "+", | |
SubsuperscriptBox["u", "y", "2"], "+", | |
SubsuperscriptBox["u", "z", "2"]}], | |
RowBox[{ | |
RowBox[{"-", "1"}], "+", | |
SubsuperscriptBox["u", "z", "2"]}]]]}]}]}, | |
{ | |
RowBox[{ | |
RowBox[{"-", "2"}], " ", | |
RowBox[{"Sin", "[", | |
FractionBox["\[Theta]", "2"], "]"}], " ", | |
RowBox[{"(", | |
RowBox[{ | |
RowBox[{ | |
RowBox[{"Cos", "[", | |
FractionBox["\[Theta]", "2"], "]"}], " ", | |
SubscriptBox["u", "y"]}], "+", | |
RowBox[{ | |
RowBox[{"Abs", "[", | |
SubscriptBox["u", "z"], "]"}], " ", | |
RowBox[{"Sin", "[", | |
FractionBox["\[Theta]", "2"], "]"}], " ", | |
SqrtBox[ | |
RowBox[{"1", "-", | |
SubsuperscriptBox["u", "z", "2"]}]], " ", | |
SqrtBox[ | |
FractionBox[ | |
RowBox[{ | |
RowBox[{"-", "1"}], "+", | |
SubsuperscriptBox["u", "y", "2"], "+", | |
SubsuperscriptBox["u", "z", "2"]}], | |
RowBox[{ | |
RowBox[{"-", "1"}], "+", | |
SubsuperscriptBox["u", "z", "2"]}]]]}]}], ")"}]}], | |
RowBox[{ | |
RowBox[{ | |
RowBox[{"-", | |
RowBox[{"Abs", "[", | |
SubscriptBox["u", "z"], "]"}]}], " ", | |
RowBox[{"(", | |
RowBox[{ | |
RowBox[{"-", "1"}], "+", | |
RowBox[{"Cos", "[", "\[Theta]", "]"}]}], ")"}], " ", | |
SubscriptBox["u", "y"]}], "-", | |
RowBox[{ | |
RowBox[{"Sin", "[", "\[Theta]", "]"}], " ", | |
SqrtBox[ | |
RowBox[{"1", "-", | |
SubsuperscriptBox["u", "z", "2"]}]], " ", | |
SqrtBox[ | |
FractionBox[ | |
RowBox[{ | |
RowBox[{"-", "1"}], "+", | |
SubsuperscriptBox["u", "y", "2"], "+", | |
SubsuperscriptBox["u", "z", "2"]}], | |
RowBox[{ | |
RowBox[{"-", "1"}], "+", | |
SubsuperscriptBox["u", "z", "2"]}]]]}]}], | |
RowBox[{ | |
RowBox[{"Cos", "[", "\[Theta]", "]"}], "-", | |
RowBox[{ | |
RowBox[{"(", | |
RowBox[{ | |
RowBox[{"-", "1"}], "+", | |
RowBox[{"Cos", "[", "\[Theta]", "]"}]}], ")"}], " ", | |
SubsuperscriptBox["u", "z", "2"]}]}]} | |
}, | |
GridBoxAlignment->{ | |
"Columns" -> {{Center}}, "ColumnsIndexed" -> {}, | |
"Rows" -> {{Baseline}}, "RowsIndexed" -> {}}, | |
GridBoxSpacings->{"Columns" -> { | |
Offset[0.27999999999999997`], { | |
Offset[0.7]}, | |
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> { | |
Offset[0.2], { | |
Offset[0.4]}, | |
Offset[0.2]}, "RowsIndexed" -> {}}], "", ")"}], | |
Function[BoxForm`e$, | |
MatrixForm[BoxForm`e$]]]\) | |
In[66]:= Assuming[ | |
Subscript[u, x]*Subscript[u, x] + Subscript[u, y]*Subscript[u, y] + | |
Subscript[u, z]*Subscript[u, z] == 1 && | |
Element[Subscript[u, x], Reals] && | |
Element[Subscript[u, y], Reals] && | |
Element[Subscript[u, z], Reals] && Subscript[u, z] >= 0, | |
FullSimplify[ | |
R[Subscript[u, x], Subscript[u, y], Subscript[u, | |
z], \[Theta]]]] // MatrixForm | |
Out[66]//MatrixForm= \!\( | |
TagBox[ | |
RowBox[{"(", "", GridBox[{ | |
{ | |
RowBox[{"1", "+", | |
RowBox[{ | |
RowBox[{"(", | |
RowBox[{ | |
RowBox[{"-", "1"}], "+", | |
RowBox[{"Cos", "[", "\[Theta]", "]"}]}], ")"}], " ", | |
SubsuperscriptBox["u", "y", "2"]}], "+", | |
RowBox[{ | |
RowBox[{"(", | |
RowBox[{ | |
RowBox[{"-", "1"}], "+", | |
RowBox[{"Cos", "[", "\[Theta]", "]"}]}], ")"}], " ", | |
SubsuperscriptBox["u", "z", "2"]}]}], | |
RowBox[{ | |
RowBox[{ | |
RowBox[{"-", | |
RowBox[{"Sin", "[", "\[Theta]", "]"}]}], " ", | |
SubscriptBox["u", "z"]}], "+", | |
RowBox[{ | |
RowBox[{"(", | |
RowBox[{ | |
RowBox[{"-", "1"}], "+", | |
RowBox[{"Cos", "[", "\[Theta]", "]"}]}], ")"}], " ", | |
SubscriptBox["u", "y"], " ", | |
SqrtBox[ | |
RowBox[{"1", "-", | |
SubsuperscriptBox["u", "y", "2"], "-", | |
SubsuperscriptBox["u", "z", "2"]}]]}]}], | |
RowBox[{ | |
RowBox[{ | |
RowBox[{"Sin", "[", "\[Theta]", "]"}], " ", | |
SubscriptBox["u", "y"]}], "+", | |
RowBox[{ | |
RowBox[{"(", | |
RowBox[{ | |
RowBox[{"-", "1"}], "+", | |
RowBox[{"Cos", "[", "\[Theta]", "]"}]}], ")"}], " ", | |
SubscriptBox["u", "z"], " ", | |
SqrtBox[ | |
RowBox[{"1", "-", | |
SubsuperscriptBox["u", "y", "2"], "-", | |
SubsuperscriptBox["u", "z", "2"]}]]}]}]}, | |
{ | |
RowBox[{ | |
RowBox[{ | |
RowBox[{"Sin", "[", "\[Theta]", "]"}], " ", | |
SubscriptBox["u", "z"]}], "+", | |
RowBox[{ | |
RowBox[{"(", | |
RowBox[{ | |
RowBox[{"-", "1"}], "+", | |
RowBox[{"Cos", "[", "\[Theta]", "]"}]}], ")"}], " ", | |
SubscriptBox["u", "y"], " ", | |
SqrtBox[ | |
RowBox[{"1", "-", | |
SubsuperscriptBox["u", "y", "2"], "-", | |
SubsuperscriptBox["u", "z", "2"]}]]}]}], | |
RowBox[{ | |
RowBox[{"Cos", "[", "\[Theta]", "]"}], "+", | |
RowBox[{ | |
RowBox[{"(", | |
RowBox[{"1", "-", | |
RowBox[{"Cos", "[", "\[Theta]", "]"}]}], ")"}], " ", | |
SubsuperscriptBox["u", "y", "2"]}]}], | |
RowBox[{ | |
RowBox[{ | |
RowBox[{"(", | |
RowBox[{"1", "-", | |
RowBox[{"Cos", "[", "\[Theta]", "]"}]}], ")"}], " ", | |
SubscriptBox["u", "y"], " ", | |
SubscriptBox["u", "z"]}], "+", | |
RowBox[{ | |
RowBox[{"Sin", "[", "\[Theta]", "]"}], " ", | |
SqrtBox[ | |
RowBox[{"1", "-", | |
SubsuperscriptBox["u", "y", "2"], "-", | |
SubsuperscriptBox["u", "z", "2"]}]]}]}]}, | |
{ | |
RowBox[{ | |
RowBox[{ | |
RowBox[{"-", | |
RowBox[{"Sin", "[", "\[Theta]", "]"}]}], " ", | |
SubscriptBox["u", "y"]}], "+", | |
RowBox[{ | |
RowBox[{"(", | |
RowBox[{ | |
RowBox[{"-", "1"}], "+", | |
RowBox[{"Cos", "[", "\[Theta]", "]"}]}], ")"}], " ", | |
SubscriptBox["u", "z"], " ", | |
SqrtBox[ | |
RowBox[{"1", "-", | |
SubsuperscriptBox["u", "y", "2"], "-", | |
SubsuperscriptBox["u", "z", "2"]}]]}]}], | |
RowBox[{ | |
RowBox[{ | |
RowBox[{"(", | |
RowBox[{"1", "-", | |
RowBox[{"Cos", "[", "\[Theta]", "]"}]}], ")"}], " ", | |
SubscriptBox["u", "y"], " ", | |
SubscriptBox["u", "z"]}], "-", | |
RowBox[{ | |
RowBox[{"Sin", "[", "\[Theta]", "]"}], " ", | |
SqrtBox[ | |
RowBox[{"1", "-", | |
SubsuperscriptBox["u", "y", "2"], "-", | |
SubsuperscriptBox["u", "z", "2"]}]]}]}], | |
RowBox[{ | |
RowBox[{"Cos", "[", "\[Theta]", "]"}], "+", | |
RowBox[{ | |
RowBox[{"(", | |
RowBox[{"1", "-", | |
RowBox[{"Cos", "[", "\[Theta]", "]"}]}], ")"}], " ", | |
SubsuperscriptBox["u", "z", "2"]}]}]} | |
}, | |
GridBoxAlignment->{ | |
"Columns" -> {{Center}}, "ColumnsIndexed" -> {}, | |
"Rows" -> {{Baseline}}, "RowsIndexed" -> {}}, | |
GridBoxSpacings->{"Columns" -> { | |
Offset[0.27999999999999997`], { | |
Offset[0.7]}, | |
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> { | |
Offset[0.2], { | |
Offset[0.4]}, | |
Offset[0.2]}, "RowsIndexed" -> {}}], "", ")"}], | |
Function[BoxForm`e$, | |
MatrixForm[BoxForm`e$]]]\) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment