MakeCoordinateSystem.hpp
Go to the documentation of this file.
1 // ========================================================================================
2 // ApproxMVBB
3 // Copyright (C) 2014 by Gabriel Nützi <nuetzig (at) imes (d0t) mavt (d0t) ethz (døt) ch>
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 // ========================================================================================
9 
10 #ifndef ApproxMVBB_MakeCoordinateSystem_hpp
11 #define ApproxMVBB_MakeCoordinateSystem_hpp
12 
13 #include <cmath>
15 #include ApproxMVBB_TypeDefs_INCLUDE_FILE
16 
17 namespace ApproxMVBB{
18 namespace CoordinateSystem {
19 
21 
27 /* @{ */
35 inline void makeCoordinateSystem( Vector3 &v1,
36  Vector3 &v2,
37  Vector3 &v3)
38 {
39 
40  using std::abs;
41  using std::sqrt;
42 
43  v1.normalize();
44 
45  if(abs(v1(0)) > abs(v1(2))){
46  PREC invLen = 1.0 / sqrt(v1(0)*v1(0) + v1(2) * v1(2));
47  v2 = MyMatrix::Vector3<PREC>(-v1(2) * invLen, 0, v1(0) *invLen);
48  }
49  else{
50  PREC invLen = 1.0 / sqrt(v1(1)*v1(1) + v1(2) * v1(2));
51  v2 = MyMatrix::Vector3<PREC>(0, v1(2) * invLen, -v1(1) *invLen);
52  }
53  v3 = v1.cross(v2);
54 
55  v2.normalize();
56  v3.normalize();
57 
58 }
59 
60 
61 inline void makeZAxisUp(Matrix33 & A_IK){
62  // Make the z-Axis the axis which has the greatest z-component
63 
64  if(A_IK(0,2) > A_IK(1,2) && A_IK(0,2) > A_IK(2,2)){
65  // x Axis becomes new z-Axis [x,y,z] -> [y,z,x]
66  A_IK.col(0).swap(A_IK.col(2));
67  A_IK.col(0).swap(A_IK.col(1));
68  }else if(A_IK(1,2) > A_IK(0,2) && A_IK(1,2) > A_IK(2,2)){
69  // y Axis becomes new z-Axis [x,y,z] -> [y,z,y]
70  A_IK.col(0).swap(A_IK.col(2));
71  A_IK.col(1).swap(A_IK.col(2));
72  }
73 }
74 
75 
76 inline bool checkOrthogonality(Vector3 &v1,
77  Vector3 &v2,
78  Vector3 &v3,
79  PREC eps = 1e-6)
80 {
81 
82  if(v1.dot(v2) <= eps && v2.dot(v3) <= eps && v3.dot(v1) <= eps){
83  return true;
84  }
85  return false;
86 }
87 
88 /* @} */
89 
90 }
91 }
92 #endif
These are some container definitions.
Eigen::Matrix< Scalar, 3, 3 > Matrix33
void makeCoordinateSystem(Vector3 &v1, Vector3 &v2, Vector3 &v3)
This function makes an orthogonal normed right-hand coordinate system. If the z-axis is the input...
bool checkOrthogonality(Vector3 &v1, Vector3 &v2, Vector3 &v3, PREC eps=1e-6)
Eigen::Matrix< Scalar, 3, 1 > Vector3
#define ApproxMVBB_DEFINE_MATRIX_TYPES
Definition: TypeDefs.hpp:26


asr_approx_mvbb
Author(s): Gassner Nikolai
autogenerated on Mon Jun 10 2019 12:38:08