www.mooseframework.org
RotationMatrix.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #include "RotationMatrix.h"
16 
19 // provides a rotation matrix that will rotate the vector vec to the z axis (the "2" direction)
20 {
21  // ensure that vec is normalised
22  vec /= std::sqrt(vec * vec);
23 
24  // construct v0 and v1 to be orthonormal to vec
25  // and form a RH basis, that is, so v1 x vec = v0
26 
27  // Use Gram-Schmidt method to find v1.
28  RealVectorValue v1;
29  // Need a prototype for v1 first, and this is done by looking at the smallest component of vec
30  RealVectorValue w(std::abs(vec(0)), std::abs(vec(1)), std::abs(vec(2)));
31  if ((w(2) >= w(1) && w(1) >= w(0)) || (w(1) >= w(2) && w(2) >= w(0)))
32  // vec(0) is the smallest component
33  v1(0) = 1;
34  else if ((w(2) >= w(0) && w(0) >= w(1)) || (w(0) >= w(2) && w(2) >= w(1)))
35  // vec(1) is the smallest component
36  v1(1) = 1;
37  else
38  // vec(2) is the smallest component
39  v1(2) = 1;
40  // now Gram-Schmidt
41  v1 -= (v1 * vec) * vec;
42  v1 /= std::sqrt(v1 * v1);
43 
44  // now use v0 = v1 x vec
45  RealVectorValue v0;
46  v0(0) = v1(1) * vec(2) - v1(2) * vec(1);
47  v0(1) = v1(2) * vec(0) - v1(0) * vec(2);
48  v0(2) = v1(0) * vec(1) - v1(1) * vec(0);
49 
50  // the desired rotation matrix is just
51  RealTensorValue rot(v0(0), v0(1), v0(2), v1(0), v1(1), v1(2), vec(0), vec(1), vec(2));
52  return rot;
53 }
54 
57 // provides a rotation matrix that will rotate the vector vec1 to the vector vec2
58 {
59  RealTensorValue rot1_to_z = rotVecToZ(vec1);
60  RealTensorValue rot2_to_z = rotVecToZ(vec2);
61  return rot2_to_z.transpose() * rot1_to_z;
62 }
VectorValue< Real > RealVectorValue
Definition: Assembly.h:40
RealTensorValue rotVec1ToVec2(RealVectorValue vec1, RealVectorValue vec2)
provides a rotation matrix that will rotate the vector vec1 to vec2
RealTensorValue rotVecToZ(RealVectorValue vec)
provides a rotation matrix that will rotate the vector vec to the z axis (the "2" direction) ...
TensorValue< Real > RealTensorValue
Definition: Assembly.h:45