Skip to contents

This function converts spherical coordinates (theta, phi) to Cartesian coordinates.

Usage

spherical_to_cartesian(theta_phi, byrow = TRUE)

Arguments

theta_phi

A matrix where each row contains the spherical coordinates (theta, phi) of a point.

byrow

logical. If TRUE (the default) the matrix is filled by rows, otherwise the matrix is filled by columns.

Value

A matrix where each row contains the Cartesian coordinates (x, y, z) of a point.

Examples

theta_phi <- matrix(c(pi/4, pi/3, pi/6, pi/4), ncol = 2, byrow = TRUE)
spherical_to_cartesian(theta_phi)
#>           [,1]      [,2]      [,3]
#> [1,] 0.3535534 0.6123724 0.7071068
#> [2,] 0.3535534 0.3535534 0.8660254