aimstil  5.0.5
matrix3Tools.h
Go to the documentation of this file.
1 #ifndef TIL_MATRIX3_TOOLS_H
2 #define TIL_MATRIX3_TOOLS_H
3 
5 
6 
7 namespace til
8 {
9 
10  //---------------------------------------------------------------------------
11 
13  template < typename T1, typename T2, typename T3 >
14  void
15  apply
16  (
17  Matrix3<T1> const & mat
18  , numeric_array<T2,3> const & vec
19  , numeric_array<T3,3> & vecout
20  )
21  {
22  for (std::size_t j = 0; j < 3; ++j)
23  {
24  vecout[j] = mat(0,j) * vec[0];
25  }
26  for (std::size_t i = 1; i < 3; ++i)
27  {
28  T2 veci = vec[i];
29  for (std::size_t j = 0; j < 3; ++j)
30  {
31  vecout[j] += mat(i,j) * veci ;
32  }
33  }
34  }
35 
36  //---------------------------------------------------------------------------
37 
39  template < typename T1, typename T2, typename T3 >
40  void
41  apply_t
42  (
43  Matrix3<T1> const & mat
44  , numeric_array<T2,3> const & vec
45  , numeric_array<T3,3> & vecout
46  )
47  {
48  for (std::size_t j = 0; j < 3; ++j)
49  {
50  vecout[j] = mat(j,0) * vec[0];
51  }
52  for (std::size_t i = 1; i < 3; ++i)
53  {
54  T2 veci = vec[i];
55  for (std::size_t j = 0; j < 3; ++j)
56  {
57  vecout[j] += mat(j,i) * veci;
58  }
59  }
60  }
61 
62  //---------------------------------------------------------------------------
63 
64  /*
65  template < typename TMatrix, typename TVector >
66  TMatrix diag(const TVector & v)
67  {
68  TMatrix m;
69  redim(m, i, i);
70  fill(m, typename value_type_of<TMatrix>::type(0));
71  for (std::size_t i = 0; i < size(v); ++i)
72  {
73  m(i,i) = v(i);
74  }
75  }
76  */
77 
78  template < typename T >
79  T det(const Matrix3<T> & m)
80  {
81  return m(0,0)*m(1,1)*m(2,2)+m(1,0)*m(2,1)*m(0,2)+m(2,0)*m(0,1)*m(1,2) -
82  m(0,2)*m(1,1)*m(2,0)-m(1,2)*m(2,1)*m(0,0)-m(2,2)*m(0,1)*m(1,0);
83  }
84 
85  /*
87  template < typename TPrec, typename TMatrix >
88  TPrec det(const TMatrix &m)
89  {
90  assert(m.dims()[0] == m.dims()[1]);
91  std::size_t n = m.dims()[0];
92  // Actually we need to extract the first row, in the same format as the underlying data.
93  typename TMatrix::row_type x;
94  resize(x, n);
95  std::copy(m.begin(), m.begin()+n, x.begin());
96  // Actually we need a cyclic iterator here. Or a cyclic range for that matter
97  for (std::size_t i = 1; i < n; ++i)
98  {
99  x[i] *= m( (i+1) % n, i);
100  }
101  TPrec res = x[n-1];
102  for (int i = n-2; i >= 0; --i)
103  {
104  res = x[i] - res;
105  }
106  return res;
107  }
108  */
109  //} // namespace linalg
110 } // namespace til
111 
112 #endif
113 
INLINE void apply(const Affine< T1 > &a, const numeric_array< T2, 3 > &in, numeric_array< typename combine< T1, T2 >::type, 3 > &out)
Belongs to package Box Do not include directly, include til/Box.h instead.
Definition: Accumulator.h:10
void apply_t(Matrix3< T1 > const &mat, numeric_array< T2, 3 > const &vec, numeric_array< T3, 3 > &vecout)
compute transpose(mat) * in
Definition: matrix3Tools.h:42
A mathematical matrix.
Definition: Matrix3.h:90
T det(const Matrix3< T > &m)
Definition: matrix3Tools.h:79