5 #include <vtestbed/config/real_type.hh> 6 #include <vtestbed/core/ship.hh> 7 #include <vtestbed/core/types.hh> 8 #include <vtestbed/geometry/basis.hh> 9 #include <vtestbed/geometry/inertia_tensor.hh> 10 #include <vtestbed/geometry/quaternion.hh> 15 this->_hull = std::move(rhs);
16 this->_inertia_matrix = this->_hull.mass_moments().inertia.matrix();
17 this->_mass = this->_hull.mass();
24 this->_inertia_matrix = this->_hull.
mass_moments().inertia.matrix();
25 this->_mass = this->_hull.mass();
32 for (
const auto& room : compartments()) { sum += room.flooded_mass(); }
39 const auto& R = rotation_matrix();
40 const auto& R_inv = inverse(R);
41 const auto& I_body = inertia_matrix();
42 angular_displacement(1, angvelocity);
43 angular_momentum(R*(I_body*(R_inv*angvelocity)));
49 quaternion(vtb::geometry::from_euler_angles(angles));
55 using vtb::geometry::rotation_matrix;
56 this->_quaternion = q;
57 this->_rotation_matrix = rotation_matrix(q);
64 v.position = position(0);
65 v.velocity = position(1);
66 v.quaternion = quaternion();
67 v.angmomentum = angular_momentum();
74 auto old_position_1 = position(1);
75 auto old_angdisplacement_1 = angular_displacement(1);
76 this->position(0, v.position);
77 this->position(1, v.velocity);
78 this->position(2, dv.velocity);
79 this->quaternion(unit(v.quaternion));
80 this->angular_momentum(v.angmomentum);
81 const auto& R = rotation_matrix();
82 const auto& R_inv = inverse(R);
83 const auto& I_body_inv = inverse(inertia_matrix());
86 auto angvelocity = R*(I_body_inv*(R_inv*v.angmomentum));
87 auto angacceleration = R*(I_body_inv*(R_inv*dv.angmomentum));
88 this->angular_displacement(0, angular_displacement() + angvelocity*dt);
89 this->angular_displacement(1, angvelocity);
90 this->angular_displacement(2, angacceleration);
96 this->_quaternion.clear();
97 this->_position[0] = 0;
98 this->_position[1] = 0;
99 this->_position[2] = 0;
100 this->_angdisplacement[0] = 0;
101 this->_angdisplacement[1] = 0;
102 this->_angdisplacement[2] = 0;
103 this->_angmomentum = 0;
109 out << std::setw(20) <<
"position" 110 << std::setw(12) <<
"[m]" 111 <<
" " << this->position(0)
113 out << std::setw(20) <<
"velocity" 114 << std::setw(12) <<
"[m/s]" 115 <<
" " << this->position(1)
117 out << std::setw(20) <<
"acceleration" 118 << std::setw(12) <<
"[m/s^2]" 119 <<
" " << this->position(2)
121 out << std::setw(20) <<
"Euler angles" 122 << std::setw(12) <<
"[rad]" 123 <<
" " << this->euler_angles()
125 out << std::setw(20) <<
"angular velocity" 126 << std::setw(12) <<
"[rad/s]" 127 <<
" " << this->angular_displacement(1)
129 out << std::setw(20) <<
"angular acceleration" 130 << std::setw(12) <<
"[rad/s^2]" 131 <<
" " << this->angular_displacement(2)
133 out << std::setw(20) <<
"mass" 134 << std::setw(12) <<
"[t]" 135 <<
" " << this->mass()/T{1000}
137 out << std::setw(20) <<
"dimensions" 138 << std::setw(12) <<
"[m]" 139 <<
" " << this->hull().bounding_box().extent()
141 out << std::setw(20) <<
"no. of vertices" 142 << std::setw(12) <<
"" 143 <<
" " << this->hull().vertices().size()
145 out << std::setw(20) <<
"no. of faces" 146 << std::setw(12) <<
"" 147 <<
" " << this->hull().faces().size()
149 out << std::setw(20) <<
"average face area" 150 << std::setw(12) <<
"[m^2]" 151 <<
" " << this->hull().average_face_area()
153 out << std::setw(20) <<
"volume" 154 << std::setw(12) <<
"[m^3]" 155 <<
" " << volume(this->hull())
157 out << std::setw(20) <<
"centroid" 158 << std::setw(12) <<
"[m]" 159 <<
" " << centroid(this->hull())
165 vtb::core::operator<<(
std::ostream& out,
const Ship<T>& rhs) {
166 rhs.dump(out);
return out;
171 vtb::core::operator<<(bstream& out,
const Ship<T>& rhs) {
172 out << rhs._quaternion;
173 for (
const auto& x : rhs._position) { out << x; }
174 for (
auto& x : rhs._angdisplacement) { out << x; }
182 vtb::core::operator>>(bstream& in, Ship<T>& rhs) {
183 in >> rhs._quaternion;
184 for (
auto& x : rhs._position) { in >> x; }
185 for (
auto& x : rhs._angdisplacement) { in >> x; }
194 vtb::core::operator<<(
std::ostream& out,
const Ship<VTB_REAL_TYPE>& rhs);
197 vtb::core::operator<<(bstream& out,
const Ship<VTB_REAL_TYPE>& rhs);
200 vtb::core::operator>>(bstream& in, Ship<VTB_REAL_TYPE>& rhs);
Mass_moments< T, N > mass_moments() const
Calculate volume, centre of mass and inertia tensor.
T flooded_mass() const
Total mass of all fluid volumes inside compartments.
Rigid ship with a mass and translational and angular velocity.
vec3 euler_angles() const
Get Euler angles or their derivatives.
const vec3 & angular_velocity() const
Angular velocity in Earth-fixed coordinate system.
const quaternion_type & quaternion() const
Get rotation quaternion.
state_vector_type state_vector() const
Get state vector for ship motion equation.