angles_to_sph: Conversion between the angular and Cartesian coordinates of...

View source: R/angles.R

angles_to_sphR Documentation

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

Description

Transforms the angles (\theta_1,\ldots,\theta_d) in [0,\pi)^{d-1}\times[-\pi,\pi) into the Cartesian coordinates

(\cos(x_1),\sin(x_1)\cos(x_2),\ldots, \sin(x_1)\cdots\sin(x_{d-1})\cos(x_d), \sin(x_1)\cdots\sin(x_{d-1})\sin(x_d))

of the sphere \mathcal{S}^{d}, and vice versa.

Usage

angles_to_sph(theta)

sph_to_angles(x)

Arguments

theta

matrix of size c(n, d) with the angles.

x

matrix of size c(n, d + 1) with the Cartesian coordinates on \mathcal{S}^{d}. Assumed to be of unit norm by rows.

Value

  • angles_to_sph: the matrix x.

  • sph_to_angles: the matrix theta.

Examples

# Check changes of coordinates
sph_to_angles(angles_to_sph(c(pi / 2, 0, pi)))
sph_to_angles(angles_to_sph(rbind(c(pi / 2, 0, pi), c(pi, pi / 2, 0))))
angles_to_sph(sph_to_angles(c(0, sqrt(0.5), sqrt(0.1), sqrt(0.4))))
angles_to_sph(sph_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))))

polykde documentation built on April 16, 2025, 1:11 a.m.