FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
AxisRotation.h
1
3#pragma once
4
5#include <array>
6#include <cmath>
7
8namespace net_axis_rotation
9{
12inline std::array<double, 9> RotationWithAxisZ(const double axis[3])
13{
14 const double helper[3] = {std::fabs(axis[0]) < 0.9 ? 1.0 : 0.0, std::fabs(axis[0]) < 0.9 ? 0.0 : 1.0, 0.0};
15 double first[3] = {helper[1] * axis[2] - helper[2] * axis[1], helper[2] * axis[0] - helper[0] * axis[2], helper[0] * axis[1] - helper[1] * axis[0]};
16 const double norm = std::sqrt(first[0] * first[0] + first[1] * first[1] + first[2] * first[2]);
17 for (double& component : first)
18 component /= norm;
19 const double second[3] = {axis[1] * first[2] - axis[2] * first[1], axis[2] * first[0] - axis[0] * first[2], axis[0] * first[1] - axis[1] * first[0]};
20 return {first[0], first[1], first[2], second[0], second[1], second[2], axis[0], axis[1], axis[2]};
21}
22} // namespace net_axis_rotation