angles_to_sphere function

Conversion between angular and Cartesian coordinates of the (hyper)sphere

Conversion between angular and Cartesian coordinates of the (hyper)sphere

Transforms the angles (θ1,,θp1)(\theta_1,\ldots,\theta_{p-1})' in [0,π)p2×[π,π)[0,\pi)^{p-2}\times[-\pi,\pi) into the Cartesian coordinates [REMOVE_ME](cos(x1),sin(x1)cos(x2),,sin(x1)sin(xp2)cos(xp1),sin(x1)sin(xp2)sin(xp1))[REMOVEME2] (\cos(x_1),\sin(x_1)\cos(x_2),\ldots,\sin(x_1)\cdots\sin(x_{p-2})\cos(x_{p-1}),\sin(x_1)\cdots\sin(x_{p-2})\sin(x_{p-1}))' [REMOVE_ME_2]

of Sp1S^{p-1}, and vice versa.

angles_to_sphere(theta) sphere_to_angles(x)

Arguments

  • theta: matrix of size c(n, p - 1) with the angles.
  • x: matrix of size c(n, p) with the Cartesian coordinates. Assumed to be of unit norm by rows.

Returns

For angles_to_sphere, the matrix x. For sphere_to_angles, the matrix theta.

Description

Transforms the angles (θ1,,θp1)(\theta_1,\ldots,\theta_{p-1})' in [0,π)p2×[π,π)[0,\pi)^{p-2}\times[-\pi,\pi) into the Cartesian coordinates

(cos(x1),sin(x1)cos(x2),,sin(x1)sin(xp2)cos(xp1),sin(x1)sin(xp2)sin(xp1)) (\cos(x_1),\sin(x_1)\cos(x_2),\ldots,\sin(x_1)\cdots\sin(x_{p-2})\cos(x_{p-1}),\sin(x_1)\cdots\sin(x_{p-2})\sin(x_{p-1}))'

of Sp1S^{p-1}, and vice versa.

Examples

# Check changes of coordinates sphere_to_angles(angles_to_sphere(c(pi / 2, 0, pi))) sphere_to_angles(angles_to_sphere(rbind(c(pi / 2, 0, pi), c(pi, pi / 2, 0)))) angles_to_sphere(sphere_to_angles(c(0, sqrt(0.5), sqrt(0.1), sqrt(0.4)))) angles_to_sphere(sphere_to_angles( rbind(c(0, sqrt(0.5), sqrt(0.1), sqrt(0.4)), c(0, sqrt(0.5), sqrt(0.5), 0), c(0, 1, 0, 0), c(0, 0, 0, -1), c(0, 0, 1, 0)))) # Circle sphere_to_angles(angles_to_sphere(0)) sphere_to_angles(angles_to_sphere(cbind(0:3))) angles_to_sphere(cbind(sphere_to_angles(rbind(c(0, 1), c(1, 0))))) angles_to_sphere(cbind(sphere_to_angles(rbind(c(0, 1)))))
  • Maintainer: Eduardo García-Portugués
  • License: GPL-3
  • Last published: 2024-05-24