30 const auto coshEtaInv = 1 / std::cosh(eta);
32 std::cos(phi) * coshEtaInv,
33 std::sin(phi) * coshEtaInv,
49 const auto cosTheta = std::cos(theta);
50 const auto sinTheta = std::sin(theta);
52 std::cos(phi) * sinTheta,
53 std::sin(phi) * sinTheta,
64 Eigen::Matrix<T, 3, 1>
unitDir) {
66 T phi = std::atan2(unitDir[1], unitDir[0]);
67 T theta = std::acos(unitDir[2]);
81 template <
typename InputVector>
83 const Eigen::MatrixBase<InputVector>& direction) {
84 EIGEN_STATIC_ASSERT_FIXED_SIZE(InputVector);
85 EIGEN_STATIC_ASSERT_VECTOR_ONLY(InputVector);
86 static_assert(3 <= InputVector::RowsAtCompileTime,
87 "Direction vector must be at least three-dimensional.");
89 using OutputVector =
typename InputVector::PlainObject;
92 OutputVector unitU = OutputVector::Zero();
94 unitU[0] = -direction[1];
95 unitU[1] = direction[0];
96 const auto scale = unitU.template head<2>().
norm();
101 if (scale < (16 * std::numeric_limits<OutputScalar>::epsilon())) {
105 unitU.template head<2>() /= scale;
123 template <
typename InputVector>
125 const Eigen::MatrixBase<InputVector>& direction) {
126 EIGEN_STATIC_ASSERT_FIXED_SIZE(InputVector);
127 EIGEN_STATIC_ASSERT_VECTOR_ONLY(InputVector);
128 static_assert(3 <= InputVector::RowsAtCompileTime,
129 "Direction vector must be at least three-dimensional.");
131 using OutputVector =
typename InputVector::PlainObject;
133 std::pair<OutputVector, OutputVector> unitVectors;
135 unitVectors.second = direction.cross(unitVectors.first);
136 unitVectors.second.normalize();