Virtual Testbed
Ship dynamics simulator for extreme conditions
inertia_tensor.hh
1 #ifndef VTESTBED_GEOMETRY_INERTIA_TENSOR_HH
2 #define VTESTBED_GEOMETRY_INERTIA_TENSOR_HH
3 
4 #include <vtestbed/geometry/types.hh>
5 
6 namespace vtb {
7 
8  namespace geometry {
9 
10  template <class T>
11  struct Inertia_tensor<T,2> {
12 
13  union { T x{}; T xx; };
14  union { T y{}; T yy; };
15  union { T xy{}; T yx; };
16 
17  inline void scale(T factor) { x *= factor, y *= factor, xy *= factor; }
18 
19  Rotation_matrix<T,2> matrix() const;
20 
21  };
22 
23  template <class T>
24  struct Inertia_tensor<T,3> {
25 
26  union { T x{}; T xx; };
27  union { T y{}; T yy; };
28  union { T z{}; T zz; };
29  union { T yz{}; T zy; };
30  union { T xz{}; T zx; };
31  union { T xy{}; T yx; };
32 
33  inline void
34  scale(T factor) {
35  x *= factor, y *= factor, z *= factor,
36  xy *= factor, xz *= factor, yz *= factor;
37  }
38 
39  Rotation_matrix<T,3> matrix() const;
40 
41  };
42 
43  template <class T>
44  struct Mass_moments<T,2> {
45 
46  Inertia_tensor<T,2> inertia;
47  Vertex<T,2> centre{T{}};
48  union { T mass{}; T area; };
49 
50  inline void
51  translate(const Vertex<T,2>& origin) {
52  Vertex<T,2> delta = origin - centre;
53  inertia.xx += mass*delta(1)*delta(1);
54  inertia.yy += mass*delta(0)*delta(0);
55  inertia.xy += mass*delta(0)*delta(1);
56  }
57 
58  };
59 
60  template <class T>
61  struct Mass_moments<T,3> {
62  Inertia_tensor<T,3> inertia;
63  Vertex<T,3> centre{T{}};
64  union { T mass{}; T volume; };
65  };
66 
67  template <class T>
68  void
69  check_matrix(const char* name, const Matrix<T,3>& m, const Matrix<T,3>& im);
70 
71  }
72 
73 }
74 
75 #endif // vim:filetype=cpp
Main namespace.
Definition: convert.hh:9