* @brief Transform the position vectors from cartesian to spherical coordinates * * @param pos * @return af::array */
| 185 | * @return af::array |
| 186 | */ |
| 187 | af::array cart_to_sph_position(const af::array& pos) { |
| 188 | if (pos.dims()[0] != 3) |
| 189 | throw make_error("Arrays must have 3 principal coordintes"); |
| 190 | |
| 191 | af::array x = pos(0, af::span); |
| 192 | af::array y = pos(1, af::span); |
| 193 | af::array z = pos(2, af::span); |
| 194 | |
| 195 | af::array r = af::sqrt(x * x + y * y + z * z); |
| 196 | af::array o = af::acos(z / r); |
| 197 | af::array p = af::atan2(y, x); |
| 198 | |
| 199 | af::array transformed_pos = af::join(0, r, o, p); |
| 200 | |
| 201 | return transformed_pos; |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * @brief Transform the velocity vectors from cartesian to spherical coordinates |