17#ifndef __math_sphere_h__
18#define __math_sphere_h__
38 template <
class VectorType1,
class VectorType2>
39 inline typename std::enable_if<VectorType1::IsVectorAtCompileTime, void>::type
42 if (az_el_r.size() == 3) {
43 xyz[0] = az_el_r[2] * std::sin (az_el_r[1]) * std::cos (az_el_r[0]);
44 xyz[1] = az_el_r[2] * std::sin (az_el_r[1]) * std::sin (az_el_r[0]);
45 xyz[2] = az_el_r[2] * cos (az_el_r[1]);
47 xyz[0] = std::sin (az_el_r[1]) * std::cos (az_el_r[0]);
48 xyz[1] = std::sin (az_el_r[1]) * std::sin (az_el_r[0]);
49 xyz[2] = cos (az_el_r[1]);
56 template <
class MatrixType1,
class MatrixType2>
57 inline typename std::enable_if<!MatrixType1::IsVectorAtCompileTime, void>::type
60 cartesian.resize (az_el.rows(), 3);
61 for (ssize_t dir = 0; dir < az_el.rows(); ++dir)
68 template <
class MatrixType>
69 inline typename std::enable_if<!MatrixType::IsVectorAtCompileTime, Eigen::MatrixXd>::type
72 Eigen::MatrixXd cartesian (az_el.rows(), 3);
73 for (ssize_t dir = 0; dir < az_el.rows(); ++dir)
81 template <
class VectorType1,
class VectorType2>
82 inline typename std::enable_if<VectorType1::IsVectorAtCompileTime, void>::type
86 az_el_r[0] = std::atan2 (xyz[1], xyz[0]);
87 az_el_r[1] = std::acos (xyz[2] / r);
88 if (az_el_r.size() == 3)
95 template <
class MatrixType1,
class MatrixType2>
96 inline typename std::enable_if<!MatrixType1::IsVectorAtCompileTime, void>::type
99 az_el.allocate (cartesian.rows(), include_r ? 3 : 2);
100 for (ssize_t dir = 0; dir < cartesian.rows(); ++dir)
107 template <
class MatrixType>
108 inline typename std::enable_if<!MatrixType::IsVectorAtCompileTime, Eigen::MatrixXd>::type
111 Eigen::MatrixXd az_el (cartesian.rows(), include_r ? 3 : 2);
112 for (ssize_t dir = 0; dir < cartesian.rows(); ++dir)
120 template <
class MatrixType>
123 assert (cartesian.cols() == 3);
124 for (ssize_t i = 0; i < cartesian.rows(); i++) {
125 auto norm = cartesian.row(i).norm();
127 cartesian.row(i).array() /= norm;
constexpr T pow2(const T &v)
std::enable_if< VectorType1::IsVectorAtCompileTime, void >::type spherical2cartesian(const VectorType1 &az_el_r, VectorType2 &&xyz)
convert spherical coordinates to Cartesian coordinates
std::enable_if< VectorType1::IsVectorAtCompileTime, void >::type cartesian2spherical(const VectorType1 &xyz, VectorType2 &&az_el_r)
convert Cartesian coordinates to spherical coordinates
void normalise_cartesian(MatrixType &cartesian)
normalise a set of Cartesian coordinates